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

Add ability to rollback migrations #2207

Open
craiglabenz opened this issue May 4, 2024 · 2 comments
Open

Add ability to rollback migrations #2207

craiglabenz opened this issue May 4, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@craiglabenz
Copy link

Is your feature request related to a problem? Please describe.

During development, it's common to iteratively build up a schema migration while adding multiple tables for a new feature. Currently, without an ability to rollback a migration, the only options are to create many small migrations (which greatly bloats a codebase) or manually remove any tables / columns added by the migration before deleting and recreating.

Describe the solution you'd like

It would be nice if migrations were generated with a rollback.sql file which could be executed if the developer indicates a specific target migration from their history.

Assuming a migration history of:

migrations/
  [timestamp-01]/
  [timestamp-02]-first-feature/

While working on that "first feature", a developer might realize they missed a column and could run:

$ dart bin/main.dart --apply-migrations --target=[timestamp-01]

Which would rollback [timestamp-02]-first-feature, allowing the developer to delete that directory, update their models' yaml files, and recreate the migration.

Additional considerations

Obviously, this feature would require additional logic to generate the DROP TABLE or ALTER SCHEMA [table] DROP [columns] queries, but I think this would be quite valuable.

@SandPod
Copy link
Contributor

SandPod commented May 6, 2024

The developer experience around this could be significantly improved with a dedicated rollback feature.

Currently, support for rolling back migrations is done by utilizing repair migrations. This is documented here: https://docs.serverpod.dev/concepts/database/migrations#rolling-back-migrations

Repair migrations can target a specific migration version using the --version option documented here: https://docs.serverpod.dev/concepts/database/migrations#targeting-a-specific-migration

@AdamMusa
Copy link
Contributor

Hey there, @craiglabenz and @SandPod I added some features here #2202

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants