fix(core): import legacy drizzle migration journals without a name column - #37707
fix(core): import legacy drizzle migration journals without a name column#37707seongilp wants to merge 1 commit into
Conversation
…lumn Journals written by drizzle-orm's stock migrator only have (id, hash, created_at) columns, so the seeding query in DatabaseMigration.applyOnly crashed with 'no such column: name' on every startup. Map created_at back to the migration id's timestamp prefix instead, mirroring the v0 -> v1 journal upgrade in effect-drizzle-sqlite.
|
The following comment was made by an LLM, it may be inaccurate: Potential duplicate or related PR found:
Why it might be related: Both PRs address legacy database migration issues in core. PR #34188 handles migrating legacy local databases, while PR #37707 specifically addresses importing legacy drizzle migration journals without the |
|
Re: the bot's note about #34188 — I found that PR (and the now-closed #31121) after opening this one, so a quick note on how this differs, for whoever triages: Both detect the legacy
Verified against a real affected database (6 legacy journal rows, empty hashes): all rows mapped to the correct ids and the remaining migrations applied cleanly on top. This PR also keeps the diff to the migration path only. Happy to defer to whichever approach the maintainers prefer — mostly want #31119 fixed, since affected installs currently freeze on startup with no visible error. |
|
Just used this PR to fix an old hanging install of opencode 👍 |
Issue for this PR
Closes #31119
Type of change
What does this PR do?
Databases whose
__drizzle_migrationsjournal was written by drizzle-orm's stock migrator have the old(id, hash, created_at)schema — nonamecolumn. On these databases every startup crashes withno such column: name. In the TUI the error never reaches the screen, so it looks like a silent freeze (blank/unresponsive, empty log file);opencode modelsprints the error directly.The crash is in
DatabaseMigration.applyOnly: when themigrationtable is empty it seeds it withSELECT name FROM __drizzle_migrations, assuming the journal is already at v1. The v0 -> v1 journal upgrade exists ineffect-drizzle-sqlite(upgradeIfNeeded), but it only runs inside that package'smigrate(), which core no longer calls for these databases — so v0 journals never get upgraded and the seed query dies.Fix: introspect the journal's columns before seeding. If
nameis missing, map each row'screated_atback to the timestamp prefix of the TypeScript migration ids. This is the same value the v0 -> v1 upgrader matches on: drizzle-kit derives the migration filename prefix from the same timestamp it stores increated_at. Rows that map to no known migration abort with a descriptive error instead of the raw SQL error.How did you verify your code works?
database-migration.test.tsreproduce the legacy journal schema taken from a real affected database (including the emptyhashvalues). Without the fix they fail with exactlyno such column: name; with it the file passes 17/17.pragma quick_checkreturns ok, and existing session/project rows are intact.tsgo --noEmit, oxlint, and prettier are clean (no new warnings).Screenshots / recordings
Not a UI change.
Checklist