migrate up: golang-migrate in CI
migrate -path <dir> -database <url> up applies all pending up migrations from a directory of numbered .sql files.
golang-migrate (the migrate binary) applies plain SQL files named like 000001_name.up.sql. up runs them in order and records the version in a schema_migrations table.
What it does
migrate ... up applies every pending up migration, or the next N with up N. It tracks the current version and a dirty flag in the schema_migrations table so it knows where to resume.
Common usage
migrate -path ./migrations \
-database "postgres://ci:$DB_PASSWORD@db:5432/app?sslmode=disable" \
up
# apply just the next migration
migrate -path ./migrations -database "$DATABASE_URL" up 1Options
| Flag / arg | What it does |
|---|---|
| -path <dir> | Directory of migration files |
| -database <url> | Connection URL, e.g. postgres://... or mysql://... |
| up [N] | Apply all pending, or the next N, up migrations |
| -source <url> | Alternate source such as file:// or github:// |
| -verbose | Print each step |
In CI
Run up as a pre-deploy step. golang-migrate does not take an application-level advisory lock for every driver, so avoid running two up jobs concurrently against one database. Add ?sslmode=disable (Postgres) or the right TLS params to the URL for your runner network.
Common errors in CI
"error: Dirty database version N. Fix and force version" means a previous migration failed partway and set the dirty flag; fix the data, then run migrate force <version>. "no change" means the database is already at the latest version (exit code reflects this). "file does not exist" or "no migration found for version" means -path is wrong or files are misnumbered.