Proposal: Improving Migration Atomicity #56607
Replies: 2 comments
-
This is a huge problem! Thanks for bringing that up, Samuel! 👍🏻 I'd say, one of the problem is that the |
Beta Was this translation helpful? Give feedback.
-
What is your reference? Check the following codes please, what am I missing? framework/src/Illuminate/Database/Schema/Grammars/Grammar.php Lines 499 to 507 in 39e9e2b framework/src/Illuminate/Database/Migrations/Migration.php Lines 14 to 19 in 39e9e2b framework/src/Illuminate/Database/Migrations/Migrator.php Lines 445 to 448 in 39e9e2b framework/src/Illuminate/Database/Schema/Grammars/PostgresGrammar.php Lines 13 to 18 in 39e9e2b |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Problem
Migrations involving multiple schema changes are not always atomic across all supported databases. When a migration step fails partway, earlier changes may remain applied, leaving the database in an inconsistent state and breaking rollback workflows. This requires manual intervention to fix.
While some databases like PostgreSQL, SQLite, and SQL Server support transactional DDL and handle this safely, others—such as MySQL and MariaDB—do not, causing frequent partial migrations.
Database Transactional DDL Support & Usage
How Other Platforms and Frameworks Handle Migration Atomicity
atomic = False
flag; documents risks for non-transactional DBs like MySQLrepair
command to fix failed migration metadataprisma migrate resolve
to recover from failed migrations* Based on Stack Overflow and community surveys
Proposed Solutions
1. None - keep current behavior
Pros:
⚠️ Partial migrations and rollback failures remain common
⚠️ Manual cleanup still required after failures
✅ No breaking changes or disruptions to existing workflows
Cons:
2. Use transactions for migrations
Pros:
⚠️ Not supported on all databases (e.g., MySQL/MariaDB) due to implicit commits
⚠️ May create false confidence where transactions don’t actually protect changes
✅ Full atomicity and safe rollbacks where supported
✅ Prevents partial application of migrations
Cons:
3. Use transactions with a protected field indicator
Pros:
⚠️ Adds complexity to migration tooling and developer workflow
⚠️ Requires explicit marking of non-transactional operations
✅ Wraps migrations in transactions while excluding operations that break transactional guarantees
✅ Improves safety without breaking compatibility on databases without full transactional DDL support
Cons:
4 votes ·
Beta Was this translation helpful? Give feedback.
All reactions