Skip to content
Latchkey

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

Terminal
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 migrate

Options

Command / flagWhat it does
upCreate db if needed, migrate, then dump schema
migrateApply 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-schemaSkip 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.

Related guides

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