diff --git a/db/sql/migration.go b/db/sql/migration.go index 51e08eb1..fb7f2224 100644 --- a/db/sql/migration.go +++ b/db/sql/migration.go @@ -142,6 +142,16 @@ func (d *SqlDb) ApplyMigration(migration db.Migration) error { return err } + switch migration.Version { + case "2.10.24": + err = migration_2_10_24{db: d}.PreApply(tx) + } + + if err != nil { + handleRollbackError(tx.Rollback()) + return err + } + queries := getVersionSQL(getVersionPath(migration)) for i, query := range queries { fmt.Printf("\r [%d/%d]", i+1, len(query)) @@ -164,20 +174,21 @@ func (d *SqlDb) ApplyMigration(migration db.Migration) error { } } - _, err = tx.Exec(d.PrepareQuery("insert into migrations(version, upgraded_date) values (?, ?)"), migration.Version, time.Now()) + switch migration.Version { + case "2.8.26": + err = migration_2_8_26{db: d}.PostApply(tx) + case "2.8.42": + err = migration_2_8_42{db: d}.PostApply(tx) + } + if err != nil { handleRollbackError(tx.Rollback()) return err } - switch migration.Version { - case "2.8.26": - err = migration_2_8_26{db: d}.Apply(tx) - case "2.8.42": - err = migration_2_8_42{db: d}.Apply(tx) - } - + _, err = tx.Exec(d.PrepareQuery("insert into migrations(version, upgraded_date) values (?, ?)"), migration.Version, time.Now()) if err != nil { + handleRollbackError(tx.Rollback()) return err } diff --git a/db/sql/migration_2_10_24.go b/db/sql/migration_2_10_24.go new file mode 100644 index 00000000..6907b19b --- /dev/null +++ b/db/sql/migration_2_10_24.go @@ -0,0 +1,19 @@ +package sql + +import "github.com/go-gorp/gorp/v3" + +type migration_2_10_24 struct { + db *SqlDb +} + +func (m migration_2_10_24) PreApply(tx *gorp.Transaction) error { + switch m.db.sql.Dialect.(type) { + case gorp.MySQLDialect: + _, _ = tx.Exec(m.db.PrepareQuery("alter table `project__template` drop foreign key `project__template_ibfk_6`")) + case gorp.PostgresDialect: + _, err := tx.Exec( + m.db.PrepareQuery("alter table `project__template` drop constraint if exists `project__template_vault_key_id_fkey`")) + return err + } + return nil +} diff --git a/db/sql/migration_2_8_28.go b/db/sql/migration_2_8_28.go index 7973cfdf..9582c7f6 100644 --- a/db/sql/migration_2_8_28.go +++ b/db/sql/migration_2_8_28.go @@ -9,7 +9,7 @@ type migration_2_8_26 struct { db *SqlDb } -func (m migration_2_8_26) Apply(tx *gorp.Transaction) error { +func (m migration_2_8_26) PostApply(tx *gorp.Transaction) error { rows, err := tx.Query(m.db.PrepareQuery("SELECT id, git_url FROM project__repository")) if err != nil { return err diff --git a/db/sql/migration_2_8_42.go b/db/sql/migration_2_8_42.go index af787211..078ea3e4 100644 --- a/db/sql/migration_2_8_42.go +++ b/db/sql/migration_2_8_42.go @@ -6,7 +6,7 @@ type migration_2_8_42 struct { db *SqlDb } -func (m migration_2_8_42) Apply(tx *gorp.Transaction) error { +func (m migration_2_8_42) PostApply(tx *gorp.Transaction) error { switch m.db.sql.Dialect.(type) { case gorp.MySQLDialect: _, _ = tx.Exec(m.db.PrepareQuery("alter table `task` drop foreign key `task_ibfk_3`"))