diff --git a/server/backend/migration/20230825000000.go b/server/backend/migration/20230825000000.go index 6f64ea82..2e49d370 100644 --- a/server/backend/migration/20230825000000.go +++ b/server/backend/migration/20230825000000.go @@ -1,8 +1,11 @@ package migration import ( + "database/sql" + "github.com/TUM-Dev/Campus-Backend/server/model" "github.com/go-gormigrate/gormigrate/v2" + "github.com/guregu/null" "gorm.io/gorm" ) @@ -12,14 +15,19 @@ func (m TumDBMigrator) migrate20230825000000() *gormigrate.Migration { return &gormigrate.Migration{ ID: "20230825000000", Migrate: func(tx *gorm.DB) error { - // deactivete the crontab (Rollback deletes this from the enum) - // given that previously, not cronjobs for this type existed there is no need to remove offending entries first + if err := tx.Delete(&model.Crontab{}, "type = 'chat'").Error; err != nil { + return err + } return SafeEnumRollback(tx, &model.Crontab{}, "type", "chat") }, Rollback: func(tx *gorm.DB) error { - // activete the crontab (Migrate adds this from to the enum) - // given that previously, not cronjobs for this type existed there is no need to add entries first - return SafeEnumMigrate(tx, &model.Crontab{}, "type", "chat") + if err := SafeEnumMigrate(tx, &model.Crontab{}, "type", "chat"); err != nil { + return err + } + return tx.Create(&model.Crontab{ + Interval: 60 * 10, // Every 10 minutes + Type: null.String{NullString: sql.NullString{String: "chat", Valid: true}}, + }).Error }, } } diff --git a/server/backend/migration/20230904000000.go b/server/backend/migration/20230904000000.go index dd75988d..b397022b 100644 --- a/server/backend/migration/20230904000000.go +++ b/server/backend/migration/20230904000000.go @@ -16,7 +16,7 @@ func (m TumDBMigrator) migrate20230904000000() *gormigrate.Migration { ID: "20230904000000", Migrate: func(tx *gorm.DB) error { // remove "canteenHeadCount" in the enum - if err := tx.Where("type = ?", "ticketsales").Delete(&model.Crontab{}).Error; err != nil { + if err := tx.Delete(&model.Crontab{}, "type = 'ticketsales'").Error; err != nil { return err } if err := SafeEnumRollback(tx, model.Crontab{}, "type", "ticketsales"); err != nil {