go-migrationGo Migration
Getting Started
Documentation

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:

bash
go version

If you need to update, visit go.dev/dl for the latest release.

Install go-migration

Add go-migration to your project using go get:

bash
go get github.com/gopackx/go-migration@v1.0.0

This installs the core package along with the schema builder, migrator, seeder, and factory modules.

Install a Database Driver

Install the driver for your database:

bash
# PostgreSQL
go get github.com/lib/pq

# MySQL
go get github.com/go-sql-driver/mysql

# SQLite
go get github.com/mattn/go-sqlite3

go-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:

bash
go install github.com/gopackx/go-migration/cmd/migrator@v1.0.0

Or use @latest to always get the most recent version:

bash
go install github.com/gopackx/go-migration/cmd/migrator@latest

go install names the binary after the last path element, so this installs a binary called migrator in your $GOBIN. The CLI refers to itself as go-migration in its help and usage text, so if you prefer that name, build it explicitly:

bash
go build -o go-migration github.com/gopackx/go-migration/cmd/migrator

The docs use go-migration for command examples — substitute migrator if you installed via go install and did not rename it.

Verify the CLI is installed:

bash
# If installed via go install:
migrator --help

# If you built/renamed it to go-migration:
go-migration --help

Once the CLI is installed, you can optionally run go-migration init (or migrator 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:

go
package main

import (
    "fmt"

    "github.com/gopackx/go-migration/pkg/migrator"
)

func main() {
    fmt.Println("go-migration installed successfully")
    _ = migrator.New
}

Run it:

bash
go run main.go

If you see go-migration installed successfully, you're ready to go. Head to the Quick Start guide to create and run your first migration.