goose Database migrations
Light · Postcard
102 × 152 mm · PDF
Dark · Postcard
102 × 152 mm · PDF
Ink saver · Postcard
102 × 152 mm · PDF
Light · A4 landscape
297 × 210 mm · PDF
Dark · A4 landscape
297 × 210 mm · PDF
Ink saver · A4 landscape
297 × 210 mm · PDF
Light · A3 landscape
420 × 297 mm · PDF
Dark · A3 landscape
420 × 297 mm · PDF
Ink saver · A3 landscape
420 × 297 mm · PDF
Start here
goose create <name> sql
goose <driver> <dbstring> up
goose <driver> <dbstring> status
goose <driver> <dbstring> down
goose <driver> <dbstring> redo
goose <driver> <dbstring> version
goose envgoose validateConcepts
- create new .sql file
- Up / Down SQL annotations
- Database goose_db_version
- Verified applied list
Connect
goose <driver> <dbstring> <command>
goose -dir <path> <command>
export GOOSE_DRIVER=<driver>
export GOOSE_DBSTRING=<dbstring>
export GOOSE_MIGRATION_DIR=<path>
goose -env <file> <command>
goose -table <name> <command>
goose -timeout <duration> <command>
goose -v <command>
goose -no-color <command>
goose -versiongoose -hDbstring examples
| driver | dbstring |
|---|---|
sqlite3 |
./app.db |
postgres |
"user=postgres dbname=app
sslmode=disable"
|
mysql |
"user:pass@/app?parseTime=true"
|
mssql |
"sqlserver://user:pass@host:1433?database=app"
|
clickhouse |
"tcp://127.0.0.1:9000" |
redshift |
"postgres://user:pass@host:5439/db"
|
goose -ssl-cert <file> -ssl-key <file>
<command>
goose -certfile <file> <command>
Create
goose create <name> sql
goose create <name> go
goose -s create <name> sql
goose -dir <path> create <name> sql
goose fixgoose validateSQL annotations
-- +goose Up
-- +goose Down
-- +goose NO TRANSACTION
-- +goose StatementBegin
-- +goose StatementEnd
-- +goose ENVSUB ON
-- +goose ENVSUB OFF
${VAR:-<default>}
Migrate
goose upgoose up-by-onegoose up-to <version>
goose downgoose down-to <version>
goose down-to 0goose redogoose resetgoose -allow-missing up
goose -no-versioning up
Inspect
goose statusgoose versiongoose envGo migrations
goose.AddMigration(Up, Down)
func Up(tx *sql.Tx) error
goose.Up(db, "migrations")
goose.UpByOne(db, "migrations")
goose.SetBaseFS(embedFS)
goose.SetDialect("postgres")
goose.WithAllowMissing()
Install
go install
github.com/pressly/goose/v3/cmd/goose@latest
brew install goose
go build -tags='no_mysql no_sqlite3'
./cmd/goose
Recipes
export GOOSE_DRIVER=postgresexport GOOSE_DBSTRING="user=app dbname=app sslmode=disable"goose -dir db/migrations create add_users sql# edit the file, then:goose -dir db/migrations up
-- +goose Up-- +goose StatementBeginCREATE FUNCTION touch() RETURNS trigger AS $$BEGIN NEW.updated = now(); RETURN NEW; END;$$ LANGUAGE plpgsql;-- +goose StatementEnd-- +goose DownDROP FUNCTION touch();
goose sqlite3 ./app.db upgoose sqlite3 ./app.db statusgoose sqlite3 ./app.db redo
goose -dir db/migrations validategoose -dir db/migrations fixgit add db/migrations



