Lite database schema migration tool by Go
A minimalist database schema migration tool implemented in Golang by gookit. Designed for simplicity with minimal dependencies, miglite provides a lightweight yet powerful solution for managing database schema changes.
miglite is a database migration tool that prioritizes simplicity and ease of use. Unlike heavyweight alternatives, it has minimal dependencies and is built directly on Go's database/sql package without adding any driver dependencies by default.
database/sql standard libraryYYYYMMDD-HHMMSS-{migration-name}.sqlDATABASE_URL environment variable.env files if presentmiglite.yaml if present_ (e.g., _backup/)./migrations/${MODULE_NAME})Install the miglite command-line tool globally:
# Install latest version
go install github.com/gookit/miglite/cmd/miglite@latest
# Verify installation
miglite --version
The CLI tool comes with all database drivers included (MySQL, PostgreSQL, SQLite, MSSQL).
Add miglite as a dependency to your Go project:
# Add dependency
go get github.com/gookit/miglite
# In your code
import "github.com/gookit/miglite"
Important: When using as a library, you must add your own database driver dependencies:
# For MySQL
go get github.com/go-sql-driver/mysql
# For PostgreSQL
go get github.com/lib/pq
# For SQLite (CGO-free recommended)
go get modernc.org/sqlite
# For MSSQL
go get github.com/microsoft/go-mssqldb
More drivers: https://go.dev/wiki/SQLDrivers
Create a migrations directory:
mkdir migrations
Option A: Environment Variable (Recommended)
# For SQLite
export DATABASE_URL="sqlite://./app.db"
# For MySQL
export DATABASE_URL="mysql://user:password@tcp(127.0.0.1:3306)/dbname?charset=utf8mb4&parseTime=True&loc=Local"
# For PostgreSQL
export DATABASE_URL="postgres://host=localhost port=5432 user=username password=password dbname=dbname sslmode=disable"
Option B: Configuration File
Create miglite.yaml:
database:
driver: mysql # or: sqlite, postgres, mssql
dsn: user:password@tcp(localhost:3306)/dbname?charset=utf8mb4&parseTime=True&loc=Local
migrations:
path: ./migrations
recursive: true
# Create the migration tracking table
miglite init
# Create a new migration file
miglite create create-users-table
This creates: ./migrations/20260128-143022-create-users-table.sql
Edit the file:
-- Migrate:UP
CREATE TABLE users (
id INT AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(255) NOT NULL,
email VARCHAR(255) NOT NULL UNIQUE,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- Migrate:DOWN
DROP TABLE users;
# Apply all pending migrations
miglite up
# Or skip confirmation
miglite up --yes
# View migration status
miglite status
Detailed documentation is organized into focused guides:
Complete configuration reference covering:
Comprehensive CLI documentation:
Everything about migration files:
Using miglite as a Go library:
Complete API documentation:
Recommended practices (10 key practices):
Common issues and solutions:
# Initialize migration system
miglite init
# Create new migration
miglite create MIGRATION_NAME
# Apply pending migrations
miglite up
miglite up --yes # Skip confirmation
miglite up --number 3 # Apply only 3 migrations
# Rollback migrations
miglite down
miglite down --number 2 # Rollback 2 migrations
# View migration status
miglite status
miglite status --json # JSON output
# Show database tables
miglite show
miglite show --details
# Skip migrations
miglite skip VERSION # Skip specific migration
miglite skip --all # Skip all pending
See CLI Reference for detailed documentation.
Simple Example:
package main
import (
"log"
"github.com/gookit/miglite"
"github.com/gookit/miglite/pkg/command"
_ "github.com/go-sql-driver/mysql"
)
func main() {
// Create migrator with auto-loaded config
mig, err := miglite.NewAuto()
if err != nil {
log.Fatal(err)
}
// Initialize migration table
if err := mig.Init(command.InitOption{}); err != nil {
log.Fatal(err)
}
// Run migrations
if err := mig.Up(command.UpOption{Yes: true}); err != nil {
log.Fatal(err)
}
log.Println("Migrations applied successfully!")
}
See Library Usage Guide for more examples and patterns.
MySQL:
PostgreSQL:
SQLite (CGO-free):
SQLite (CGO):
MSSQL:
Complete List:
Alternative Migration Tools:
Go database/sql:
Database Schema Migrations:
For questions and issues:
Note: This skill was auto-generated by repo2skill on 2026-01-28. For the latest information, always refer to the official repository.