API Reference

Goose

Go database migration tool with a CLI and library API that applies SQL or Go migrations in order.

Official Documentation ↗
CompatibilityThis documentation covers version v3. Check the official docs for the latest API surface.

Installation

gogo install github.com/pressly/goose@latest

Methods

Overview

Goose is a Go database migration tool with a CLI and a library API that applies SQL or Go migrations in order. This reference lists the most frequently used APIs with accurate signatures and runnable snippets.

Core APIs

  • goose up — Applies all pending migrations, or up to a target version if given.
  • goose.Up — Library entry point that applies migrations against a database handle.
  • goose create — Creates a timestamped migration file with Up and Down sections.

Example

goose -dir ./migrations postgres "$DATABASE_URL" up
goose -dir ./migrations postgres "$DATABASE_URL" status

Notes

It tracks versions in a goose_db_version table. Migration files are ordered by timestamp, so keep naming consistent across branches.

Verification

Run goose up and confirm the version table lists the new version, then run goose down and confirm it is removed.

Errors

The following points are quoted verbatim from the official documentation. 来源:https://cdn.jsdelivr.net/gh/pressly/goose@latest/README.md · 取证方式:HTTP GET 官方 README/文档页(HTML 去标签) · 抓取时间:2026-11-07T13:49:58.021Z. Any error type, throw condition or recovery step not stated there is left unspecified; this page does not infer exception classes or return values.

FAQ

How does goose record applied migrations?
In a goose_db_version table it manages automatically, storing each applied version and its direction.
Can migrations be written in Go?
Yes. Create a .go migration that registers Up and Down functions via goose.AddMigration.
How do I run migrations from application code?
Call goose.Up with your sql.DB and migrations directory, or use goose.SetDialect to select the dialect first.