Skip to content

Commit

Permalink
because the migration was partially applied in prod the migration nee…
Browse files Browse the repository at this point in the history
…ds to be slightly adjusted
  • Loading branch information
CommanderStorm committed Mar 27, 2024
1 parent 3e9f4d4 commit 71ba9da
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions server/backend/migration/20240327000000.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down

0 comments on commit 71ba9da

Please sign in to comment.