Database migrations in Go, done right.
Struct-based migrations, a fluent schema builder, seeders, factories, and a single-binary CLI — all framework-agnostic. Ship confident schema changes across PostgreSQL, MySQL, and SQLite.
package migrations
type CreateUsers struct{}
func (m *CreateUsers) Up(s *schema.Builder) {
s.Create("users", func(t *schema.Table) {
t.ID()
t.String("email").Unique()
t.String("name").Nullable()
t.Timestamps()
})
}From zero to your first migration in 60 seconds
Install the CLI, scaffold a migration, and run it. That's it.
Install the CLI with a single go install command.
go install github.com/gopackx/go-migration@latest
Generate a migration file with a sensible template.
go-migration make:migration create_users_table
Apply pending migrations to your database.
go-migration migrate ✔ 001_create_users_table
A modern take on Go database migrations
See how go-migration compares to the most popular alternatives in the Go ecosystem.
| Feature | go-migration | golang-migrate | goose |
|---|---|---|---|
| Struct-based migration API | ✓ | ✕ | Partial |
| Fluent schema builder (no raw SQL) | ✓ | ✕ | ✕ |
| Built-in seeders with dependency resolution | ✓ | ✕ | ✕ |
| Generic factories with faker support | ✓ | ✕ | ✕ |
| Transactional migrations with auto-rollback | ✓ | ✓ | ✓ |
| Database drivers supported | PG · MySQL · SQLite | 10+ drivers | 6+ drivers |
| Framework agnostic (works with any *sql.DB) | ✓ | ✓ | ✓ |
| CLI with migrate, rollback, fresh, scaffold | ✓ | Partial | ✓ |
Dive into the docs
Everything you need to ship confident migrations, organized by topic.
Getting Started
Install go-migration, scaffold your first struct migration, and run it in under five minutes.
Read more02 · SCHEMASchema Builder Reference
Every column type, index, foreign key, and constraint the fluent API supports — with examples.
Read more03 · MIGRATIONSWriting Migrations
Patterns for Up / Down methods, safe production rollouts, and version-controlled schema evolution.
Read more04 · DATASeeders & Factories
Build deterministic or faker-driven test data with factories, traits, and dependency resolution.
Read more05 · CLICLI Command Reference
Flags, environments, and output for migrate, rollback, fresh, status, seed, and scaffold commands.
Read more06 · COOKBOOKRecipes & Patterns
Real-world patterns: zero-downtime migrations, multi-tenant schemas, testing strategies, and more.
Read moreFirst-class support for every major database
PostgreSQL
9.6 → latest · JSON, arrays, CTE
MySQL / MariaDB
5.7 → latest · InnoDB tuned
SQLite
3.8+ · Ideal for tests & embedded
SQL Server
2017+ · Windows & Linux drivers
Ready to ship faster migrations?
Join thousands of Go developers managing their database schemas with confidence. Read the docs, explore examples, or drop a star on GitHub.