Closed tuan-tu-tran closed 2 years ago
A real pleasure to read an issue so well written. thanks @tuan-tu-tran I'm gonna check
Ok i confirm your analysis. In fact out of order migration are executed out of the transaction scope. They are never rollbacked then. I'm gonna fix that in the next version of Evolve
Thanks @lecaillon Do you have an idea when version 3.1 will be released?
Hello,
It seems the options
--transaction-mode RollbackAll
and--out-of-order
are not working well together and it's not completely rolling back everything.Say you have applied versions 2 and 3 and you add versions 1 and 4. Running
evolve migrate --transaction-mode RollbackAll --out-of-order [...]
will report that it applied 1 and 4 and that it then rolled them back. But in reality, only version 4 was rolled back and version 1 was not: it was applied and recorded in the changelog table.That's the gist of it. Hereunder are a bunch of additional details, with a powershell script that reproduces and illustrates the issue
Thanks!
Working base scenario
Consider this base scenario where Evolve behaves as expected.
First, you have 2 versioned migrations applied: 2 and 3
Then you create a versioned migration 1 i.e. with a version number lower than 2 and 3.
Trying to apply this migration results in an error, something along the lines of
Because the database is already at version 3, it considers it's an anomaly that all of a sudden a script for version 1 appears.
You can instruct Evolve to apply version 1 anyway, using the
--out-of-order
switch. From the documentation:Note: in this case, it's not really "being ignored" but it actually generates an error, but that's not the point.
So running:
Will work as expected and Evolve will apply the version 1.
Incorrect behaviour
Imagine that after applying versions 2 and 3, before applying version 1, you want to test your migrations using the
--transaction-mode RollbackAll
option.So running:
The expected behaviour is that the version 1 would be applied then rolled back.
But the observed behaviour is that:
Bug reproduction
Here's a powershell script that illustrates this