2019-05-27 02:44:40 -05:00
|
|
|
package schema
|
|
|
|
|
|
|
|
import (
|
2019-08-12 10:26:00 -08:00
|
|
|
"context"
|
2019-05-27 02:44:40 -05:00
|
|
|
"log"
|
|
|
|
|
2019-05-28 04:44:01 -05:00
|
|
|
"github.com/geeks-accelerator/sqlxmigrate"
|
2019-05-27 02:44:40 -05:00
|
|
|
"github.com/jmoiron/sqlx"
|
|
|
|
)
|
|
|
|
|
2019-08-12 10:26:00 -08:00
|
|
|
func Migrate(ctx context.Context, masterDb *sqlx.DB, log *log.Logger, isUnittest bool) error {
|
2019-05-27 02:44:40 -05:00
|
|
|
// Load list of Schema migrations and init new sqlxmigrate client
|
2019-08-12 10:26:00 -08:00
|
|
|
migrations := migrationList(ctx, masterDb, log, isUnittest)
|
2019-05-27 02:44:40 -05:00
|
|
|
m := sqlxmigrate.New(masterDb, sqlxmigrate.DefaultOptions, migrations)
|
|
|
|
m.SetLogger(log)
|
|
|
|
|
|
|
|
// Append any schema that need to be applied if this is a fresh migration
|
|
|
|
// ie. the migrations database table does not exist.
|
2019-08-12 10:26:00 -08:00
|
|
|
m.InitSchema(initSchema(ctx, masterDb, log, isUnittest))
|
2019-05-27 02:44:40 -05:00
|
|
|
|
|
|
|
// Execute the migrations
|
|
|
|
return m.Migrate()
|
|
|
|
}
|