Skip to content
Latchkey

goose up: Apply Go Migrations in CI

goose <driver> <dsn> up applies all pending migrations in the migrations directory, recording each in the goose_db_version table.

goose runs SQL or Go migrations. The CLI takes the driver and DSN positionally, then the command, so the invocation looks different from Flyway or Liquibase.

What it does

goose up applies every migration newer than the current version, in order, and records the version in goose_db_version. up-by-one applies just the next one. Migrations can be .sql files with up/down annotations or Go functions.

Common usage

Terminal
goose -dir ./migrations postgres \
  "host=db user=ci password=$DB_PASSWORD dbname=app sslmode=disable" up

# apply just the next migration
goose -dir ./migrations postgres "$GOOSE_DSN" up-by-one

Options

Arg / flagWhat it does
-dir <dir>Directory containing migrations
<driver>Database driver: postgres, mysql, sqlite3, etc.
<dsn>Data source name / connection string
upApply all pending migrations
up-by-oneApply only the next pending migration

In CI

Set the DSN from a secret and run goose up as a pre-deploy step. goose applies migrations sequentially and stores the version in goose_db_version; avoid running two up jobs against one database at once, since goose does not lock across processes for every driver.

Common errors in CI

"goose run: ERROR ... failed to run SQL migration" wraps the underlying SQL error from the failing file. "no migration files found" means -dir is wrong for the CI working directory. "unknown driver" means the driver name is misspelled or that build lacks that driver. A partly-applied migration can leave goose_db_version behind the real schema, so keep migrations transactional where the driver allows.

Related guides

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