dbmate up: Create and Migrate in One Step
dbmate up creates the database if it does not exist, applies all pending migrations, and writes the schema file.
dbmate reads the connection from DATABASE_URL. up is the convenient all-in-one; migrate is the same without the create-database step.
What it does
dbmate up runs three actions: create the database if missing, apply every pending migration from db/migrations, and dump the resulting schema to db/schema.sql. dbmate migrate does only the apply step, assuming the database already exists.
Common usage
export DATABASE_URL="postgres://ci:$DB_PASSWORD@db:5432/app?sslmode=disable"
dbmate up
# apply only, assume the database already exists (typical in CI)
dbmate migrateOptions
| Command / flag | What it does |
|---|---|
| up | Create db if needed, migrate, then dump schema |
| migrate | Apply pending migrations only (no create) |
| -d, --migrations-dir <dir> | Directory of migration files |
| -e, --env <name> | Env var to read the URL from (default DATABASE_URL) |
| --no-dump-schema | Skip writing db/schema.sql |
In CI
In CI the database usually already exists (a service container), so dbmate migrate is often the right command, avoiding the create-database privilege that up needs. Set DATABASE_URL from a secret. Use --no-dump-schema in CI if the runner should not rewrite the committed schema file.
Common errors in CI
"Error: unable to connect to database" means DATABASE_URL is wrong or the database is unreachable. "could not create database ... permission denied" from up means the CI user lacks CREATE DATABASE; use dbmate migrate against a pre-created database instead. "Error: schema_migrations table ..." can appear if the migrations table was created by a different tool.