dbmate icon indicating copy to clipboard operation
dbmate copied to clipboard

Add migrate options: `--one`, `--all`, `--to`, `--only`

Open realkarych opened this issue 9 months ago • 11 comments

Implements #631 according to https://github.com/amacneil/dbmate/discussions/633

realkarych avatar Apr 06 '25 16:04 realkarych

@dossy please review

realkarych avatar Apr 07 '25 10:04 realkarych

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.

dossy avatar Apr 08 '25 21:04 dossy

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?

realkarych avatar Apr 08 '25 21:04 realkarych

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:

  1. Apply or rollback 1 (or n?) pending migrations
  2. Apply or rollback a specific migration
  3. Apply all migrations up to (and including) a specific migration version
  4. Rollback all migrations down to (excluding) a specific migration version
  5. 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?

amacneil avatar Apr 29 '25 16:04 amacneil

There is lots of prior discussion about this:

Including some thoughts I posted in #438 (comment)

I would like to see a proposal that solves all (or most) of these use cases:

  1. Apply or rollback 1 (or n?) pending migrations
  2. Apply or rollback a specific migration
  3. Apply all migrations up to (and including) a specific migration version
  4. Rollback all migrations down to (excluding) a specific migration version
  5. 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?

So good, I'll implement this in current PR this week.

realkarych avatar Apr 29 '25 19:04 realkarych

epic!

let us know when ready for a review

amacneil avatar May 01 '25 00:05 amacneil

@amacneil @dossy Ready for Review! 😊

realkarych avatar May 05 '25 20:05 realkarych

@tjarbo Ready for re-review =)

realkarych avatar May 22 '25 22:05 realkarych

Hi @amacneil is there anything else I can do to unblock this PR so that it can be merged?

Best regards

tjarbo avatar Jun 11 '25 16:06 tjarbo

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:

NINNiT avatar Sep 22 '25 14:09 NINNiT

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.

realkarych avatar Sep 23 '25 21:09 realkarych