Skip to content
Latchkey

How to Run Alembic and Rails Migrations in CI

Alembic applies revisions up to head and Rails runs db:migrate; both support a down path and a pending-migration check for CI.

Alembic tracks a revision chain and upgrades to head; Rails Active Record applies timestamped migrations with db:migrate. Both offer a way to roll back and to verify no migration is pending, which you run in the deploy pipeline.

Commands

Terminal
# Alembic
alembic upgrade head       # apply
alembic downgrade -1       # roll back one revision
alembic current            # show applied head

# Rails
bin/rails db:migrate       # apply
bin/rails db:rollback      # roll back last
bin/rails db:migrate:status

In CI

.github/workflows/ci.yml
jobs:
  migrate:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: alembic upgrade head
        env:
          DATABASE_URL: ${{ secrets.DATABASE_URL }}

Gotchas

  • Rails wraps each migration in a transaction; use disable_ddl_transaction! for CREATE INDEX CONCURRENTLY.
  • Alembic autogenerate can miss data changes; review the generated revision before applying.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →