Skip to content

Add ability to rollback migrations #2207

Open

Description

@craiglabenz

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.

Activity

  1. added
    enhancement
    on May 6, 2024
  2. SandPod commented on May 6, 2024

    @SandPod
    Contributor

    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

  3. AdamMusa commented on May 18, 2024

    @AdamMusa
    Contributor

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

  4. added
    area: cli
    on Jan 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: clienhancement

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions