gitmyhub

goose

Go ★ 11k updated 1d ago

A database migration tool. Supports SQL migrations and Go functions.

Goose is a database migration tool for Go projects that tracks and runs SQL or Go-based schema changes for Postgres, MySQL, SQLite, and more, with rollback support.

GoSQLPostgreSQLMySQLSQLiteSQL ServerClickHousesetup: easycomplexity 2/5

Goose is a tool for managing database migrations, the controlled process of updating or rolling back the structure of a database as a software project evolves. It is written in Go and works as both a command-line program you can run directly and as a library you can import into your own Go code.

When a project's database needs a new table, a changed column, or some removed data, developers write migration files that describe those changes in sequence. Goose keeps track of which migrations have already been applied, runs the ones that have not, and can reverse them if needed. Migration files can be written as plain SQL statements or as Go functions, giving teams flexibility in how they express changes.

Goose works with many database systems, including Postgres, MySQL, SQLite, SQL Server, ClickHouse, and several others. Installing it takes one command using the standard Go toolchain, and macOS users can also install it through Homebrew.

The commands you use most often are: up to apply all pending migrations, down to roll back the most recent one, status to see which migrations have run and which are still pending, and create to generate a new migration file with a timestamp in the name. The tool also offers up-to and down-to for landing at a specific version, and reset to roll back everything at once.

A notable feature is support for out-of-order migrations, which means Goose can apply migrations correctly even when different team members created them in different orders across different environments. SQL migration files can also reference environment variables, which is useful when connection strings or schema names differ between development and production.

Where it fits