Installation
Install go-migration in your Go project with go get.
Installation
Check Go Version
go-migration requires Go 1.21 or later. Check your installed version:
go versionIf you need to update, visit go.dev/dl for the latest release.
Install go-migration
Add go-migration to your project using go get:
go get github.com/gopackx/go-migration@v1.0.0This installs the core package along with the schema builder, migrator, seeder, and factory modules.
Install a Database Driver
Install the driver for your database:
# PostgreSQL
go get github.com/lib/pq
# MySQL
go get github.com/go-sql-driver/mysql
# SQLite
go get github.com/mattn/go-sqlite3go-migration depends only on *sql.DB from the Go standard library. It works with any database driver that implements the database/sql interface.
CLI Installation
To use the go-migration CLI tool for generating migrations, seeders, and factories from the terminal:
go install github.com/gopackx/go-migration/cmd/migrator@v1.0.0Or use @latest to always get the most recent version:
go install github.com/gopackx/go-migration/cmd/migrator@latestVerify the CLI is installed:
go-migration --helpOnce the CLI is installed, you can optionally run go-migration init to scaffold your project structure — it creates the recommended directories, a starter cmd/migrator/main.go, and a migration.json config file. See the Quick Start guide or the CLI Reference for details.
Verify Installation
Create a simple Go file to verify everything is wired up:
package main
import (
"fmt"
"github.com/gopackx/go-migration/migrator"
)
func main() {
fmt.Println("go-migration installed successfully")
_ = migrator.New
}Run it:
go run main.goIf you see go-migration installed successfully, you're ready to go. Head to the Quick Start guide to create and run your first migration.