Skip to content
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

specify specific migrations to use #434

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

gregwebs
Copy link

@gregwebs gregwebs commented Apr 20, 2023

It's not unusual for there to be multiple pending migrations but to want to carefully apply just one.
I have been forced to engage in workarounds like deleting the migration files I don't want to apply (probably most people are putting the migration file they want into a separate directory).

This ignores all other migrations and assumes you are handling dependency management.
There are other migration tools like sqitch that actually track migration dependencies. #256 provides somewhat similar functionality but will assume a dependency chain and apply multiple migrations.

Testing

This was tested manually with dbmate status by using the version and the filename and seeing that only one migration showed up. Also tested by using a non-existent version and seeing the error show up.

@gregwebs gregwebs changed the title specify just a single migration to use specify specific migrations to use Apr 21, 2023
@gregwebs
Copy link
Author

This PR is updated to allow for multiple migrations to be specified rather than just one.

@gregwebs
Copy link
Author

#256 for automatically applying multiple migrations at once by specifying one does not satisfy my workflows: I would still have to engage in workarounds. However, someone that wants that functionality can use this PR to apply multiple migrations in one go.

It would be possible to add a special syntax to this MR to directly support what is desired in #256. Something like adding a star in front: *migration would signify that all the migrations up to that one should be applied as well. The nice think about this PR is that it works with dbmate status. So you could use *migration with status to see ahead of time what would get applied. I love tools that can tell me exactly what they will do ahead of time.

@gregwebs
Copy link
Author

gregwebs commented Apr 24, 2023

It would be possible to add a special syntax to this MR to directly support what is desired in #256. Something like adding a star in front: *migration would signify that all the migrations up to that one should be applied as well. The nice think about this PR is that it works with dbmate status. So you could use *migration with status to see ahead of time what would get applied. I love tools that can tell me exactly what they will do ahead of time.

It wouldn't work to use status to see what will happen with rollback with a * syntax since it is the opposite of up. But a range syntax of ... could work.

dbmate -m ...version status # everything before and including version
dbmate -m version... status # everything starting at version and after
dbmate -m version...version2 status # everything starting at version and ending at version2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants