Skip to content

Core Commands

Apply and rollback migrations.

queen up

Apply pending migrations.

queen up [flags]
Flag Type Default Description
--steps int 0 Apply only N migrations (0 = all)

Examples

queen up                    # Apply all pending
queen up --steps 3          # Apply next 3
queen up --yes              # Skip confirmation (CI/CD)

Output:

All migrations applied successfully (2 applied)

Behavior

  • Each migration runs in a separate transaction.
  • Lock prevents concurrent migrations.
  • Checksums recorded after applying.
  • If a migration fails, its transaction is rolled back and execution stops.

queen down

Rollback applied migrations.

queen down [flags]
Flag Type Default Description
--steps int 0 Rollback N migrations (default: 1 if neither flag set)
--to string "" Rollback to specific version (exclusive -- keeps the target)

Cannot use both --steps and --to. If neither provided, rolls back 1 migration.

Examples

queen down                  # Rollback last migration
queen down --steps 2        # Rollback last 2
queen down --to 001         # Rollback to version 001 (keeps 001)

Output:

Rolling back migrations...
  003_add_comments rolled back (15ms)

Behavior

  • Migrations must have DownSQL or DownFunc defined.
  • Destructive migrations show warnings before executing.
  • Each rollback runs in its own transaction.

queen goto

Migrate to a specific version. Automatically determines direction.

queen goto VERSION

Examples

queen goto 005              # Migrate to version 005
queen goto latest           # Migrate to the latest version

If current version is 003, applies 004 and 005. If current version is 007, rolls back 007 and 006. If current version is 005, does nothing.

Accepts latest as a special version to apply all pending migrations.

Use Cases

  • Hotfix rollback: queen goto 009 to revert to last known good version.
  • Staging sync: queen goto 012 to match production version.

queen reset

Rollback all applied migrations.

queen reset

Examples

queen reset                 # Rollback all (prompts for confirmation)
queen reset --yes           # Skip confirmation

Output:

This will rollback ALL migrations:
  010_add_feature
  009_add_index
  ...
  001_create_users

WARNING: This is a destructive operation
Continue? [y/N]

Requires double confirmation for destructive operations.

Use Cases

  • Clean development database: queen reset --yes && queen up
  • CI/CD testing: queen up && go test ./... && queen reset --yes

Warning

All schema and data created by migrations is lost. Always backup production databases before reset.