diff --git a/migration/current.go b/migration/current.go index b4790920..f0660043 100644 --- a/migration/current.go +++ b/migration/current.go @@ -19,5 +19,6 @@ func Migrations() []*gormigrate.Migration { v10(), v11(), v12(), + v13(), } } diff --git a/migration/v13.go b/migration/v13.go new file mode 100644 index 00000000..01ee7875 --- /dev/null +++ b/migration/v13.go @@ -0,0 +1,30 @@ +package migration + +import ( + "github.com/go-gormigrate/gormigrate/v2" + "gorm.io/gorm" +) + +func v13() *gormigrate.Migration { + return &gormigrate.Migration{ + ID: "13", + Migrate: func(db *gorm.DB) error { + return db.Exec( + ` +SET @sql = ( + SELECT IF( + COUNT(*) > 0, + 'ALTER TABLE events DROP CONSTRAINT idx_name_time_start_time_end', + 'SELECT "Constraint idx_name_time_start_time_end does not exist thus not dropping it"' + ) FROM information_schema.TABLE_CONSTRAINTS + WHERE CONSTRAINT_NAME = 'idx_name_time_start_time_end' AND TABLE_NAME = 'events' +); + +PREPARE statement FROM @sql; +EXECUTE statement; +DEALLOCATE PREPARE statement; +`, + ).Error + }, + } +}