Skip to content

fix(drizzle-kit): Handle migration failures more clearly#5617

Open
opensourcezeal wants to merge 2 commits into
drizzle-team:mainfrom
opensourcezeal:main
Open

fix(drizzle-kit): Handle migration failures more clearly#5617
opensourcezeal wants to merge 2 commits into
drizzle-team:mainfrom
opensourcezeal:main

Conversation

@opensourcezeal

Copy link
Copy Markdown

Summary
This PR fixes #5601 #5521 #3214; issues where database migrations could fail silently without surfacing errors, making debugging difficult and misleading for users.

Previously, when running migrations generated by npx drizzle-kit generate, any runtime errors during execution were not properly surfaced. This resulted in migrations appearing to succeed even when they had actually failed at the database execution layer.

This behavior occurs regardless of SQL dialect and is for example problematic when generated SQL is incompatible with the target database (e.g. MySQL constraints such as UUID vs CUID mismatches).

Changes

  • Introduced a connection context wrapper in drizzle-kit/src/cli/connections.ts ensures migration execution context is properly tracked
  • Captures and reports runtime errors instead of swallowing them
  • Improved error propagation so failures during migration execution are no longer silent

Test coverage

A new test scenario was added in drizzle-kit/tests/cli-migrate.test.ts
This validates a case where:

  • A schema is generated using npx drizzle-kit generate
  • The schema includes an unsupported type (e.g. CUID in MySQL context where only UUID is valid)
  • Migration execution via npx drizzle-kit migrate correctly fails with a visible error message

Migrations were silently failing. Now, report errors from the connection context if a migration fails to provide more clarity.
@opensourcezeal

Copy link
Copy Markdown
Author

@AndriiSherman

@opensourcezeal opensourcezeal changed the title [Drizzle Kit]: Handle migration failures more clearly [Drizzle Kit] Fix: Handle migration failures more clearly Apr 11, 2026
@opensourcezeal opensourcezeal changed the title [Drizzle Kit] Fix: Handle migration failures more clearly Fix (Drizzle Kit): Handle migration failures more clearly Apr 18, 2026
@opensourcezeal opensourcezeal changed the title Fix (Drizzle Kit): Handle migration failures more clearly fix(drizzle-kit): Handle migration failures more clearly Apr 18, 2026
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.

[BUG]: drizzle-kit migrate: migration SQL failures exit with code 1 but print no error (MigrateProgress hides rejection)

1 participant