Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move Canteen Static Data in Migration #251

Merged
merged 31 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
62ed7e4
moved old functions in new migration
tobiasjungmann Oct 4, 2023
f993188
remove unnecessary checks whether tag exists
tobiasjungmann Oct 4, 2023
0affee3
removed old initializer
tobiasjungmann Oct 4, 2023
5b665f7
delete previous data + cron entries fix
tobiasjungmann Oct 4, 2023
035e027
silenced logging of adding entries
tobiasjungmann Oct 4, 2023
a6e301b
registered the migration andfixed a few typos
CommanderStorm Oct 4, 2023
793e11c
Merge branch 'main' into chore/canteen-static-data-migration
CommanderStorm Oct 4, 2023
75a0098
fixed linting issues
CommanderStorm Oct 4, 2023
169e06b
added code review feedback
tobiasjungmann Oct 5, 2023
411564e
added state of models in migration
tobiasjungmann Oct 5, 2023
7e8ffc1
Update server/backend/migration/20231003000000.go
tobiasjungmann Oct 5, 2023
c503612
Update server/backend/migration/20231003000000.go
tobiasjungmann Oct 5, 2023
d2b702c
Update server/backend/migration/20231003000000.go
tobiasjungmann Oct 5, 2023
bfc06ef
Update server/backend/migration/20231003000000.go
tobiasjungmann Oct 5, 2023
fbe39c3
Update server/backend/migration/20231003000000.go
tobiasjungmann Oct 5, 2023
34c3b70
Update server/backend/migration/20231003000000.go
tobiasjungmann Oct 5, 2023
325cf1e
Update server/backend/migration/20231003000000.go
tobiasjungmann Oct 5, 2023
c8dde88
Update server/backend/migration/20231003000000.go
tobiasjungmann Oct 5, 2023
4571d12
Update server/backend/migration/20231003000000.go
tobiasjungmann Oct 5, 2023
c961c7a
Update server/backend/migration/20231003000000.go
tobiasjungmann Oct 5, 2023
c6edd44
Update server/backend/migration/20231003000000.go
tobiasjungmann Oct 5, 2023
efb5a20
Update server/backend/migration/20231003000000.go
tobiasjungmann Oct 5, 2023
b7f5b6b
merge feedback versions
tobiasjungmann Oct 5, 2023
0f23fc2
create missing tables in migration
tobiasjungmann Oct 6, 2023
c9bc92d
fixed batch delete in migration
tobiasjungmann Oct 6, 2023
20648b8
set fix version of migrated structs
tobiasjungmann Oct 6, 2023
8464572
formatting change
CommanderStorm Oct 6, 2023
9b6656b
formatting change
CommanderStorm Oct 6, 2023
ddc08fa
removed unnecessary create models
tobiasjungmann Oct 9, 2023
4de83d3
Merge branch 'main' into chore/canteen-static-data-migration
tobiasjungmann Oct 9, 2023
4ad7077
removed further instances of hasTable
CommanderStorm Oct 9, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions server/backend/cafeteria.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ import (
"gorm.io/gorm"
)

type modelType int
type ModelType int

// Used to differentiate between the type of the model for different queries to reduce duplicated code.
const (
DISH modelType = 1
CAFETERIA modelType = 2
NAME modelType = 3
DISH ModelType = 1
CAFETERIA ModelType = 2
NAME ModelType = 3
)

