Skip to main content

Commands

Run each with go run ./cmd/migrate <command>.

No database needed​

CommandDoes
diff <name>Write a migration for what changed in the models
diff <name> --emptyWrite an empty migration to fill by hand
diff <name> --rename a.b=cTreat a change as a rename, repeatable
diff <name> --dry-runPrint the SQL and write nothing
checkFail if models, snapshot, and files are out of step
snapshotAccept the models as they are, with no migration
adopt <dump.sql>Make a schema dump the first migration
squash [name]Replace all migrations with one baseline, --keep to join them
schema-dumpPrint the whole schema as SQL, --snapshot to use the snapshot
inspect [table]List the tables and columns the models describe
scriptPrint all migrations as one idempotent file, --plain for other tools

With a database​

CommandDoes
upApply pending migrations, then changed repeatable ones
up --to <version>Stop after this version
up --dry-runPrint what would run
statusList every migration and where it stands
driftCompare the live database with the migrations, --sql for the fix
db-showSummarize the live database: version, size, and tables
baseline [version]Record migrations as applied without running them
repairAccept changed files, clear failed runs, and forget missing files
seed [name...]Run seeders
resetDelete everything and apply all migrations, --seed to seed too

These take --dsn, and otherwise read DATABASE_URL, then Config.DSN.