-
Notifications
You must be signed in to change notification settings - Fork 269
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 ability to specify rollback limit/amount and the target version to migrate to #256
base: main
Are you sure you want to change the base?
Conversation
LGTM. Shall we add some tests? It would be nice (and safe!), but I don't have ideas for now |
Definetely a good idea, but I currently don't have any ideas either. Tried to make sure the existing tests don't break, at least that seemed to have worked :D |
Couple thoughts:
|
Uhm, I don't expect to rollback a specific migration in a normal workflow (except when it's the last applied). Given the fact that migrations are written to be executed in a given sequence, I don't think that you can safely assume that you can rollback only The way I see this feature is the following: consider deploying to multiple environments (test and prod), you may want to In other words: in my opinion, rolling back a specific migration in a series (skipping newer migrations) is hacky and not safe. If ever happen, you may want to look at the rollback code and execute it manually. |
Hi ! Is this the missing tests that block this PR ? |
Just added and edit some basic test here: TECHNOFAB11#1 |
Oh wow, never gotten any notification for all this and I don't use Github actively so I didn't see it, I'm so sorry :D |
test: add some to test up-to/down-to specific migrations
Is there anything needed before this can be merged? |
I opened up a PR #434 that allows specifying a single migration to use. The PR is small and easy to understand and works across all commands (such as status). It works differently though: it ignores all other migrations and assumes you are handling dependency management. So both of these could be merged in without issue, but it might be confusing for the end user. |
I opened #438 which allows a syntax of |
Separately we still need a way to rollback/down more than just one item. |
I'm kinda confused about the expected behavior from this feature. I wrote up some thoughts here. |
My main use care are the first two points in the OP. I use dbmate to migrate DBs in an init container in Kubernetes and when rolling back the app version it migrates up to the version and then down to the version to make sure the right schema exists. |
Unfortunately, merging #441 has introduced merge conflicts for this PR. Sorry, @TECHNOFAB11. I did a partial review of the code and there's something about it that bothers me but I can't clearly articulate it so I'm going to hold back commenting on the code, but there's one thing that I would like to share: How do you all feel about positional arguments for subcommands like How do people feel about specifying the version with a command option |
This PR is problematic for me because it it doesn't do anything to show what is going on ahead of time. Sure, you can calculate it, but that's what computers are for. In my PR #438 I solved this by making a filter flag rather than a bunch of commands. That way the exact same filter flag can be used with the |
I'm actually a big fan of the |
The way these commands are designed is problematic for me though. Take this migration scenario:
If I want to migrate just version C there is no way to do this.
What if I want to rollback just migration A? And already the fact that the version specified is not actually rolled back is confusing. In #438 I introduce a syntax to specify a specific migration or a migration range. I would rather to that here than have more commands that imply an upward or downward range that then have to be modified to not use that range with |
Just a quick info, I think Greg's implementation is much better for general use. I use my implementation because of a specific use case, it's never meant to be used so generally like in the examples in the comments. |
Used this evening to quickly implement #18
This now allows the following:
dbmate migrate <version>
ordbmate up <version>
→ migrates until <version> is reacheddbmate rollback <version>
→ rollbacks until <version> is reached (<version> is NOT rolled back)dbmate rollback -limit <int>
→ limits how many migrations are rolled backFeel free to edit :)