This guide covers installing and setting up makemigrations for Go-based database migration management.
- Go 1.24 or later — Required for building and running makemigrations
- Git — For cloning the repository
- CGO_ENABLED=1 — Required only when using SQLite; PostgreSQL and MySQL do not need CGO
- Database — One of the supported databases: PostgreSQL, MySQL, or SQLite
go install github.com/ocomsoft/makemigrations@latestThis places the makemigrations binary in $(go env GOPATH)/bin. Ensure that directory is on your PATH.
git clone https://github.com/ocomsoft/makemigrations.git
cd makemigrations
go build -o makemigrations .
# Optionally install globally
sudo cp makemigrations /usr/local/bin/Download pre-built binaries from the releases page:
# Linux/macOS
curl -L https://github.com/ocomsoft/makemigrations/releases/latest/download/makemigrations-linux-amd64 -o makemigrations
chmod +x makemigrations
# Windows
curl -L https://github.com/ocomsoft/makemigrations/releases/latest/download/makemigrations-windows-amd64.exe -o makemigrations.exeConfirm the installation is working:
makemigrations --help
makemigrations init --helpThis is the primary workflow. Migrations are generated as Go source files, compiled into a standalone binary, and applied directly against your database.
go install github.com/ocomsoft/makemigrations@latestRun init from the root of your Go project. This creates a migrations/ subdirectory with its own Go module and entry point:
makemigrations initEdit schema/schema.yaml to describe your database tables and fields:
database:
name: myapp
version: 1.0.0
tables:
- name: users
fields:
- name: id
type: uuid
primary_key: true
default: new_uuid
- name: email
type: varchar
length: 255
nullable: false
- name: created_at
type: timestamp
default: now
auto_create: truemakemigrations makemigrations --name "initial"
# Creates migrations/0001_initial.gocd migrations && go mod tidy && go build -o migrate ../migrations/migrate upAfter each change to schema.yaml, regenerate, rebuild, and apply:
makemigrations makemigrations
cd migrations && go build -o migrate .
./migrations/migrate upmyapp/
├── go.mod
├── schema/
│ └── schema.yaml # YAML schema definitions
└── migrations/
├── go.mod # separate module for the migrations binary
├── main.go # migrations binary entry point
└── 0001_initial.go # generated Go migration (after first makemigrations)
The ./migrations/migrate binary reads connection settings from environment variables.
export MAKEMIGRATIONS_DB_TYPE=postgresql
export MAKEMIGRATIONS_DB_HOST=localhost
export MAKEMIGRATIONS_DB_PORT=5432
export MAKEMIGRATIONS_DB_USER=postgres
export MAKEMIGRATIONS_DB_PASSWORD=yourpassword
export MAKEMIGRATIONS_DB_NAME=yourdb
export MAKEMIGRATIONS_DB_SSLMODE=disableexport MAKEMIGRATIONS_DB_TYPE=mysql
export MAKEMIGRATIONS_DB_HOST=localhost
export MAKEMIGRATIONS_DB_PORT=3306
export MAKEMIGRATIONS_DB_USER=root
export MAKEMIGRATIONS_DB_PASSWORD=yourpassword
export MAKEMIGRATIONS_DB_NAME=yourdbSQLite requires CGO. Build with CGO_ENABLED=1:
export MAKEMIGRATIONS_DB_TYPE=sqlite
export MAKEMIGRATIONS_DATABASE_URL=./database.dbCreate a .env file for local development:
MAKEMIGRATIONS_DB_TYPE=postgresql
MAKEMIGRATIONS_DB_HOST=localhost
MAKEMIGRATIONS_DB_PORT=5432
MAKEMIGRATIONS_DB_USER=dev_user
MAKEMIGRATIONS_DB_PASSWORD=dev_password
MAKEMIGRATIONS_DB_NAME=myapp_developmentMAKEMIGRATIONS_DB_TYPE=postgresql
MAKEMIGRATIONS_DB_HOST=production-db-host
MAKEMIGRATIONS_DB_USER=app_user
MAKEMIGRATIONS_DB_PASSWORD=secure_password
MAKEMIGRATIONS_DB_NAME=myapp_production# Ensure GOPATH/bin is on your PATH
export PATH=$PATH:$(go env GOPATH)/bin
# Or use the full path
./makemigrations --help# Check that schema.yaml exists in the expected location
find . -name "schema.yaml" -type f
# Verify directory structure
ls -la schema/# Check that environment variables are set
echo $MAKEMIGRATIONS_DB_HOST
echo $MAKEMIGRATIONS_DB_USER
# Test a direct connection
psql -h $MAKEMIGRATIONS_DB_HOST -U $MAKEMIGRATIONS_DB_USER -d $MAKEMIGRATIONS_DB_NAME# Validate YAML syntax
yamllint schema/schema.yamlSQLite requires CGO. Rebuild the migrations binary with CGO enabled:
CGO_ENABLED=1 go build -o migrate .For projects using the older YAML-to-SQL+Goose workflow, initialise with:
makemigrations init --sqlThis generates raw .sql migration files managed by Goose instead of Go source files. See docs/commands/init.md for full details.
- Read the Configuration Guide to customise settings
- Review Schema Format Documentation for YAML schema syntax
- Explore Command Documentation for detailed usage
- Set up CI/CD integration using
--checkand--silentflags
- Documentation: Browse the
/docsdirectory for detailed guides - Examples: Check the
/exampledirectory for sample schemas - Issues: Report problems on GitHub Issues
- Discussions: Join GitHub Discussions for questions
For detailed command usage, see the Commands Documentation.