-
Notifications
You must be signed in to change notification settings - Fork 281
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
Missing up migrations applied during "down" #88
Comments
I had the same issue and looked at the code but I wasn't sure how to fix it or whether it is possible to fix it without changing the public interface of the library. In my opinion migrations should be executed from the CI/CD pipeline as a commandline tool and not by a service at startup (by using the migration tool as a library). I find the latter to be an antipattern and it makes changing/refactoring the code more difficult (because of the exported public stuff). In my opinion what you need to perform migrations is only a If we assume that we have a
Based on the above algorithm if we have a situation like this:
... and we perform a
Result:
However, I think if you have unapplied migrations that are older than some applied migrations then you already have a problem that should be resolved manually - which means that the You can easily end up with gaps in the range of your applied migrations by working on several branches and merging them. |
@pasztorpisti Cool to see you build your own tool, but please name it something else. Right now it's going to lead to a ton of confusion and it makes it impossible to have both installed at the same time (not to mention broken builds). |
@rubenv For now I think it's better if I keep the tool private for myself (less hassle for many reasons). I'll have to think about a name and need free time to change the references everywhere (CI, docker hub) if I decide to make the change. I'm a barbarian who names things by simply joins keywords so "migrate" and "sql-migrate" are pretty obvious choices. |
Same problem. |
Proposed PR #235 |
I had a situation with switching branches where the latest migration in the DB was "newer" than 2 migration files that had not yet been applied.
When running a "Down" migration, I noticed the "Up" code for both migrations was unintentionally applied and even worse they weren't recorded in the migrations table.
I tracked it down to the PlanMigration() function where it adds the results of ToCatchup(), regardless of the migration direction.
Obviously there a few issues with this. 1. They are up migrations when applying down. 2. The "catchup" migrations aren't considered in the check against the "max" parameter (which is 1 in my case). 3. The up migrations aren't recorded in the DB at all, leaving us in a broken state.
I'm not fluent in Go quite yet, otherwise I'd make a PR... but maybe the "catchup" logic should be ignored altogether for Down migrations.
The text was updated successfully, but these errors were encountered: