the part that actually runs the migrations in order

This commit is contained in:
Ian Norden 2019-03-07 15:02:13 -06:00
parent b3ce1ecd78
commit f37c458992

View File

@ -66,21 +66,6 @@ func (m *manager) RunMigrations() error {
if err != nil { if err != nil {
return err return err
} }
// Fix the migrations
cmd := exec.Command("goose", "fix")
cmd.Dir = m.tmpMigDir
err = cmd.Run()
if err != nil {
return errors.New(fmt.Sprintf("version fixing for plugin migrations failed: %s", err.Error()))
}
// Run the copied migrations with goose
pgStr := fmt.Sprintf("postgres://%s:%d/%s?sslmode=disable", m.DBConfig.Hostname, m.DBConfig.Port, m.DBConfig.Name)
cmd = exec.Command("goose", "postgres", pgStr, "up")
cmd.Dir = m.tmpMigDir
err = cmd.Run()
if err != nil {
return errors.New(fmt.Sprintf("db migrations for plugin transformers failed: %s", err.Error()))
}
return nil return nil
} }
@ -125,6 +110,30 @@ func (m *manager) createMigrationCopies(paths []string) error {
return err return err
} }
} }
err = m.fixAndRun(path)
if err != nil {
return err
}
}
return nil
}
func (m *manager) fixAndRun(path string) error {
// Fix the migrations
cmd := exec.Command("goose", "fix")
cmd.Dir = m.tmpMigDir
err := cmd.Run()
if err != nil {
return errors.New(fmt.Sprintf("version fixing for plugin migrations at %s failed: %s", path, err.Error()))
}
// Run the copied migrations with goose
pgStr := fmt.Sprintf("postgres://%s:%d/%s?sslmode=disable", m.DBConfig.Hostname, m.DBConfig.Port, m.DBConfig.Name)
cmd = exec.Command("goose", "postgres", pgStr, "up")
cmd.Dir = m.tmpMigDir
err = cmd.Run()
if err != nil {
return errors.New(fmt.Sprintf("db migrations for plugin transformers at %s failed: %s", path, err.Error()))
} }
return nil return nil