Skip to content

fix: genesis migration to unblock migration chain on empty DB#756

Merged
arturasmckwcz merged 1 commit into
developfrom
fix-migration-chain-clean-db
Jul 13, 2026
Merged

fix: genesis migration to unblock migration chain on empty DB#756
arturasmckwcz merged 1 commit into
developfrom
fix-migration-chain-clean-db

Conversation

@arturasmckwcz

Copy link
Copy Markdown
Collaborator

Summary

  • The 73-migration chain was written against a pre-existing schema and fails on a completely empty DB: migration 1 clean up and create user entity #2 (AddEventEntity) tries to add a FK to the language table which doesn't exist, causing relation "language" does not exist
  • This adds a genesis migration with timestamp 1763036250000 (runs first) that creates the full schema in idempotent form and marks all 73 prior migrations as already-run in be_migrations
  • On a fresh DB: genesis creates all enums, sequences, tables, constraints, indexes — then server starts immediately, zero additional migrations run
  • On an existing DB (production, staging): all IF NOT EXISTS / DO EXCEPTION / WHERE NOT EXISTS guards make every statement a no-op — zero schema drift

Test plan

  • Local clean-replay: docker compose down -v && RUN_MIGRATIONS=1 docker compose upbe logs must reach Migrations completed with no errors
  • Existing DB: run yarn migration:run on a populated local DB — genesis runs, all statements no-op, no errors
  • CI tests pass

🤖 Generated with Claude Code

The 73-migration chain was written against a pre-existing schema and
cannot replay from scratch — migration #2 fails with 'relation language
does not exist'. This genesis migration (timestamp 1763036250000) runs
first on any DB and:
- Creates all enums, sequences, tables and constraints in their current
  final form using IF NOT EXISTS / DO EXCEPTION blocks (idempotent)
- Marks all 73 existing migrations as already-run in be_migrations so
  TypeORM skips them on both fresh and existing DBs

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@arturasmckwcz arturasmckwcz merged commit b21d1a6 into develop Jul 13, 2026
@arturasmckwcz arturasmckwcz deleted the fix-migration-chain-clean-db branch July 13, 2026 13:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants