A Golang framework for data migration. Focused on programmability and flexibility.
Step 1: Install gomiger and deps.
go get github.com/ParteeLabs/gomiger/core
go get github.com/urfave/cli/v3 # Optional, if you want to use the CLI
Step 2: Add the gomiger.rc.yaml
file to the root of your project.
path: './migrations' # Path to the migrations folder
pkg_name: 'mgr' # Package name
schema_store: '' # Database schema store
Step 3: Initialize the source code by running:
go run github.com/ParteeLabs/gomiger/core/cmd/gomiger-init
The source code will be initialized in the path
folder.
migrations/
├── cli.mg.go
└── migrator.mg.go
Step 4: Add you CLI entry point.
You can add any entry point (e.g. cli.go
or gomiger.go
) then import & call the Run
function in cli.mg.go
// cli.go
package main
import (
mgr "test/migrations"
)
func main() {
mgr.Run()
}
Step 5: Chose the DB plugin you want to use
Gomiger supports multiple DBs by implementing the DbPlugin
interface. You can add your plugin to the migrator.mg.go
file. Use our plugin in this monorepo or build your own plugin.
First, install the DB plugin
go get github.com/ParteeLabs/gomiger/mongomiger
Then add the DB plugin to your generate migrator.mg.go
file.
type Migrator struct {
- core.BaseMigrator
+ *mongomiger.Mongomiger
Config *core.GomigerConfig
}
func NewMigrator(config *core.GomigerConfig) core.Gomiger {
m := &Migrator{
+ Mongomiger: mongomiger.NewMongomiger(config),
Config: config,
}
...
}
Generate a new migration file.
go run cli.go new migration_name
Run migrations up.
export GOMIGER_URI="mongodb://localhost:27017"
go run cli.go up # To run all migrations
go run cli.go up version # To stop at a specific version
Run migrations down.
export GOMIGER_URI="mongodb://localhost:27017"
go run cli.go down version