Add migrate options: `--one`, `--all`, `--to`, `--only`
Implements #631 according to https://github.com/amacneil/dbmate/discussions/633
@dossy please review
Code and tests look fair, although questionable whether it's better to parameterize the migrate function vs. duplicating it with minor changes, and tests are passing, which is good.
However, I won't be approving this PR because I recognize that the decision to accept or reject this change needs to be made by someone who is better qualified to decide if this is a good change or not.
See also: #316, #434, #438.
Code and tests look fair, although questionable whether it's better to parameterize the migrate function vs. duplicating it with minor changes, and tests are passing, which is good.
However, I won't be approving this PR because I have elected to not involve myself in feature requests of this nature as I have no use for them, and I feel it encourages use of dbmate that are better served by other tools.
See also: #316, #434, #438.
Okey, who can make a decision about this feature? I agree that the option of the migrate command instead migrate-next would be better.
@amacneil Hi! What do you think about that?
There is lots of prior discussion about this:
- https://github.com/amacneil/dbmate/pull/256
- https://github.com/amacneil/dbmate/pull/316
- https://github.com/amacneil/dbmate/pull/434
- https://github.com/amacneil/dbmate/pull/438
Including some thoughts I posted in https://github.com/amacneil/dbmate/pull/438#issuecomment-1545258004
I would like to see a proposal that solves all (or most) of these use cases:
- Apply or rollback 1 (or n?) pending migrations
- Apply or rollback a specific migration
- Apply all migrations up to (and including) a specific migration version
- Rollback all migrations down to (excluding) a specific migration version
- Rollback all migrations
I think we can do this within the scope of the current migrate and rollback commands, without introducing a new command.
For example (open for comments, I think these cover all the needs people have expressed in the past):
# these flags would be supported for `dbmate up` and `dbmate down` too
dbmate migrate # existing: apply all pending migrations
dbmate rollback # existing: rollback one version
dbmate migrate --only 0003 # apply only this version
dbmate rollback --only 0003 # rollback only this version
dbmate migrate --to 0003 # migrate up to this version (inclusive)
dbmate rollback --to 0003 # roll back to this version (exclusive, i.e. the specified version will become the current applied version)
dbmate migrate --one # apply one pending migration
dbmate rollback --one # this is the default, maybe included for consistency?
dbmate rollback --all # special case to rollback all migrations
dbmate migrate --all # this is the default, maybe included for consistency?
There is lots of prior discussion about this:
- add ability to specify rollback limit/amount and the target version to migrate to #256
- Add --number flag to dbmate down #316
- specify specific migrations to use #434
- Filter migrations #438
Including some thoughts I posted in #438 (comment)
I would like to see a proposal that solves all (or most) of these use cases:
- Apply or rollback 1 (or n?) pending migrations
- Apply or rollback a specific migration
- Apply all migrations up to (and including) a specific migration version
- Rollback all migrations down to (excluding) a specific migration version
- Rollback all migrations
I think we can do this within the scope of the current
migrateandrollbackcommands, without introducing a new command.For example (open for comments, I think these cover all the needs people have expressed in the past):
# these flags would be supported for `dbmate up` and `dbmate down` too dbmate migrate # existing: apply all pending migrations dbmate rollback # existing: rollback one version dbmate migrate --only 0003 # apply only this version dbmate rollback --only 0003 # rollback only this version dbmate migrate --to 0003 # migrate up to this version (inclusive) dbmate rollback --to 0003 # roll back to this version (exclusive, i.e. the specified version will become the current applied version) dbmate migrate --one # apply one pending migration dbmate rollback --one # this is the default, maybe included for consistency? dbmate rollback --all # special case to rollback all migrations dbmate migrate --all # this is the default, maybe included for consistency?
So good, I'll implement this in current PR this week.
epic!
let us know when ready for a review
@amacneil @dossy Ready for Review! 😊
@tjarbo Ready for re-review =)
Hi @amacneil is there anything else I can do to unblock this PR so that it can be merged?
Best regards
Thanks for your work - really looking forward to this! It would help immensely in our CI pipelines / tests.
Any news on when this will make it in? :rocket:
Thanks for your work - really looking forward to this! It would help immensely in our CI pipelines / tests.
Any news on when this will make it in? 🚀
Call for @amacneil =)
I will resolve conflict if this pr will be merged after that.