- Write migration functions with Golang
- Register functions on
MigrationManger
- Execute the
migrate
orrollback
command
If you've used rails, you'll be impressed by its migration management.
gorm-migration
is a clumsy parody, I've implemented basic migration management, including Check
, Migrate
and Rollback
.
go get github.com/icbd/gorm-migration
For some types of databases, you need to create the database
first.
It will perform all the tasks that haven't been run yet.
db := newMemoryDB()
mm := NewMigrationManger(db, Migrate)
mm.RegisterFunctions(
mm.createUsersTable,
mm.addAvatarToUsers,
mm.addEmailIndexToUsers)
mm.Migrate()
It will roll it back step by step.
# ...
mm.Type = Rollback
mm.Migrate()
# ...
mm.Type = Check
mm.Migrate()
MIT, see LICENSE