Rollback Migrations

This guide shows you how to rollback database migrations.

Rollback Last Migration

migrator = MyDB.migrator(config)
migrator.down
puts "Rolled back one migration"

Rollback Multiple Migrations

# Rollback last 3 migrations
3.times { migrator.down }

Rollback to Specific Version

# Rollback to version 5
migrator.down_to(5)

Rollback All Migrations

# Rollback everything (use with caution!)
migrator.down_to(0)

Check Before Rollback

Safe Rollback Script

Handle Irreversible Migrations

Some migrations can't be rolled back:

When you try to rollback:

Refresh Database

Rollback all and re-migrate (development only):

Verify Rollback

Last updated

Was this helpful?