diff --git a/HISTORY.md b/HISTORY.md index b67f81c..992dfd8 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -3,6 +3,8 @@ + +- [0.7.0](#070) - [0.6.0](#060) - [New location](#new-location) - [Deprecating Redis and RethinkDB](#deprecating-redis-and-rethinkdb) @@ -12,6 +14,15 @@ +## 0.7.0 + +Version 0.7.0 includes two minor BC breaks in the SQLManager. The method signature `CreateSchemas() ( error)` +was changed to `CreateSchemas(schema, table string) (int, error)` where int now returns the number of migrations applied. +Arguments `schema` and `table` are passed to the migration script, defining which schema and table name should be used +to store and look up migration plans. + +To keep the default values from the migrate package, use `CreateSchemas("", "")`. It is safe to reapply all migration +commands with this version - implying that you can choose an arbitrary name and it won't break your schema. ## 0.6.0 diff --git a/manager/sql/manager_sql.go b/manager/sql/manager_sql.go index b2788a8..2aac6cd 100644 --- a/manager/sql/manager_sql.go +++ b/manager/sql/manager_sql.go @@ -152,7 +152,7 @@ func NewSQLManager(db *sqlx.DB, schema []string) *SQLManager { } // CreateSchemas creates ladon_policy tables -func (s *SQLManager) CreateSchemas() error { +func (s *SQLManager) CreateSchemas(schema, table string) (int, error) { var source *migrate.MemoryMigrationSource switch s.db.DriverName() { case "postgres", "pgx": @@ -160,14 +160,16 @@ func (s *SQLManager) CreateSchemas() error { case "mysql": source = migrations["mysql"] default: - return errors.Errorf("Database driver %s is not supported", s.db.DriverName()) + return 0, errors.Errorf("Database driver %s is not supported", s.db.DriverName()) } + migrate.SetSchema(schema) + migrate.SetTable(table) n, err := migrate.Exec(s.db.DB, s.db.DriverName(), source, migrate.Up) if err != nil { - return errors.Wrapf(err, "Could not migrate sql schema, applied %d migrations", n) + return 0, errors.Wrapf(err, "Could not migrate sql schema, applied %d migrations", n) } - return nil + return n, nil } // Create inserts a new policy diff --git a/manager_all_test.go b/manager_all_test.go index cee5518..692cd3a 100644 --- a/manager_all_test.go +++ b/manager_all_test.go @@ -168,7 +168,7 @@ func connectPG(wg *sync.WaitGroup) { defer wg.Done() var db = integration.ConnectToPostgres("ladon") s := NewSQLManager(db, nil) - if err := s.CreateSchemas(); err != nil { + if _, err := s.CreateSchemas("",""); err != nil { log.Fatalf("Could not create postgres schema: %v", err) } @@ -183,7 +183,7 @@ func connectMySQL(wg *sync.WaitGroup) { defer wg.Done() var db = integration.ConnectToMySQL() s := NewSQLManager(db, nil) - if err := s.CreateSchemas(); err != nil { + if _, err := s.CreateSchemas("",""); err != nil { log.Fatalf("Could not create mysql schema: %v", err) } diff --git a/xxx_manager_sql_migrator_test.go b/xxx_manager_sql_migrator_test.go index e2098bb..337c0cf 100644 --- a/xxx_manager_sql_migrator_test.go +++ b/xxx_manager_sql_migrator_test.go @@ -13,7 +13,7 @@ func TestSQLManagerMigrateFromMajor0Minor6ToMajor0Minor7(t *testing.T) { // var db = getSqlDatabaseFromSomewhere() // s := NewSQLManager(db, nil) // - // if err := s.CreateSchemas(); err != nil { + // if _, err := s.CreateSchemas(); err != nil { // log.Fatalf("Could not create mysql schema: %v", err) // } //