Skip to content

[Orm] Skip executing fully-commented introspect migration files#5812

Open
youcefzemmar wants to merge 1 commit into
drizzle-team:mainfrom
youcefzemmar:fix/bug-drizzle-kit-migrate-fails-with-parsing-error-o
Open

[Orm] Skip executing fully-commented introspect migration files#5812
youcefzemmar wants to merge 1 commit into
drizzle-team:mainfrom
youcefzemmar:fix/bug-drizzle-kit-migrate-fails-with-parsing-error-o

Conversation

@youcefzemmar
Copy link
Copy Markdown

## What

`readMigrationFiles` now recognises the introspection SQL file that `drizzle-kit pull` emits — two `--` notes followed by the entire schema wrapped in a single `/* ... */` block — and returns `sql: []` for that entry instead of feeding the comment delimiters to the driver. The migration is still hashed and inserted into `__drizzle_migrations`, so it's recorded as an applied baseline.

The detection is intentionally narrow: it only kicks in when the body (after stripping leading `--` lines and whitespace) starts with `/*`, ends with `*/`, and has no nested `*/`. Anything else falls through to the existing `--> statement-breakpoint` split.

## Why

Reproduced in #4851. `drizzle-kit pull` writes the schema commented out and asks the user to uncomment before running `migrate`. People (`@joshbodily`, `@melroy89` in the thread) are using the commented file on purpose, as a "this schema is already in the DB, just record it as applied" baseline. Today `drizzle-kit migrate` crashes with a parse error because the runtime tries to execute the `/* ... */` wrapper.

Treating the no-op file as zero statements matches what users were already doing manually (deleting the file or hand-editing the journal) and keeps the journal/hash row in place so subsequent migrations diff cleanly.

## Testing

- Added `drizzle-orm/tests/migrator.test.ts` covering: the commented introspect file → `sql: []`; a normal `--> statement-breakpoint`-split file is unaffected; an uncommented introspect file still executes; a file with SQL after a trailing block comment is not skipped.
- I couldn't run `pnpm test` locally — `pnpm` errors with "unable to open database file" in this sandbox before it can install. Verified the detection logic directly with `node` against the four fixtures and the project's `tsc --noEmit` against the touched files.

## Notes

- `readMigrationFiles` is shared by every dialect migrator (pg, mysql, sqlite, libsql, neon, vercel, etc.); the change is read-only and only fires on files that today crash, so working migrations are unaffected — the "normal multi-statement" test covers that explicitly.
- Detection is conservative on purpose: nested `*/`, mixed real SQL + comment block, or any non-`--`/`/* */` content disables the skip. Risk of silently dropping a real migration is low.
- Bumped `changelogs/drizzle-orm/0.45.4.md` with a one-liner.

Fixes #4851.

`drizzle-kit pull` writes the discovered schema into the next migration
file wrapped in a single `/* ... */` block with two `--` notes above it,
expecting the user to uncomment before running `migrate`. When the user
leaves it commented (intentionally, as a baseline), `migrate` crashes
the underlying driver with a parse error on the comment delimiters.

Detect this exact shape in `readMigrationFiles` — `--` lines + a single
balanced `/* ... */` body with no nested `*/` — and treat such entries
as zero-statement migrations. The hash row still gets inserted into
`__drizzle_migrations`, so the baseline is recorded as applied. Normal
multi-statement files and any file that contains real SQL outside the
block are unchanged.

Fixes drizzle-team#4851.
@youcefzemmar youcefzemmar marked this pull request as ready for review May 27, 2026 14:11
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