gin-go-migration is a lightweight Bash-based CLI tool inspired by php artisan, designed to simplify SQL-based database migrations for Golang projects.
- Automatically generates timestamped .up.sql and .down.sql migration files.
- Supports running migrations via golang-migrate.
- Works seamlessly on Windows, macOS, and Linux.
- Allows custom database connection parameters.
Make sure the following files are in the same folder:
gin-go-migration
install.sh
chmod +x install.sh
./install.shThis script will:
- Copy
gin-go-migrationto/usr/local/bin - Make it executable
- Allow you to run it directly from any terminal
Example:
gin-go-migration helpchmod +x install.sh
./install.shThis will:
- Install the script to
C:\Program Files\gin-go-migration - Create a
gin-go-migration.batwrapper so it can be run from CMD or PowerShell
After installation, you can use it directly from:
- Git Bash
- PowerShell
- CMD
Example:
gin-go-migration help- Copy the
gin-go-migrationfile to:C:\Program Files\gin-go-migration - Add that folder to your PATH environment variable.
To uninstall, simply run:
./install.sh uninstallThis will remove:
/usr/local/bin/gin-go-migration(macOS/Linux)C:\Program Files\gin-go-migration\gin-go-migrationand.batwrapper (Windows)
gin-go-migration create add_new_tableThis will generate two files inside the database/migrations/ folder:
Default output:
database/migrations/20251111224220_add_new_table.up.sql
database/migrations/20251111224220_add_new_table.down.sql
gin-go-migration create add_new_table -o ./sql/migrationsOutput:
sql/migrations/20251111224220_add_new_table.up.sql
sql/migrations/20251111224220_add_new_table.down.sql
The following command executes migrations using go-migrate:
gin-go-migration migrate -s database/migrations -db postgres -u username -p 'password' -port 5434 -ssl disable up
Expected output:
Running migration...
Migrating from: database/migrations
Database: postgres://username:password@localhost:5434/yourdb?sslmode=disable
Migration successful!
To rollback one migration step:
gin-go-migration migrate -s database/migrations -db postgres -u username -p 'password' -port 5434 -ssl disable down -1
Checking for the lastest version, then download it.
gin-go-migration update
Checking for the current version installed.
gin-go-migration version
gin-go-migration helpDisplays a list of available commands and usage examples.
-
The script automatically checks if go-migrate (from golang-migrate) is installed. If not found, it will show:
[ERROR] go-migrate not found in the system. Please install it with: go install -tags 'postgres' github.com/golang-migrate/migrate/v4/cmd/migrate@latest -
Default migration directory is
database/migrations.
- Make sure you run the script from the same folder as
install.sh - If the
gin-go-migrationcommand isn’t recognized after installation, restart your terminal - Use
sudowhen installing on macOS/Linux if permission is required
Built with ❤️