/mgo-migrate

Migrate function of MongoDB driver for Go

Primary LanguageGoMIT LicenseMIT

mgo-migrate

GoDoc Build Status codecov Go Report Card

Migrate function of MongoDB driver for Go

How to use

package main

import (
	"github.com/appleboy/mgo-migrate"
	"gopkg.in/mgo.v2"
)

func main() {
	session, err := mgo.Dial("127.0.0.1")
	if err != nil {
		panic(err)
	}

	m := migrate.New(session, "test_db", migrate.DefaultOptions, []*migrate.Migration{{
		ID: "201709201400",
		Migrate: func(s *mgo.Session) error {
			return nil
		},
		Rollback: func(s *mgo.Session) error {
			return nil
		},
	}})

	if err := m.Migrate(); err != nil {
		panic(err)
	}

	if err := m.RollbackLast(); err != nil {
		panic(err)
	}
}