-
Notifications
You must be signed in to change notification settings - Fork 40
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
add full-rollback option for production migrations #19
base: master
Are you sure you want to change the base?
Conversation
I see it practically useless since alter of database commits the transaction automatically (edit: and immidiately). But I may be missing some point, since I don't get it all. |
Why not make rollbacking all migrations a default behavior? |
Also because rolling schema changes is not supported in mysql. I feel safer introducing it as a opt-in feature. |
Yes, of course Postgre is about sth another. Personally, I am ok with switch, but I see two important facts:
|
|
||
} else if ($mode === self::MODE_CONTINUE) { | ||
// commit migrations not including the failing one | ||
$this->driver->commitTransaction(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is probably wrong. It migrations contains more sqls and only the last one is wrong (throws exception), all previous queries are commited, aren't they?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've retained original transactions that wrap single file. This should only affect the new outer one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are actually right; this won't work with mysql (because it has terrible support for nested transactions). I will have to rewrite this for other than postgres driver which I initially had in mind when implementing this.
Not sure I get your point. I'm just saying this full rollback would mostly be useful for deployment, but there is no implied connection.
Fair enough. I'm having troubles correcting tests for mysql anyway, so what if I enabled this mode for postgres only? Throwing during args parsing if driver is mysql and full-rollback is on. |
Sorry, I was under impression that '--production' switch in symfony commands will force this option. |
Ok I believe I'm done. Tests should be passing now; hhvm errored on packagist timeout or something. |
I rerun the hhvm buil, we will see :) |
ea75d6b
to
084163a
Compare
So the tests work now, this pull request seems to introduce no regression. Neither did c184cf1 but it broke hhvm build https://travis-ci.org/nextras/migrations/jobs/71658822 |
Usecase: running migrations during deploy should not alter the database at all. It’s handy to only rollback the last migration during development, so the original behaviour is retained. Side effect: migrations are committed at once, not per single migration. Also affects original continue mode, not just full rollback mode. Original behaviour could have caused transient problems during deploy.
@Mikulas feel free to rebase again :) |
@Mikulas one other thing: probably you could try to enhace our doc to mention it :)) |
Btw, http://www.postgresql.org/docs/9.5/static/transaction-iso.html
|
If I remember the doc correctly, that should only mean that incrementing the sequence is immediately published so no two transactions try to insert two same values. Sequence provides unique values that are not necessarily–contrary to the name–in sequence. Edit: yeah found it:
You are correct that |
Well, this is vailid also for setval, so the rollback will never be 100% reliable for all possible migrations. |
Yep I agree, but it's documented, so whoever uses the function should know it'll break. Using Anyway, I still have to write failing tests for mysql and then fix the code. Current implementation relies on nesting transactions which is apparently something mysql can't handle. |
d0ab005
to
36fd4b7
Compare
281a660
to
88684df
Compare
Usecase: running migrations during deploy should not alter the database at all. It is however handy to only rollback the last migration during development, so the original behaviour is retained.
Side effect: migrations are committed at once, not per single migration.
Also affects original continue mode, not just full rollback mode.
Original behaviour could have caused (very edge case) transient problems during deploy if one of the migrations introduced an back incompatible error fixed in another migration queued for execution and an application query was run in that time.