Skip to Content
DatabaseMigrations

Migrations

Migrations live under db/migrations and are listed in db/migrations.go. They can be written in Go or plain SQL.

Create a new migration with the CLI:

go run cmd/cli/main.go generate migration create_users_table

Use --sql to generate a SQL migration instead of a Go one.

Run pending migrations:

go run cmd/cli/main.go db migrate

Rollback the last migration:

go run cmd/cli/main.go db rollback

You can also drop all tables with:

go run cmd/cli/main.go db clean

The migrator operates on a *gorm.DB, allowing migrations to participate in the same transactional context as your application code.

When to run migration ?

Migration are ran when the application starts, this is by default added inside the db provider, but you can also run them manually.

Last updated on