-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Enhancement: Wrap each migration file in an atomic transaction #196
Comments
This would be an interesting change to support in the driver. (See: #14) For now, migrate errs on the side of flexibility. |
Golang Migrate Version 1 to Version 4 Are all migration files run in a transaction implicitly(from a black box perspective)? if yes, then why do we have to explicitly mention (Begin/commit) in migration files with multiple sql statements? Thanks in advance, PS :- working with Postgres here. |
No. That's what this issue/feature request is about. See: https://github.com/golang-migrate/migrate/blob/master/MIGRATIONS.md#migration-content-format
It's a best practice. If your migration contains multiple statements, a failure in a single statement will rollback the whole migration which makes it easier to re-apply the whole migration after the issue has been resolved. An issue w/ this feature request is that it's not backwards compatible. e.g. existing migrations using with |
I find it really hard to believe this is something the user is supposed to remember every single time they write a migration. I'm personally going to look for an alternate solution now, I really don't trust myself to remember that. |
Other options:
See also: #374 |
i think it could be roled out progressively one by one driver |
Could migration scripts be wrapped in
db.BeginTx() ... db.Rollback/db.Commit()
, to make it easier to resolve any errors that occur during migrations?This could help keep migrations in a clean state, even when a migration fails! Rather than having to clean up the innards of the golang-migrate state, the user can simply fix the migrations and run them again until they pass.
https://golang.org/pkg/database/sql/#Conn.BeginTx
The text was updated successfully, but these errors were encountered: