-
It is suggested to perform migration within a transaction. Why? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Migrations are "vulnerable" (from a correctness kind of view) since, if anything goes wrong in the middle of a migration, chances are your database is in a really bad state. With a partial migration, you'll likely won't be able to use the database since some required columns may not be there. But you also won't be able to fix this since you'd re-run a migration which then tries to redo some steps in an unexpected schema, causing errors or other correctness errors. Pretty much the only thing that helps is deleting the database and starting over. Errors in migrations are always really bad, but if you put the migration in a transaction you can at least reason about the state afterwards - it's not any more broken than before. So you have a chance to retry if the app is restart and the original failure was due to something unlucky like an IO error and not something happening every time. |
Beta Was this translation helpful? Give feedback.
Migrations are "vulnerable" (from a correctness kind of view) since, if anything goes wrong in the middle of a migration, chances are your database is in a really bad state. With a partial migration, you'll likely won't be able to use the database since some required columns may not be there. But you also won't be able to fix this since you'd re-run a migration which then tries to redo some steps in an unexpected schema, causing errors or other correctness errors. Pretty much the only thing that helps is deleting the database and starting over.
Errors in migrations are always really bad, but if you put the migration in a transaction you can at least reason about the state afterwards - it'…