From 71ba9dac033c165eedbf50bf2028d44a75a5d99c Mon Sep 17 00:00:00 2001 From: Frank Elsinga Date: Wed, 27 Mar 2024 22:27:09 +0100 Subject: [PATCH] because the migration was partially applied in prod the migration needs to be slightly adjusted --- server/backend/migration/20240327000000.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/server/backend/migration/20240327000000.go b/server/backend/migration/20240327000000.go index ea3624e4..fd89920a 100644 --- a/server/backend/migration/20240327000000.go +++ b/server/backend/migration/20240327000000.go @@ -15,7 +15,7 @@ func migrate20240327000000() *gormigrate.Migration { ID: "20240327000000", Migrate: func(tx *gorm.DB) error { // news_alert does have a FK on the wrong field set - if err := tx.Exec("alter table news_alert drop foreign key news_alert").Error; err != nil { + if err := tx.Exec("alter table news_alert drop foreign key if exists news_alert").Error; err != nil { return err } if err := tx.Exec("alter table news_alert add constraint news_alert_files_file_fk foreign key (file) references files (file) on delete cascade").Error; err != nil { @@ -36,7 +36,7 @@ func migrate20240327000000() *gormigrate.Migration { if err := migrateField(tx, "crontab", "cron", "BIGINT NOT NULL"); err != nil { return err } - if err := tx.Exec("alter table crontab drop key cron").Error; err != nil { + if err := tx.Exec("alter table crontab drop key if exists cron").Error; err != nil { return err } if err := tx.Exec("alter table crontab add constraint crontab_pk primary key (cron)").Error; err != nil { @@ -53,7 +53,7 @@ func migrate20240327000000() *gormigrate.Migration { }, Rollback: func(tx *gorm.DB) error { // news_alert does have a FK on the wrong field set - if err := tx.Exec("alter table news_alert drop foreign key news_alert_files_file_fk").Error; err != nil { + if err := tx.Exec("alter table news_alert drop foreign key if exists news_alert_files_file_fk").Error; err != nil { return err } if err := tx.Exec("alter table news_alert add constraint news_alert foreign key (news_alert) references files (file) on delete cascade").Error; err != nil { @@ -74,7 +74,7 @@ func migrate20240327000000() *gormigrate.Migration { if err := migrateField(tx, "crontab", "cron", "BIGINT NOT NULL"); err != nil { return err } - if err := tx.Exec("alter table crontab drop key crontab_pk").Error; err != nil { + if err := tx.Exec("alter table crontab drop key if exists crontab_pk").Error; err != nil { return err } if err := tx.Exec("alter table crontab add constraint cron unique (cron)").Error; err != nil {