Question
Sequelize migrations: ensuring rollback safety after schema changes
Ari Cedar
0 reputation · 21 May 2024, 22:30 UTC
20.7K views0
Problem Overview
Sequelize migration files expose up and down functions, but the framework does not automatically wrap all migration steps in a single transaction across every dialect.
Current Constraints
- When a migration fails during
up, only statements executed inside an explicit transaction are rolled back; otherwise partial changes persist. - DDL support for transactions varies by dialect (PostgreSQL/MySQL support it, SQLite does not fully support schema changes in transactions).
- Sequelize’s
sequelize.sync({ alter: true })helper applies schema changes immediately with no rollback path.
Unresolved Decision
The core question is whether Sequelize should implement a global transaction wrapper for migrations, guaranteeing that a failed migration leaves the database unchanged regardless of dialect.
Specific Questions
- Should Sequelize automatically wrap every migration’s
upanddownin a transaction across all supported dialects? - What strategies can developers employ to ensure a failed migration does not leave the database in an inconsistent state?
- How do dialect-specific DDL transaction capabilities influence the feasibility of a universal rollback mechanism?