// GetCafeteriaRatings RPC Endpoint
Expand Down Expand Up @@ -284,7 +284,7 @@ type queryRatingTag struct {
// queryTags
// Queries the average ratings for either cafeteriaRatingTags, dishRatingTags or NameTags.
// Since the db only stores IDs in the results, the tags must be joined to retrieve their names form the rating_options tables.
func queryTags(cafeteriaID int32, dishID int32, ratingType modelType, tx *gorm.DB) []*pb.RatingTagResult {
func queryTags(cafeteriaID int32, dishID int32, ratingType ModelType, tx *gorm.DB) []*pb.RatingTagResult {
var results []queryRatingTag
var err error
if ratingType == DISH {
Expand Down Expand Up @@ -333,7 +333,7 @@ func queryTags(cafeteriaID int32, dishID int32, ratingType modelType, tx *gorm.D

// queryTagRatingOverviewForRating
// Query all rating tags which belong to a specific rating given with an ID and return it as TagRatingOverviews
func queryTagRatingsOverviewForRating(dishID int64, ratingType modelType, tx *gorm.DB) []*pb.RatingTagNewRequest {
func queryTagRatingsOverviewForRating(dishID int64, ratingType ModelType, tx *gorm.DB) []*pb.RatingTagNewRequest {
var results []*pb.RatingTagNewRequest
var err error
if ratingType == DISH {
Expand Down Expand Up @@ -538,7 +538,7 @@ func inputSanitizationForNewRatingElements(rating int32, comment string, cafeter
// storeRatingTags
// Checks whether the rating-tag name is a valid option and if so,
// it will be saved with a reference to the rating
func storeRatingTags(parentRatingID int64, tags []*pb.RatingTag, tagType modelType, tx *gorm.DB) error {
func storeRatingTags(parentRatingID int64, tags []*pb.RatingTag, tagType ModelType, tx *gorm.DB) error {
var errorOccurred = ""
var warningOccurred = ""
if len(tags) > 0 {
Expand Down Expand Up @@ -599,7 +599,7 @@ func storeRatingTags(parentRatingID int64, tags []*pb.RatingTag, tagType modelTy

}

func getModelStoreTag(tagType modelType, tx *gorm.DB) *gorm.DB {
func getModelStoreTag(tagType ModelType, tx *gorm.DB) *gorm.DB {
if tagType == DISH {
return tx.Model(&model.DishRatingTag{})
} else {
Expand Down
227 changes: 0 additions & 227 deletions server/backend/cafeteria_rating_db_initializer.go

This file was deleted.

16 changes: 16 additions & 0 deletions server/backend/migration/20210709193000.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ import (
"gorm.io/gorm"
)

type File struct {
File int64 `gorm:"primary_key;AUTO_INCREMENT;column:file;type:int;" json:"file"`
Name string `gorm:"column:name;type:text;size:16777215;" json:"name"`
Path string `gorm:"column:path;type:text;size:16777215;" json:"path"`
Downloads int32 `gorm:"column:downloads;type:int;default:0;" json:"downloads"`
URL null.String `gorm:"column:url;default:null;" json:"url"` // URL of the files source (if any)
Downloaded null.Bool `gorm:"column:downloaded;type:boolean;default:1;" json:"downloaded"` // true when file is ready to be served, false when still being downloaded
}

// migrate20210709193000
// adds a "url" column to the database containing the url the file was downloaded from.
// adds a "finished" column to the database that indicates, that a files download is finished.
Expand All @@ -15,6 +24,13 @@ func (m TumDBMigrator) migrate20210709193000() *gormigrate.Migration {
return &gormigrate.Migration{
ID: "20210709193000",
Migrate: func(tx *gorm.DB) error {
if !tx.Migrator().HasTable(&File{}) {
if err := m.database.AutoMigrate(
&File{},
); err != nil {
return err
}
}
CommanderStorm marked this conversation as resolved.
Show resolved Hide resolved
type Files struct {
URL null.String `gorm:"column:url;default:null;" json:"url"` // URL of the file source (if any)
Downloaded null.Bool `gorm:"column:downloaded;type:boolean;default:1;" json:"downloaded"` // true when file is ready to be served, false when still being downloaded
Expand Down
30 changes: 19 additions & 11 deletions server/backend/migration/20230826000000.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,25 @@ func (m TumDBMigrator) migrate20230826000000() *gormigrate.Migration {
return &gormigrate.Migration{
ID: "20230826000000",
Migrate: func(tx *gorm.DB) error {
if err := tx.Migrator().AddColumn(&Feedback{}, "Processed"); err != nil {
return err
}
if err := tx.Migrator().AddColumn(&Feedback{}, "OsVersion"); err != nil {
return err
}
if err := tx.Migrator().AddColumn(&Feedback{}, "AppVersion"); err != nil {
return err
}
if err := tx.Exec("UPDATE feedback SET processed = true WHERE processed != true;").Error; err != nil {
return err
if tx.Migrator().HasTable(&model.Feedback{}) {
if err := tx.Migrator().AddColumn(&Feedback{}, "Processed"); err != nil {
return err
}
if err := tx.Migrator().AddColumn(&Feedback{}, "OsVersion"); err != nil {
return err
}
if err := tx.Migrator().AddColumn(&Feedback{}, "AppVersion"); err != nil {
return err
}
if err := tx.Exec("UPDATE feedback SET processed = true WHERE processed != true;").Error; err != nil {
return err
}
} else {
if err := m.database.AutoMigrate(
&model.Feedback{},
); err != nil {
return err
}
CommanderStorm marked this conversation as resolved.
Show resolved Hide resolved
}
if err := SafeEnumMigrate(tx, &model.Crontab{}, "type", "feedbackEmail"); err != nil {
return err
Expand Down
21 changes: 18 additions & 3 deletions server/backend/migration/20230904100000.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,18 @@ import (
"gorm.io/gorm"
)

// NewsSource struct is a row record of the newsSource table in the tca database
type NewsSource struct {
Source int64 `gorm:"primary_key;AUTO_INCREMENT;column:source;type:int;"`
Title string `gorm:"column:title;type:text;size:16777215;"`
URL null.String `gorm:"column:url;type:text;size:16777215;"`
FileID int64 `gorm:"column:icon;not null;type:int;"`
File model.File `gorm:"foreignKey:FileID;references:file;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
Hook null.String `gorm:"column:hook;type:char;size:12;"`
}

// migrate20230904100000
// migrates the crontap from kino to movie crontab
// migrates the crontab from kino to movie crontab
func (m TumDBMigrator) migrate20230904100000() *gormigrate.Migration {
return &gormigrate.Migration{
ID: "20230904100000",
Expand All @@ -23,8 +33,13 @@ func (m TumDBMigrator) migrate20230904100000() *gormigrate.Migration {
if err := SafeEnumMigrate(tx, &model.Crontab{}, "type", "movie"); err != nil {
return err
}
if err := m.database.AutoMigrate(
&NewsSource{},
); err != nil {
CommanderStorm marked this conversation as resolved.
Show resolved Hide resolved
return err
}
// tu film news source is now inlined
if err := tx.Delete(&model.NewsSource{Source: 2}).Error; err != nil {
if err := tx.Delete(&NewsSource{Source: 2}).Error; err != nil {
return err
}
return tx.Create(&model.Crontab{
Expand All @@ -44,7 +59,7 @@ func (m TumDBMigrator) migrate20230904100000() *gormigrate.Migration {
if err := SafeEnumMigrate(tx, &model.Crontab{}, "type", "kino"); err != nil {
return err
}
if err := tx.Create(&model.NewsSource{
if err := tx.Create(&NewsSource{
Source: 2,
Title: "TU Film",
URL: null.StringFrom("http://www.tu-film.de/programm/index/upcoming.rss"),
Expand Down
Loading
Loading