Skip to content

fix(db): seed __drizzle_migrations from legacy migration table on EFS boot - #74

Merged
hblanken merged 1 commit into
collabfrom
fix/drizzle-migration-legacy-seed
Aug 19, 2026
Merged

fix(db): seed __drizzle_migrations from legacy migration table on EFS boot#74
hblanken merged 1 commit into
collabfrom
fix/drizzle-migration-legacy-seed

Conversation

@hblanken

Copy link
Copy Markdown
Collaborator

Root cause

The ECS container was crashing immediately after deployment, causing aws ecs wait services-stable to time out after 10 minutes.

drizzle-orm beta.19 (previously used) tracked applied migrations in a migration table:

id TEXT PRIMARY KEY  -- folder name, e.g. "20260511173437_session-metadata"
time_completed INTEGER

drizzle-orm 1.0.0-rc.2 (merged in PR #72/#73) switched to __drizzle_migrations:

id INTEGER PRIMARY KEY
hash text
created_at numeric
name text          -- same folder name
applied_at TEXT

The EFS production database has the legacy migration table but no __drizzle_migrations. When rc.2 starts, it sees an empty __drizzle_migrations, treats all migrations as unapplied, and tries to re-run 20260511173437_session-metadata — which crashes with:

SqliteError: duplicate column name: metadata

(The ALTER TABLE session ADD metadata text was already applied.)

Fix

Before calling applyMigrations(), detect the legacy migration table and seed __drizzle_migrations from it. rc.2 then skips already-applied work and boots normally.

Verification

  • Tested against a SQLite DB with the same schema as the EFS production database (session table + 38 legacy migration records, no __drizzle_migrations)
  • bun run --cwd packages/opencode src/index.ts serve starts without errors: opencode server listening on http://0.0.0.0:4099
  • Standalone drizzle migrate call with seeded DB returns SUCCESS
  • Full typecheck passes (cache hit — no type changes)

Deploy

After merge, trigger the deploy-collab.yml workflow to redeploy to ECS.

…st boot

Drizzle beta.19 tracked applied migrations in a `migration` table (id TEXT
PRIMARY KEY).  rc.2 switched to `__drizzle_migrations` (name column).  On
the EFS production database the old table exists but the new one does not,
so rc.2 sees all migrations as unapplied and re-runs them — crashing on
`ALTER TABLE session ADD metadata text` because the column already exists.

Before handing off to applyMigrations, check for the legacy table and seed
`__drizzle_migrations` with any migration folder names that appear in both
the journal and the old table.  rc.2 then skips already-applied work and
the server boots normally.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Aug 18, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: e2c2f610-7043-4c40-acaf-7fbc9fc0ce6f


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@hoj-unleash
hoj-unleash self-requested a review August 19, 2026 00:22

@hoj-unleash hoj-unleash left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@hblanken
hblanken merged commit 6d7f1eb into collab Aug 19, 2026
4 of 8 checks passed
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