From f37c458992a7190c1a6b6f15ce1c34f255717cf9 Mon Sep 17 00:00:00 2001 From: Ian Norden Date: Thu, 7 Mar 2019 15:02:13 -0600 Subject: [PATCH] the part that actually runs the migrations in order --- pkg/plugin/manager/manager.go | 39 +++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/pkg/plugin/manager/manager.go b/pkg/plugin/manager/manager.go index 54d2be17..f80edda3 100644 --- a/pkg/plugin/manager/manager.go +++ b/pkg/plugin/manager/manager.go @@ -66,21 +66,6 @@ func (m *manager) RunMigrations() error { if err != nil { 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 } @@ -125,6 +110,30 @@ func (m *manager) createMigrationCopies(paths []string) error { 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