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

feat: add RollbackAll to roll back all migrations #303

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

gnuletik
Copy link
Contributor

No description provided.

@gnuletik
Copy link
Contributor Author

@amacneil is there anything blocking this PR that I can do? Thanks!

@gregwebs gregwebs mentioned this pull request Apr 26, 2023
4 tasks
@gregwebs
Copy link

I opened #438 which allows a syntax for specifying a range of migration. That would work well combined with a command like this. But not sure if we should have a new command or have a --all flag?

@amacneil
Copy link
Owner

amacneil commented May 12, 2023

I think dbmate rollback --all is a good suggestion.

I put more thoughts in this comment.

@dossy
Copy link
Collaborator

dossy commented Nov 15, 2023

Just wondering, @gnuletik, what is the semantic difference between rollback --all and drop followed by create? And, if they are, in theory, both meant to leave the system in an identical state, wouldn't drop followed by create be preferred as it's certainly faster to execute than a rollback --all would be?

Is there an expectation that rollback --all should leave the system in a different state than a drop followed by a create? I suppose this is the case if some migrations lack a "migrate down". But, then the system in that state may not be able to migrate up without error, which is a problem.

@gnuletik
Copy link
Contributor Author

@dossy I totally agree with you.

Rolling back all migrations should leave the database in the same state as a new database if all up/down migrations file are clean.

If you missed something in your down migration, then applying all up migrations will fail. This is the use case I'm trying to cover with this command.

Having a rollback --all command would allow easy testing (e.g. in CI) of the down and up migrations.

@dossy
Copy link
Collaborator

dossy commented Nov 16, 2023

Having a rollback --all command would allow easy testing (e.g. in CI) of the down and up migrations.

😲 🤯

Okay, that's a super clever use case for rollback --all!

You do a migrate, then a rollback --all, followed by another migrate and if that throws an error the second time around, you know there's an issue with your migration scripts, somewhere.

Well, I'm sold :) on the idea! I'm sorry I never saw #292 and your previous explanation in this comment -- thanks for repeating it here.

We'll need to add the --all subcommand option to the rollback command, update the README, and add some tests, but otherwise this looks good so far.

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.

None yet

4 participants