Skip to content

Bug? Expected functionality? No error thrown on rollback if migration doesn't exist #671

@alex-hall

Description

@alex-hall

Description

When attempting to rollback a migration whose file is not present in the current codebase, dbmate silently skips the missing migration and rolls back the previous available migration instead of throwing an error.

We encountered this when a migration was accidentally run against our staging database from a local machine. The staging environment didn't have the migration file, but when we attempted to rollback (from the staging app), dbmate reported success while actually rolling back the wrong migration.

While this scenario represents user error and isn't a standard workflow, the silent failure behavior is problematic because it provides misleading feedback and can cause unintended schema changes.

Version: 2.26.0
Database: Postgres
Operating System: Heroku

Steps To Reproduce

  1. Apply migration A to database
  2. Apply migration B to database
  3. Remove migration B file from codebase (simulating missing migration file)
  4. Run dbmate rollback
  5. dbmate reports "Done." and rolls back migration A instead of migration B

Expected Behavior
dbmate should throw an error when the most recent migration file cannot be found, such as:
Error: Cannot rollback migration [filename] - migration file not found

Actual Behavior
dbmate silently skips the missing migration file and rolls back the next available migration, reporting success while performing an unintended operation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions