atlas migrate apply: Apply Versioned Migrations
atlas migrate apply executes the pending versioned migration files in a directory against the target database.
Atlas is a modern schema tool with a versioned-migrations workflow. apply is the deploy command; it verifies the atlas.sum checksum file before running anything.
What it does
atlas migrate apply reads the migration directory, verifies its integrity against atlas.sum, and applies any files not yet recorded in the atlas_schema_revisions table. It applies in filename order and stops on the first failure.
Common usage
atlas migrate apply \
--dir "file://migrations" \
--url "postgres://ci:$DB_PASSWORD@db:5432/app?sslmode=disable"
# preview without applying
atlas migrate apply --dir "file://migrations" --url "$DB_URL" --dry-runOptions
| Flag | What it does |
|---|---|
| --dir <url> | Migration directory, e.g. file://migrations |
| --url <url> | Target database URL |
| --dry-run | Print what would run without applying |
| --revisions-schema <name> | Schema holding the revisions table |
| --allow-dirty | Apply even if the database already has objects |
In CI
Run migrate apply as a pre-deploy step. Atlas locks the database during apply to prevent concurrent runs. Regenerate atlas.sum with atlas migrate hash whenever migration files change, or apply will refuse to run in CI due to the integrity check.
Common errors in CI
"checksum mismatch" or "the migration directory is not in sync with the atlas.sum file" means files changed without rehashing; run atlas migrate hash and commit atlas.sum. "connected database is not clean" means the target already has objects Atlas did not create; use --allow-dirty on a known baseline or start from a clean database. "executing statement" errors wrap the failing SQL.