-
Notifications
You must be signed in to change notification settings - Fork 542
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 the ability to apply missing (out-of-order) migrations #280
Conversation
version = flags.Bool("version", false, "print version") | ||
certfile = flags.String("certfile", "", "file path to root CA's certificates in pem format (only support on mysql)") | ||
sequential = flags.Bool("s", false, "use sequential numbering for new migrations") | ||
allowMissing = flags.Bool("allow-missing", false, "applies missing (out-of-order) migrations") |
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 keep flip flopping on the name, I've narrowed it down to:
out-of-order
allow-missing
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.
Going with "allow-missing" terminology, which is analogous to "out-of-order"
One behaviour I don't like is that running This was always the default in Here I didn't apply migration 6 and 8. And the current
But then I ran
|
Missing migrations now raise an error when attempting to apply migrations. 2021/10/24 11:00:38 OK 00001_a.sql
2021/10/24 11:00:38 OK 00002_b.sql
2021/10/24 11:00:38 OK 00003_c.sql
2021/10/24 11:00:38 OK 00004_d.sql
2021/10/24 11:00:38 OK 00005_e.sql
2021/10/24 11:00:38 OK 00007_g.sql
error: found 1 missing migrations:
version 6: testdata/postgres/migrations/00006_f.sql |
Closes #249 #233 #262 #279 #172 and probably a bunch of other issues.
At a high, the library adds functional options to support applying missing or out-of-order migrations and the pre-built binary will have a new flag:
-allow-missing=true
or-out-of-order=true
.. not sure which name folks like better? (suggestions welcome)Note. There was an existing bug reported previously, described in detail here #279. In this PR
goose
will detect "pending" migrations and return and error unless you enable the flags (CLI) or options (library) mentioned earlier. This should have always been the behaviour, but alas this might be a breaking change to some.Those that follow hybrid-versioning should not have pending migrations and thus will not be affected.
Add a dry-run options that display what migrations will be applied without applying them.This will be a separate feature.version_id
order.Down migrations are applied in the reverse order they were applied. So up:
1, 4, 2, 3, 5
means down will be the reverse:5, 3, 2, 4, 1
.