Repository navigation
feat(migrations): Regenerate branch migrations with pnpm db:rebase - #4121
Conversation
Co-Authored-By: BYK <[email protected]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
5 screenshot changes — 5 changed · 0 added · 0 removed Review screenshots in Frameshift
|
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit fc3bbc0. Configure here.
| const entry = show("_journal.json").entries.find((item) => item.tag === tag); | ||
| const prefix = (idx) => String(idx).padStart(4, "0"); | ||
| const current = show(`${prefix(entry.idx)}_snapshot.json`); | ||
| const previous = show(`${prefix(entry.idx - 1)}_snapshot.json`); |
There was a problem hiding this comment.
Invalid snapshot filename when branch migration has idx 0
Low Severity
When a branch migration is the first migration in a package (entry.idx === 0), prefix(entry.idx - 1) evaluates to String(-1).padStart(4, "0") which produces "00-1". The git show call then tries to read 00-1_snapshot.json, a file that doesn't exist, causing a confusing git error instead of a clear message. This is reachable when origin/main has the migrations directory (with journal) but no SQL migrations yet, and the branch adds the first one.
Reviewed by Cursor Bugbot for commit fc3bbc0. Configure here.
Upgrades drizzle-orm and drizzle-kit to `1.0.0-rc.6`, the newest 1.0 pre-release, pinned in the catalog. Migrations use the v1 folder layout, so two PRs that add migrations no longer conflict in a journal. `drizzle-kit check` reports only real collisions. ## Existing databases `applyMigrations` now writes the v1 migration table (`hash`, `created_at`, `name`, `applied_at`) and picks pending migrations by folder `name`, as the v1 migrator does. A table from 0.x has only `hash` and `created_at`. On the first run, one transaction adds the two columns and names each row: - A row matches the migration with the same time, else the same SQL hash, else the same second. v1 reads the time from the folder name with second precision, and the converted SQL is byte for byte the old SQL. - The earlier plugin adoption recorded only its newest migration. The migrations before it get rows too, so every applied migration has a named row. After that, the only pending migration is the new no-op baseline, and Drizzle's own migrator sees the same table. A 0.x-shaped core table with all 174 rows went through this: 174 existing, 1 migrated (the baseline), no unnamed rows. Then stock `migrate()` from `drizzle-orm/node-postgres/migrator` found nothing to run. ## Changes - `drizzle-kit up` converted all migrations in the three packages (174 core, 22 GitHub, 1 Google). - Two explicit FK names now use the 63-character prefix that Postgres already stores, so the database does not change. - `20261124202143_drizzle_v1_baseline` holds only comments. Its snapshot records the v1 form of 40 index and 35 check expressions, so `generate` does not rebuild them (drizzle-team/drizzle-orm#6589). The GitHub and Google packages need no baseline: `drizzle-kit check` reports no schema change for all three. - `drizzle()` no longer gets `schema`, since v1's relational queries need relations instead. The database types are now `PgAsyncDatabase<PgQueryResultHKT>`. The one RQBv1 call, in the eval recording export, uses `readConversationEventRows`. - Removed `strict` from the drizzle configs. v1 dropped the option, and `push` now asks before data loss by default. - Updated the migration checks: - `migration-metadata:check` checks the folder layout and runs `drizzle-kit check`, which fails on conflicting migrations or a schema that no migration creates. - `money-units:check` and `provider-state:check` rebuild the schema from the delta snapshots with drizzle-kit's `reconstruct()`. - `migration-locks:check`, its baseline (same entries) and `.squawk.toml` read `<folder>/migration.sql`. - Removed `pnpm db:rebase` from #4121. Folder names order the migrations, and a migration that merges after a newer one still runs, so the journal `when` rule has nothing left to protect. - The test global setup and the GitHub skip list use folder names. <!-- junior-request-attribution:start --> via @BYK. <!-- junior-request-attribution:end --> <!-- junior-session-footer:start --> <!-- junior-conversation-id:agent%3A2c8fee31bbec555fe60f8e291053f5c8 --> -- [View Session](https://junior-prod.sentry.dev/conversations/agent%3A2c8fee31bbec555fe60f8e291053f5c8) [[Sentry]](https://sentry.sentry.io/explore/conversations/agent%3A2c8fee31bbec555fe60f8e291053f5c8/?project=4510944073809921) <!-- junior-session-footer:end --> Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com> Co-authored-by: BYK <[email protected]>


If two branches each add a Drizzle migration, they always conflict: both append to
_journal.jsonand both add the sameNNNN_snapshot.json. Fixing the conflict markers does not fix the branch, because each snapshot is missing the other branch's schema. The usual hand fix is to renumber the migration, and that adds a quiet prod risk.applyMigrationsskips every migration whose journalwhenis not later than the newest applied one. So a branch migration that gets renumbered after main's new migration but keeps its oldwhennever runs.Changes
pnpm migration-metadata:checknow fails when a journal entry'swhenis not greater than the entry before it. The error says the migrator would skip it and points topnpm db:rebase.pnpm db:rebase [junior-github ...]is a new command. Run it after you merge or rebase onorigin/main. It works on every package that has branch migrations, which are the migration SQL files that are not inorigin/main. For each such package it:origin/main's migrations in the working tree,db:generateagain with the branch migration name,db:generate, which must find no schema changes.Hand edits and custom migrations
To find hand edits, the script rebuilds the SQL that drizzle generated for each branch migration. It uses the snapshots from the branch commit that last changed that SQL file, through
drizzle-kit/api.--custom, so no schema diff) is created again withdb:generate --custom, and the script copies its SQL back.The script stops and puts the package's migrations back as they were in these cases. The error says what to do by hand.
migrations/.origin/main.The script is temporary. Drizzle v1 drops the journal and the snapshot chain, and then the script can go.
via @BYK.
--
View Session [Sentry]