Skip to content

fix(drizzle-kit): validate journal entries before converting migrations folder - #6170

Open
webdevsamran wants to merge 1 commit into
drizzle-team:betafrom
webdevsamran:fix/up-half-converted-journal
Open

fix(drizzle-kit): validate journal entries before converting migrations folder#6170
webdevsamran wants to merge 1 commit into
drizzle-team:betafrom
webdevsamran:fix/up-half-converted-journal

Conversation

@webdevsamran

Copy link
Copy Markdown

Summary

Fixes #6166.

migrateToFoldersV3() (the drizzle-kit up v0→v3 folder conversion) processed journal entries incrementally and destructively: for each entry it created the new folder, wrote snapshot.json + migration.sql, then deleted the original flat .sql. A journal entry whose snapshot file is missing was only discovered when the loop reached it — by which point every earlier entry had already been converted and its original deleted. Result: a half-converted migrations folder that drizzle-kit up can never finish (re-running hits MigrationsOutdatedCliError), with an error message ("No snapshot was found") that didn't even name the missing file.

Changes:

  1. Validate every entry up-front before writing anything: each entry's snapshot must exist, and any SQL-file ambiguity (MigrationSqlFilesConflictCliError) is detected in the same pre-pass. If anything is wrong, nothing is converted — originals stay intact and the folder remains resumable once fixed.
  2. Name the missing path in the error: No snapshot was found for '<path>' so users know exactly which journal entry is broken.

Testing

New regression tests in drizzle-kit/tests/other/migrate-folders-v3.test.ts (pure file-based, no DB):

  • a two-entry journal where the second snapshot is missing → throws, and asserts nothing was converted: both original .sql files intact, meta/ untouched, no new folders created
  • a complete folder still converts fully (meta removed, originals moved)

Red/green verified: without the fix the atomicity test fails (entry 0 already converted + original deleted when the error throws); with the fix both pass.

✓ tests/other/migrate-folders-v3.test.ts (2 tests) 14ms

 Test Files  1 passed (1)
      Tests  2 passed (2)

…ns folder

migrateToFoldersV3 converted entries incrementally and deleted each original .sql as it went, so a journal entry with a missing snapshot aborted mid-loop after earlier entries were already moved - leaving the folder half-converted and non-resumable. Validate every entry up-front so nothing is written unless the whole journal is convertible, and name the missing snapshot path in the error message.
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

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.

1 participant