Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: Is execution of multiple migrations atomic? #410

Closed
igorsechyn opened this issue Sep 5, 2016 · 2 comments
Closed

Question: Is execution of multiple migrations atomic? #410

igorsechyn opened this issue Sep 5, 2016 · 2 comments

Comments

@igorsechyn
Copy link

igorsechyn commented Sep 5, 2016

If i have multiple new migrations and I execute up, are they executed as one atomic operation? i.e. if one migration fails, will other migrations be reverted?

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/37601084-question-is-execution-of-multiple-migrations-atomic?utm_campaign=plugin&utm_content=tracker%2F73887&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F73887&utm_medium=issues&utm_source=github).
@wzrdtales
Copy link
Member

No. This is also a bit more complicated than you think.

You have to think of many things that can actually happen and would need to reverse, this begins on the migration that fails. The biggest problem actually is that transactions of many RDBMS, e.g. MySQL, do only work for DML and not for DDL, that means that the reversal of the actual migration would need to reverse on a potentially on an incomplete migration. There might be some easy cases to reverse this actually, like dropping a table that should have been created and ignoring if it has not been created. But there are many other cases, in fact some operations are not just safely reversable without transactions. In the case of transactions that work for DDL this is not that much of a problem anymore. However as stated, many RDBMS do not support this.

Anyhow, to come back to your question:

No, and there is no reason for them to be. A migration is atomic itself. That means every single migration is surrounded by a transaction, for some DBs this would result in resetting the transaction on a failure while this migration. A set of migrations should however not be atomic, that does not make any sense to be a default behavior. But it could possibly introduced via an optional setting, that might be named rollbackOnFailure: true or something like that.

I do see where you would see a benefit for this feature, I suspect you're looking for programmatic migrations and want to go back to the old state on failure I guess? In this case this really could be helpful though. I consider this as a feature request as of now :)

@wzrdtales
Copy link
Member

Closing in favour of #508

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants