Skip to content

Commit

Permalink
fixed errors in migration 20231003000000
Browse files Browse the repository at this point in the history
  • Loading branch information
CommanderStorm committed Oct 10, 2023
1 parent 6439adb commit a83bad3
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 7 deletions.
6 changes: 3 additions & 3 deletions server/backend/cron/dish_name_download.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,12 @@ func addDishTagsToMapping(dishID int64, dishName string, db *gorm.DB) {
}

var excludedTags []int64
errExcluded := db.Model(&model.DishNameTagOptionExcluded{}).
err := db.Model(&model.DishNameTagOptionExcluded{}).
Where("? LIKE CONCAT('%', expression ,'%')", lowercaseDish).
Select("nameTagID").
Scan(&excludedTags).Error
if errExcluded != nil {
log.WithError(errExcluded).Error("Error while querying all excluded expressions for the dish: ", lowercaseDish)
if err != nil {
log.WithError(err).Error("Error while querying all excluded expressions for the dish: ", lowercaseDish)
}

//set all entries in included to -1 if the excluded tag was recognised for this tag rating.
Expand Down
31 changes: 27 additions & 4 deletions server/backend/migration/20231003000000.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,33 @@ type DishNameTagOption struct {
EN string `gorm:"column:EN;type:text;not null;" json:"EN"`
}

// TableName sets the insert table name for this struct type
func (n *DishNameTagOption) TableName() string {
return "dish_name_tag_option"
}

type DishNameTagOptionExcluded struct {
DishNameTagOptionExcluded int64 `gorm:"primary_key;AUTO_INCREMENT;column:dishNameTagOptionExcluded;type:int;not null;" json:"dishNameTagOptionExcluded"`
NameTagID int64 `gorm:"foreignKey:dishNameTagOption;column:nameTagID;type:int;not null;" json:"nameTagID"`
Expression string `gorm:"column:expression;type:text;" json:"expression"`
}

// TableName sets the insert table name for this struct type
func (n *DishNameTagOptionExcluded) TableName() string {
return "dish_name_tag_option_excluded"
}

type DishNameTagOptionIncluded struct {
DishNameTagOptionIncluded int64 `gorm:"primary_key;AUTO_INCREMENT;column:dishNameTagOptionIncluded;type:int;not null;" json:"dishNameTagOptionIncluded"`
NameTagID int64 `gorm:"foreignKey:dishNameTagOption;column:nameTagID;type:int;not null;" json:"nameTagID"`
Expression string `gorm:"column:expression;type:text;" json:"expression"`
}

// TableName sets the insert table name for this struct type
func (n *DishNameTagOptionIncluded) TableName() string {
return "dish_name_tag_option_included"
}

//go:embed static_data
var staticData embed.FS

Expand All @@ -80,11 +95,13 @@ func (m TumDBMigrator) migrate20231003000000() *gormigrate.Migration {
setTagTable("static_data/dishRatingTags.json", tx, backend.DISH)
setTagTable("static_data/cafeteriaRatingTags.json", tx, backend.CAFETERIA)
setNameTagOptions(tx)
err := tx.Create(&model.Crontab{
if err := SafeEnumAdd(tx, &model.Crontab{}, "type", "averageRatingComputation", "dishNameDownload"); err != nil {
return err
}
if err := tx.Create(&model.Crontab{
Interval: 300,
Type: null.StringFrom("averageRatingComputation"),
}).Error
if err != nil {
}).Error; err != nil {
return err
}
return tx.Create(&model.Crontab{
Expand All @@ -96,7 +113,13 @@ func (m TumDBMigrator) migrate20231003000000() *gormigrate.Migration {
if err := tx.Where("1=1").Delete(&DishNameTagOption{}, &CafeteriaRatingTagOption{}, &DishNameTagOptionIncluded{}, &DishNameTagOptionExcluded{}).Error; err != nil {
return err
}
return nil
if err := tx.Delete(&model.Crontab{}, "type = 'averageRatingComputation'").Error; err != nil {
return err
}
if err := tx.Delete(&model.Crontab{}, "type = 'dishNameDownload'").Error; err != nil {
return err
}
return SafeEnumRemove(tx, &model.Crontab{}, "type", "dishNameDownload", "averageRatingComputation")
},
}
}
Expand Down

0 comments on commit a83bad3

Please sign in to comment.