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:statusIn 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
How to Run Flyway and Liquibase Migrations in CIRun Flyway and Liquibase migrations in a CI/CD pipeline with their migrate and status commands, the standard…
How to Run Atlas and Prisma Migrations in CIRun Atlas and Prisma migrations in CI with atlas migrate apply and prisma migrate deploy, the declarative and…