diff --git a/client/local/client.go b/client/local/client.go index 88df04ca..b0533b2e 100644 --- a/client/local/client.go +++ b/client/local/client.go @@ -57,7 +57,7 @@ func canteenHeadCount(c pb.CampusClient, ctx context.Context) { func canteenRatingTools(c pb.CampusClient, ctx context.Context) { currentCanteen := "MENSA_GARCHING" - currentDish := "Vegane rote Grütze mit Soja-Vanillesauce" //must be in the dish table + currentDish := "Vegane rote Grütze mit Soja-Vanillesauce" //must be in the dishes table generateDishRating(c, ctx, currentCanteen, currentDish, 3) generateCanteenRating(c, ctx, currentCanteen, 2) queryCanteen(currentCanteen, c, ctx, true) diff --git a/server/backend/cafeteria.go b/server/backend/cafeteria.go index 6f3e57c7..ca80bc92 100644 --- a/server/backend/cafeteria.go +++ b/server/backend/cafeteria.go @@ -76,7 +76,7 @@ func (s *CampusServer) GetCafeteriaRatings(ctx context.Context, input *pb.ListCa // queryLastCafeteriaRatingsWithLimit // Queries the actual ratings for a cafeteria and attaches the tag ratings which belong to the ratings func queryLastCafeteriaRatingsWithLimit(input *pb.ListCanteenRatingsRequest, cafeteriaID int32, tx *gorm.DB) []*pb.SingleRatingReply { - var ratings []model.CafeteriaRating + var ratings []model.CanteenRating var err error var limit = int(input.Limit) @@ -276,25 +276,25 @@ func queryTags(cafeteriaID int32, dishID int32, ratingType ModelType, tx *gorm.D var results []queryRatingTag var err error if ratingType == DISH { - err = tx.Table("dish_rating_tag_option options"). + err = tx.Table("dish_rating_tag_options options"). Joins("JOIN dish_rating_tag_average results ON options.dishRatingTagOption = results.tagID"). Select("options.dishRatingTagOption as tagId, results.average as avg, "+ "results.min as min, results.max as max, results.std as std"). Where("results.cafeteriaID = ? AND results.dishID = ?", cafeteriaID, dishID). Scan(&results).Error } else if ratingType == CAFETERIA { - err = tx.Table("cafeteria_rating_tag_option options"). + err = tx.Table("cafeteria_rating_tag_options options"). Joins("JOIN cafeteria_rating_tag_average results ON options.cafeteriaRatingTagOption = results.tagID"). Select("options.cafeteriaRatingTagOption as tagId, results.average as avg, "+ "results.min as min, results.max as max, results.std as std"). Where("results.cafeteriaID = ?", cafeteriaID). Scan(&results).Error } else { //Query for name tags - err = tx.Table("dish_to_dish_name_tag mapping"). + err = tx.Table("dish_to_dish_name_tags mapping"). Where("mapping.dishID = ?", dishID). Select("mapping.nameTagID as tag"). Joins("JOIN dish_name_tag_average results ON mapping.nameTagID = results.tagID"). - Joins("JOIN dish_name_tag_option options ON mapping.nameTagID = options.dishNameTagOption"). + Joins("JOIN dish_name_tag_options options ON mapping.nameTagID = options.dishNameTagOption"). Select("mapping.nameTagID as tagId, results.average as avg, " + "results.min as min, results.max as max, results.std as std"). Scan(&results).Error @@ -325,13 +325,13 @@ func queryTagRatingsOverviewForRating(dishID int64, ratingType ModelType, tx *go var results []*pb.RatingTagNewRequest var err error if ratingType == DISH { - err = tx.Table("dish_rating_tag_option options"). - Joins("JOIN dish_rating_tag rating ON options.dishRatingTagOption = rating.tagID"). + err = tx.Table("dish_rating_tag_options options"). + Joins("JOIN dish_rating_tags rating ON options.dishRatingTagOption = rating.tagID"). Select("dishRatingTagOption as tagId, points, parentRating"). Find(&results, "parentRating = ?", dishID).Error } else { - err = tx.Table("cafeteria_rating_tag_option options"). - Joins("JOIN cafeteria_rating_tag rating ON options.cafeteriaRatingTagOption = rating.tagID"). + err = tx.Table("cafeteria_rating_tag_options options"). + Joins("JOIN cafeteria_rating_tags rating ON options.cafeteriaRatingTagOption = rating.tagID"). Select("cafeteriaRatingTagOption as tagId, points, correspondingRating"). Find(&results, "correspondingRating = ?", dishID).Error } @@ -355,7 +355,7 @@ func (s *CampusServer) CreateCanteenRating(ctx context.Context, input *pb.Create } resPath := imageWrapper(input.Image, "cafeterias", cafeteriaID) - rating := model.CafeteriaRating{ + rating := model.CanteenRating{ Comment: input.Comment, Points: input.Points, CafeteriaID: cafeteriaID, @@ -501,10 +501,10 @@ func inputSanitizationForNewRatingElements(rating int32, comment string, cafeter return -1, status.Error(codes.InvalidArgument, "Comments must not contain @ symbols in order to prevent misuse. Rating has not been saved.") } - var result *model.Cafeteria + var result *model.Canteen if res := tx.First(&result, "name LIKE ?", cafeteriaName); errors.Is(res.Error, gorm.ErrRecordNotFound) || res.RowsAffected == 0 { log.WithError(res.Error).Error("Error while querying the cafeteria id by name: ", cafeteriaName) - return -1, status.Error(codes.InvalidArgument, "Cafeteria does not exist. Rating has not been saved.") + return -1, status.Error(codes.InvalidArgument, "Canteen does not exist. Rating has not been saved.") } return result.Cafeteria, nil @@ -528,7 +528,7 @@ func storeRatingTags(parentRatingID int64, tags []*pb.RatingTag, tagType ModelTy Where("dishRatingTagOption LIKE ?", currentTag.TagId). Count(&count).Error } else { - err = tx.Model(&model.CafeteriaRatingTagOption{}). + err = tx.Model(&model.CanteenRatingTagOption{}). Where("cafeteriaRatingTagOption LIKE ?", currentTag.TagId). Count(&count).Error } @@ -578,13 +578,13 @@ func getModelStoreTag(tagType ModelType, tx *gorm.DB) *gorm.DB { if tagType == DISH { return tx.Model(&model.DishRatingTag{}) } else { - return tx.Model(&model.CafeteriaRatingTag{}) + return tx.Model(&model.CanteenRatingTag{}) } } func getIDForCafeteriaName(name string, tx *gorm.DB) int32 { var result int32 = -1 - err := tx.Model(&model.Cafeteria{}). + err := tx.Model(&model.Canteen{}). Where("name LIKE ?", name). Select("cafeteria"). Scan(&result).Error @@ -646,7 +646,7 @@ func (s *CampusServer) ListNameTags(ctx context.Context, _ *pb.ListNameTagsReque func (s *CampusServer) GetAvailableCafeteriaTags(ctx context.Context, _ *pb.ListAvailableCanteenTagsRequest) (*pb.ListAvailableCanteenTagsReply, error) { var result []*pb.TagsOverview var requestStatus error = nil - err := s.db.WithContext(ctx).Model(&model.CafeteriaRatingTagOption{}).Select("DE as de, EN as en, cafeteriaRatingsTagOption as TagId").Find(&result).Error + err := s.db.WithContext(ctx).Model(&model.CanteenRatingTagOption{}).Select("DE as de, EN as en, cafeteriaRatingsTagOption as TagId").Find(&result).Error if err != nil { log.WithError(err).Error("while loading Cafeterias from database.") requestStatus = status.Error(codes.Internal, "Available cafeteria tags could not be loaded from the database.") @@ -662,7 +662,7 @@ func (s *CampusServer) GetAvailableCafeteriaTags(ctx context.Context, _ *pb.List func (s *CampusServer) GetCafeterias(ctx context.Context, _ *pb.ListCanteensRequest) (*pb.ListCanteensReply, error) { var result []*pb.Canteen var requestStatus error = nil - if err := s.db.WithContext(ctx).Model(&model.Cafeteria{}).Select("cafeteria as id,address,latitude,longitude").Scan(&result).Error; err != nil { + if err := s.db.WithContext(ctx).Model(&model.Canteen{}).Select("cafeteria as id,address,latitude,longitude").Scan(&result).Error; err != nil { log.WithError(err).Error("while loading Cafeterias from database.") requestStatus = status.Error(codes.Internal, "Cafeterias could not be loaded from the database.") } @@ -685,7 +685,7 @@ func (s *CampusServer) ListDishes(ctx context.Context, request *pb.ListDishesReq var requestStatus error = nil var results []string - err := s.db.WithContext(ctx).Table("dishes_of_the_week weekly"). + err := s.db.WithContext(ctx).Table("dishes_of_the_weeks weekly"). Where("weekly.day = ? AND weekly.week = ? and weekly.year = ?", request.Day, request.Week, request.Year). Select("weekly.dishID"). Joins("JOIN dish d ON d.dish = weekly.dishID"). diff --git a/server/backend/cron/average_rating_computation.go b/server/backend/cron/average_rating_computation.go index 9c3324bb..6d2a8f34 100644 --- a/server/backend/cron/average_rating_computation.go +++ b/server/backend/cron/average_rating_computation.go @@ -21,8 +21,8 @@ func (c *CronService) averageRatingComputation() error { func computeAverageNameTags(c *CronService) { var results []model.DishNameTagAverage err := c.db.Raw("SELECT mr.cafeteriaID as cafeteriaID, mnt.tagnameID as tagID, AVG(mnt.points) as average, MAX(mnt.points) as max, MIN(mnt.points) as min, STD(mnt.points) as std" + - " FROM dish_rating mr" + - " JOIN dish_name_tag mnt ON mr.dishRating = mnt.correspondingRating" + + " FROM dish_ratings mr" + + " JOIN dish_name_tags mnt ON mr.dishRating = mnt.correspondingRating" + " GROUP BY mr.cafeteriaID, mnt.tagnameID").Scan(&results).Error if err != nil { @@ -40,8 +40,8 @@ func computeAverageNameTags(c *CronService) { func computeAverageForDishesInCafeteriasTags(c *CronService) { var results []model.DishRatingTagAverage //todo namen im select anpassen err := c.db.Raw("SELECT mr.dishID as dishID, mr.cafeteriaID as cafeteriaID, mrt.tagID as tagID, AVG(mrt.points) as average, MAX(mrt.points) as max, MIN(mrt.points) as min, STD(mrt.points) as std" + - " FROM dish_rating mr" + - " JOIN dish_rating_tag mrt ON mr.dishRating = mrt.parentRating" + + " FROM dish_ratings mr" + + " JOIN dish_rating_tags mrt ON mr.dishRating = mrt.parentRating" + " GROUP BY mr.cafeteriaID, mrt.tagID, mr.dishID").Scan(&results).Error if err != nil { @@ -61,8 +61,8 @@ func computeAverageForDishesInCafeteriasTags(c *CronService) { func computeAverageCafeteriaTags(c *CronService) { var results []model.CafeteriaRatingTagAverage err := c.db.Raw("SELECT cr.cafeteriaID as cafeteriaID, crt.tagID as tagID, AVG(crt.points) as average, MAX(crt.points) as max, MIN(crt.points) as min, STD(crt.points) as std" + - " FROM cafeteria_rating cr" + - " JOIN cafeteria_rating_tag crt ON cr.cafeteriaRating = crt.correspondingRating" + + " FROM cafeteria_ratings cr" + + " JOIN cafeteria_rating_tags crt ON cr.cafeteriaRating = crt.correspondingRating" + " GROUP BY cr.cafeteriaID, crt.tagID").Scan(&results).Error if err != nil { @@ -98,7 +98,7 @@ func computeAverageForDishesInCafeterias(c *CronService) { func computeAverageForCafeteria(c *CronService) { var results []model.CafeteriaRatingAverage - err := c.db.Model(&model.CafeteriaRating{}). + err := c.db.Model(&model.CanteenRating{}). Select("cafeteriaID, AVG(points) as average, MAX(points) as max, MIN(points) as min, STD(points) as std"). Group("cafeteriaID").Find(&results).Error diff --git a/server/backend/cron/dish_name_download.go b/server/backend/cron/dish_name_download.go index e02e0e28..93b55db9 100644 --- a/server/backend/cron/dish_name_download.go +++ b/server/backend/cron/dish_name_download.go @@ -51,7 +51,7 @@ func (c *CronService) dishNameDownloadCron() error { func downloadDailyDishes(c *CronService) { var result []CafeteriaWithID - if err := c.db.Model(&model.Cafeteria{}).Select("name,cafeteria").Scan(&result).Error; err != nil { + if err := c.db.Model(&model.Canteen{}).Select("name,cafeteria").Scan(&result).Error; err != nil { log.WithError(err).Error("Error while querying all cafeteria names from the database.") } @@ -137,13 +137,13 @@ func downloadCanteenNames(c *CronService) { } for _, cafeteriaName := range cafeteriaNames { - mensa := model.Cafeteria{ + mensa := model.Canteen{ Name: cafeteriaName.Name, Address: cafeteriaName.Location.Address, Latitude: cafeteriaName.Location.Latitude, Longitude: cafeteriaName.Location.Longitude, } - var cafeteriaResult model.Cafeteria + var cafeteriaResult model.Canteen if err := c.db.First(&cafeteriaResult, "name = ?", cafeteriaName.Name).Error; err != nil { if err := c.db.Create(&mensa).Error; err != nil { log.WithError(err).Error("Error while creating the db entry for the cafeteria ", cafeteriaName.Name) @@ -162,7 +162,7 @@ func downloadCanteenNames(c *CronService) { func addDishTagsToMapping(dishID int64, dishName string, db *gorm.DB) { lowercaseDish := strings.ToLower(dishName) var includedTags []int64 - if err := db.Model(&model.DishNameTagOptionIncluded{}). + if err := db.Model(&model.IncludedDishNameTagOption{}). Where("? LIKE CONCAT('%', expression ,'%')", lowercaseDish). Select("nameTagID"). Scan(&includedTags).Error; err != nil { @@ -170,7 +170,7 @@ func addDishTagsToMapping(dishID int64, dishName string, db *gorm.DB) { } var excludedTags []int64 - if err := db.Model(&model.DishNameTagOptionExcluded{}). + if err := db.Model(&model.ExcludedDishNameTagOption{}). Where("? LIKE CONCAT('%', expression ,'%')", lowercaseDish). Select("nameTagID"). Scan(&excludedTags).Error; err != nil { diff --git a/server/backend/cron/movies.go b/server/backend/cron/movies.go index 1d2a85e4..56ea983c 100644 --- a/server/backend/cron/movies.go +++ b/server/backend/cron/movies.go @@ -49,7 +49,7 @@ func (c *CronService) movieCron() error { for _, item := range channel.Items { logFields := log.Fields{"link": item.Link, "title": item.Title, "date": item.PubDate, "location": item.Location, "url": item.Enclosure.Url} var exists bool - if err := c.db.Model(model.Kino{}).Select("count(*) > 0").Find(&exists, "link = ?", item.Link).Error; err != nil { + if err := c.db.Model(model.Movie{}).Select("count(*) > 0").Find(&exists, "link = ?", item.Link).Error; err != nil { log.WithError(err).WithFields(logFields).Error("Cound lot check if movie already exists") continue } @@ -89,7 +89,7 @@ func (c *CronService) movieCron() error { } // save the result of the previous steps (🎉) - movie := model.Kino{ + movie := model.Movie{ Date: date, Title: item.Title, Year: omdbMovie.ReleaseYear, diff --git a/server/backend/migration/20230825000000.go b/server/backend/migration/20230825000000.go deleted file mode 100644 index b35630c0..00000000 --- a/server/backend/migration/20230825000000.go +++ /dev/null @@ -1,31 +0,0 @@ -package migration - -import ( - "github.com/TUM-Dev/Campus-Backend/server/model" - "github.com/go-gormigrate/gormigrate/v2" - "github.com/guregu/null" - "gorm.io/gorm" -) - -// migrate20230825000000 -// Removes the ability to run chat cronjobs -func migrate20230825000000() *gormigrate.Migration { - return &gormigrate.Migration{ - ID: "20230825000000", - Migrate: func(tx *gorm.DB) error { - if err := tx.Delete(&model.Crontab{}, "type = 'chat'").Error; err != nil { - return err - } - return SafeEnumRemove(tx, &model.Crontab{}, "type", "chat") - }, - Rollback: func(tx *gorm.DB) error { - if err := SafeEnumAdd(tx, &model.Crontab{}, "type", "chat"); err != nil { - return err - } - return tx.Create(&model.Crontab{ - Interval: 60 * 10, // Every 10 minutes - Type: null.StringFrom("chat"), - }).Error - }, - } -} diff --git a/server/backend/migration/20230912000000.go b/server/backend/migration/20230912000000.go new file mode 100644 index 00000000..4af8324c --- /dev/null +++ b/server/backend/migration/20230912000000.go @@ -0,0 +1,79 @@ +package migration + +import ( + "github.com/go-gormigrate/gormigrate/v2" + "gorm.io/gorm" +) + +// migrate20230912000000 +// Removes ticketsales from the db +func migrate20230912000000() *gormigrate.Migration { + return &gormigrate.Migration{ + ID: "20230912000000", + Migrate: func(tx *gorm.DB) error { + // order intentional to avoid foreign key constraint errors + for _, tbl := range []string{"ticket_history", "ticket_type", "ticket_payment", "ticket_admin2group", "ticket_admin", "event", "ticket_group"} { + if err := tx.Migrator().DropTable(tbl); err != nil { + return err + } + } + return nil + }, + + Rollback: func(tx *gorm.DB) error { + //ticket_group + if err := tx.Exec(`create table ticket_group (ticket_group int auto_increment primary key,description text not null);`).Error; err != nil { + return err + } + //event + if err := tx.Exec("create table event(event int auto_increment primary key, news int null, kino int null, file int null, title varchar(100) not null, description text not null, locality varchar(200) not null, link varchar(200) null, start datetime null, end datetime null, ticket_group int default 1 null, constraint fkEventFile foreign key (file) references files (file) on update cascade on delete set null, constraint fkEventGroup foreign key (ticket_group) references ticket_group (ticket_group), constraint fkKino foreign key (kino) references kino (kino) on update cascade on delete set null, constraint fkNews foreign key (news) references news (news) on update cascade on delete set null);").Error; err != nil { + return err + } + if err := tx.Exec("create index file on event (file);").Error; err != nil { + return err + } + if err := tx.Exec("create fulltext index searchTitle on event (title);").Error; err != nil { + return err + } + //ticket_admin + if err := tx.Exec("create table ticket_admin(ticket_admin int auto_increment primary key, `key` text not null, created timestamp default current_timestamp() not null, active tinyint(1) default 0 not null, comment text null);").Error; err != nil { + return err + } + //ticket_admin2group + if err := tx.Exec("create table ticket_admin2group( ticket_admin2group int auto_increment primary key, ticket_admin int not null, ticket_group int not null, constraint fkTicketAdmin foreign key (ticket_admin) references ticket_admin (ticket_admin) on update cascade on delete cascade, constraint fkTicketGroup foreign key (ticket_group) references ticket_group (ticket_group) on update cascade on delete cascade);").Error; err != nil { + return err + } + if err := tx.Exec("create index ticket_admin on ticket_admin2group (ticket_admin);").Error; err != nil { + return err + } + if err := tx.Exec("create index ticket_group on ticket_admin2group (ticket_group);").Error; err != nil { + return err + } + //ticket_payment + if err := tx.Exec("create table ticket_payment( ticket_payment int auto_increment primary key, name varchar(50) not null, min_amount int null, max_amount int null, config text not null);").Error; err != nil { + return err + } + //ticket_type + if err := tx.Exec("create table ticket_type( ticket_type int auto_increment primary key, event int not null, ticket_payment int not null, price double not null, contingent int not null, description varchar(100) not null, constraint fkEvent foreign key (event) references event (event) on update cascade on delete cascade, constraint fkPayment foreign key (ticket_payment) references ticket_payment (ticket_payment) on update cascade);").Error; err != nil { + return err + } + if err := tx.Exec("create index event on ticket_type (event);").Error; err != nil { + return err + } + if err := tx.Exec("create index ticket_payment on ticket_type (ticket_payment);").Error; err != nil { + return err + } + //ticket_history + if err := tx.Exec("create table ticket_history( ticket_history int auto_increment primary key, member int not null, ticket_payment int null, ticket_type int not null, purchase datetime null, redemption datetime null, created timestamp default current_timestamp() not null, code char(128) not null, constraint fkMember foreign key (member) references member (member) on update cascade on delete cascade, constraint fkTicketPayment foreign key (ticket_payment) references ticket_payment (ticket_payment) on update cascade, constraint fkTicketType foreign key (ticket_type) references ticket_type (ticket_type) on update cascade);").Error; err != nil { + return err + } + if err := tx.Exec("create index member on ticket_history (member);").Error; err != nil { + return err + } + if err := tx.Exec("create index ticket_payment on ticket_history (ticket_payment);").Error; err != nil { + return err + } + return tx.Exec("create index ticket_type on ticket_history (ticket_type);").Error + }, + } +} diff --git a/server/backend/migration/20231003000000.go b/server/backend/migration/20231003000000.go index 1c0b696f..3cf3d880 100644 --- a/server/backend/migration/20231003000000.go +++ b/server/backend/migration/20231003000000.go @@ -164,7 +164,7 @@ func addNotIncluded(parentId int64, db *gorm.DB, v nameTag) { Expression: expression, NameTagID: parentId}).Error if err != nil { - log.WithError(err).WithFields(fields).Error("Unable to create new DishNameTagOptionExcluded") + log.WithError(err).WithFields(fields).Error("Unable to create new ExcludedDishNameTagOption") } } } diff --git a/server/backend/migration/20231023000000.go b/server/backend/migration/20231023000000.go new file mode 100644 index 00000000..e7310c27 --- /dev/null +++ b/server/backend/migration/20231023000000.go @@ -0,0 +1,93 @@ +package migration + +import ( + "github.com/TUM-Dev/Campus-Backend/server/model" + "github.com/go-gormigrate/gormigrate/v2" + "github.com/guregu/null" + "gorm.io/gorm" +) + +type device2stats struct { + ChatRoomsActivity int `gorm:"column:ChatRoomsActivity;default 0;not null"` + ChatActivity int `gorm:"column:ChatActivity;default 0;not null"` + WizNavChatActivity int `gorm:"column:WizNavChatActivity;default 0;not null"` +} + +// migrate20231023000000 +// - Removes the chat cronjob +// - Removes all traces of the chat from the database +func migrate20231023000000() *gormigrate.Migration { + return &gormigrate.Migration{ + ID: "20231023000000", + Migrate: func(tx *gorm.DB) error { + //cronjob + if err := tx.Delete(&model.Crontab{}, "type = 'chat'").Error; err != nil { + return err + } + if err := SafeEnumRemove(tx, &model.Crontab{}, "type", "chat"); err != nil { + return err + } + + // Remove tracking from device2stats + if err := tx.Migrator().DropColumn(&device2stats{}, "ChatRoomsActivity"); err != nil { + return err + } + if err := tx.Migrator().DropColumn(&device2stats{}, "ChatActivity"); err != nil { + return err + } + if err := tx.Migrator().DropColumn(&device2stats{}, "WizNavChatActivity"); err != nil { + return err + } + + // Delete all tables + if err := tx.Migrator().DropTable("chat_message"); err != nil { + return err + } + if err := tx.Migrator().DropTable("chat_room2members"); err != nil { + return err + } + return tx.Migrator().DropTable("chat_room") + }, + Rollback: func(tx *gorm.DB) error { + // Restore chat_room + if err := tx.Exec("create table chat_room(room int auto_increment primary key, name varchar(100) not null, semester varchar(3) null, constraint `Index 2` unique (semester, name));").Error; err != nil { + return err + } + + // Add tracking from device2stats + if err := tx.Migrator().AutoMigrate(&device2stats{}); err != nil { + return err + } + + // Restore chat_message + if err := tx.Exec("create table chat_message (message int auto_increment primary key, member int not null, room int not null, text longtext not null, created datetime not null, signature longtext not null, constraint FK_chat_message_chat_room foreign key (room) references chat_room (room) on update cascade on delete cascade, constraint chat_message_ibfk_1 foreign key (member) references member (member) on update cascade on delete cascade);").Error; err != nil { + return err + } + if err := tx.Exec("create index chat_message_b3c09425 on chat_message (member);").Error; err != nil { + return err + } + if err := tx.Exec("create index chat_message_ca20ebca on chat_message (room);").Error; err != nil { + return err + } + + // Restore chat_room2members + if err := tx.Exec("create table chat_room2members(room2members int auto_increment primary key, room int not null, member int not null, constraint chatroom_id unique (room, member), constraint FK_chat_room2members_chat_room foreign key (room) references chat_room (room) on update cascade on delete cascade, constraint chat_room2members_ibfk_2 foreign key (member) references member (member) on update cascade on delete cascade );").Error; err != nil { + return err + } + if err := tx.Exec("create index chat_chatroom_members_29801a33 on chat_room2members (room);").Error; err != nil { + return err + } + if err := tx.Exec("create index chat_chatroom_members_b3c09425 on chat_room2members (member);").Error; err != nil { + return err + } + //cronjob + if err := SafeEnumAdd(tx, &model.Crontab{}, "type", "chat"); err != nil { + return err + } + return tx.Create(&model.Crontab{ + Interval: 60 * 10, // Every 10 minutes + Type: null.StringFrom("chat"), + }).Error + }, + } +} diff --git a/server/backend/migration/20231024000000.go b/server/backend/migration/20231024000000.go new file mode 100644 index 00000000..0c39d020 --- /dev/null +++ b/server/backend/migration/20231024000000.go @@ -0,0 +1,58 @@ +package migration + +import ( + "github.com/go-gormigrate/gormigrate/v2" + "gorm.io/gorm" +) + +type wrongTableName struct { + Original string + New string +} + +var wrongTableNames = []wrongTableName{ + {"crontab", "crontabs"}, + {"kino", "movies"}, + {"cafeteria", "canteens"}, + {"canteen_head_count", "canteen_head_counts"}, + {"cafeteria_rating", "canteen_ratings"}, + {"cafeteria_rating_tag", "canteen_rating_tags"}, + {"cafeteria_rating_tag_option", "canteen_rating_tag_options"}, + {"dish", "dishes"}, + {"dish_rating", "dish_ratings"}, + {"dish_rating_tag", "dish_rating_tags"}, + {"dish_rating_tag_option", "dish_rating_tag_options"}, + {"dish_name_tag", "dish_name_tags"}, + {"dish_name_tag_option", "dish_name_tag_options"}, + {"dish_name_tag_option_excluded", "excluded_dish_name_tag_options"}, + {"dish_name_tag_option_included", "included_dish_name_tag_option"}, + {"dish_to_dish_name_tag", "dish_to_dish_name_tags"}, + {"dishes_of_the_week", "dishes_of_the_weeks"}, + {"update_note", "update_notes"}, + {"newsSource", "news_sources"}, + {"news_alert", "news_alerts"}, +} + +// migrate20231024000000 +// - replaces all instances of misleadingly named tables with the correct ones +func migrate20231024000000() *gormigrate.Migration { + return &gormigrate.Migration{ + ID: "20231024000000", + Migrate: func(tx *gorm.DB) error { + for _, table := range wrongTableNames { + if err := tx.Migrator().RenameTable(table.Original, table.New); err != nil { + return err + } + } + return nil + }, + Rollback: func(tx *gorm.DB) error { + for _, table := range wrongTableNames { + if err := tx.Migrator().RenameTable(table.New, table.Original); err != nil { + return err + } + } + return nil + }, + } +} diff --git a/server/backend/migration/migration.go b/server/backend/migration/migration.go index 2c477d31..31017e7c 100644 --- a/server/backend/migration/migration.go +++ b/server/backend/migration/migration.go @@ -12,12 +12,12 @@ import ( func autoMigrate(db *gorm.DB) error { err := db.AutoMigrate( - &model.Cafeteria{}, - &model.CafeteriaRating{}, + &model.Canteen{}, + &model.CanteenRating{}, &model.CafeteriaRatingAverage{}, - &model.CafeteriaRatingTag{}, + &model.CanteenRatingTag{}, &model.CafeteriaRatingTagAverage{}, - &model.CafeteriaRatingTagOption{}, + &model.CanteenRatingTagOption{}, &model.CanteenHeadCount{}, &model.Crontab{}, &model.Device{}, @@ -25,8 +25,8 @@ func autoMigrate(db *gorm.DB) error { &model.DishNameTag{}, &model.DishNameTagAverage{}, &model.DishNameTagOption{}, - &model.DishNameTagOptionExcluded{}, - &model.DishNameTagOptionIncluded{}, + &model.ExcludedDishNameTagOption{}, + &model.IncludedDishNameTagOption{}, &model.DishRating{}, &model.DishRatingAverage{}, &model.DishRatingTag{}, @@ -45,7 +45,7 @@ func autoMigrate(db *gorm.DB) error { //&model.IOSRemoteNotification...{}, -- wtf??? &model.IOSScheduledUpdateLog{}, &model.IOSSchedulingPriority{}, - &model.Kino{}, + &model.Movie{}, &model.NewExamResultsSubscriber{}, &model.News{}, &model.NewsAlert{}, @@ -73,12 +73,14 @@ func manualMigrate(db *gorm.DB) error { migrate20220713000000(), migrate20221119131300(), migrate20221210000000(), - migrate20230825000000(), + migrate20230912000000(), migrate20230904000000(), migrate20230530000000(), migrate20230904100000(), migrate20230826000000(), migrate20231003000000(), + migrate20231023000000(), + migrate20231024000000(), } return gormigrate.New(db, gormigrateOptions, migrations).Migrate() } diff --git a/server/backend/movie.go b/server/backend/movie.go index 12981ccd..c722db6b 100644 --- a/server/backend/movie.go +++ b/server/backend/movie.go @@ -12,7 +12,7 @@ import ( ) func (s *CampusServer) ListMovies(ctx context.Context, req *pb.ListMoviesRequest) (*pb.ListMoviesReply, error) { - var movies []model.Kino + var movies []model.Movie tx := s.db.WithContext(ctx).Joins("File") if req.OldestDateAt.GetSeconds() != 0 || req.OldestDateAt.GetNanos() != 0 { tx = tx.Where("date > ?", req.OldestDateAt.AsTime()) @@ -24,7 +24,7 @@ func (s *CampusServer) ListMovies(ctx context.Context, req *pb.ListMoviesRequest var movieResponse []*pb.Movie for _, movie := range movies { movieResponse = append(movieResponse, &pb.Movie{ - MovieId: movie.Id, + MovieId: movie.Movie, Date: timestamppb.New(movie.Date), Created: timestamppb.New(movie.Created), Title: movie.Title, diff --git a/server/backend/news.go b/server/backend/news.go index f8f29847..89404f5b 100644 --- a/server/backend/news.go +++ b/server/backend/news.go @@ -23,7 +23,7 @@ func (s *CampusServer) ListNewsSources(ctx context.Context, _ *pb.ListNewsSource var sources []model.NewsSource if err := s.db.WithContext(ctx).Joins("File").Find(&sources).Error; err != nil { - log.WithError(err).Error("could not find newsSources") + log.WithError(err).Error("could not find news_sources") return nil, status.Error(codes.Internal, "could not ListNewsSources") } @@ -89,9 +89,9 @@ func (s *CampusServer) ListNewsAlerts(ctx context.Context, req *pb.ListNewsAlert } var res []*model.NewsAlert - tx := s.db.WithContext(ctx).Joins("File").Where("news_alert.to >= NOW()") + tx := s.db.WithContext(ctx).Joins("File").Where("news_alerts.to >= NOW()") if req.LastNewsAlertId != 0 { - tx = tx.Where("news_alert.news_alert > ?", req.LastNewsAlertId) + tx = tx.Where("news_alerts.news_alert > ?", req.LastNewsAlertId) } if err := tx.Find(&res).Error; errors.Is(err, gorm.ErrRecordNotFound) { return nil, status.Error(codes.NotFound, "no news alerts") diff --git a/server/backend/news_test.go b/server/backend/news_test.go index 62922c7c..242fb1d6 100644 --- a/server/backend/news_test.go +++ b/server/backend/news_test.go @@ -85,7 +85,7 @@ func source2() *model.NewsSource { } } -const ExpectedListNewsSourcesQuery = "SELECT `newsSource`.`source`,`newsSource`.`title`,`newsSource`.`url`,`newsSource`.`icon`,`newsSource`.`hook`,`File`.`file` AS `File__file`,`File`.`name` AS `File__name`,`File`.`path` AS `File__path`,`File`.`downloads` AS `File__downloads`,`File`.`url` AS `File__url`,`File`.`downloaded` AS `File__downloaded` FROM `newsSource` LEFT JOIN `files` `File` ON `newsSource`.`icon` = `File`.`file`" +const ExpectedListNewsSourcesQuery = "SELECT `news_sources`.`source`,`news_sources`.`title`,`news_sources`.`url`,`news_sources`.`icon`,`news_sources`.`hook`,`File`.`file` AS `File__file`,`File`.`name` AS `File__name`,`File`.`path` AS `File__path`,`File`.`downloads` AS `File__downloads`,`File`.`url` AS `File__url`,`File`.`downloaded` AS `File__downloaded` FROM `news_sources` LEFT JOIN `files` `File` ON `news_sources`.`icon` = `File`.`file`" func (s *NewsSuite) Test_ListNewsSourcesMultiple() { s1, s2 := source1(), source2() @@ -141,7 +141,7 @@ func (s *NewsSuite) Test_ListNewsSourcesNone() { require.Equal(s.T(), expectedResp, response) } -const ExpectedListNewsQuery = "SELECT `news`.`news`,`news`.`date`,`news`.`created`,`news`.`title`,`news`.`description`,`news`.`src`,`news`.`link`,`news`.`image`,`news`.`file`,`File`.`file` AS `File__file`,`File`.`name` AS `File__name`,`File`.`path` AS `File__path`,`File`.`downloads` AS `File__downloads`,`File`.`url` AS `File__url`,`File`.`downloaded` AS `File__downloaded`,`NewsSource`.`source` AS `NewsSource__source`,`NewsSource`.`title` AS `NewsSource__title`,`NewsSource`.`url` AS `NewsSource__url`,`NewsSource`.`icon` AS `NewsSource__icon`,`NewsSource`.`hook` AS `NewsSource__hook`,`NewsSource__File`.`file` AS `NewsSource__File__file`,`NewsSource__File`.`name` AS `NewsSource__File__name`,`NewsSource__File`.`path` AS `NewsSource__File__path`,`NewsSource__File`.`downloads` AS `NewsSource__File__downloads`,`NewsSource__File`.`url` AS `NewsSource__File__url`,`NewsSource__File`.`downloaded` AS `NewsSource__File__downloaded` FROM `news` LEFT JOIN `files` `File` ON `news`.`file` = `File`.`file` LEFT JOIN `newsSource` `NewsSource` ON `news`.`src` = `NewsSource`.`source` LEFT JOIN `files` `NewsSource__File` ON `NewsSource`.`icon` = `NewsSource__File`.`file`" +const ExpectedListNewsQuery = "SELECT `news`.`news`,`news`.`date`,`news`.`created`,`news`.`title`,`news`.`description`,`news`.`src`,`news`.`link`,`news`.`image`,`news`.`file`,`File`.`file` AS `File__file`,`File`.`name` AS `File__name`,`File`.`path` AS `File__path`,`File`.`downloads` AS `File__downloads`,`File`.`url` AS `File__url`,`File`.`downloaded` AS `File__downloaded`,`NewsSource`.`source` AS `NewsSource__source`,`NewsSource`.`title` AS `NewsSource__title`,`NewsSource`.`url` AS `NewsSource__url`,`NewsSource`.`icon` AS `NewsSource__icon`,`NewsSource`.`hook` AS `NewsSource__hook`,`NewsSource__File`.`file` AS `NewsSource__File__file`,`NewsSource__File`.`name` AS `NewsSource__File__name`,`NewsSource__File`.`path` AS `NewsSource__File__path`,`NewsSource__File`.`downloads` AS `NewsSource__File__downloads`,`NewsSource__File`.`url` AS `NewsSource__File__url`,`NewsSource__File`.`downloaded` AS `NewsSource__File__downloaded` FROM `news` LEFT JOIN `files` `File` ON `news`.`file` = `File`.`file` LEFT JOIN `news_sources` `NewsSource` ON `news`.`src` = `NewsSource`.`source` LEFT JOIN `files` `NewsSource__File` ON `NewsSource`.`icon` = `NewsSource__File`.`file`" func (s *NewsSuite) Test_ListNewsNone_withFilters() { s.mock.ExpectQuery(regexp.QuoteMeta(ExpectedListNewsQuery+" WHERE src = ? AND news > ?")). @@ -227,7 +227,7 @@ func alert2() *model.NewsAlert { } } -const ExpectedListNewsAlertsQuery = "SELECT `news_alert`.`news_alert`,`news_alert`.`file`,`news_alert`.`name`,`news_alert`.`link`,`news_alert`.`created`,`news_alert`.`from`,`news_alert`.`to`,`File`.`file` AS `File__file`,`File`.`name` AS `File__name`,`File`.`path` AS `File__path`,`File`.`downloads` AS `File__downloads`,`File`.`url` AS `File__url`,`File`.`downloaded` AS `File__downloaded` FROM `news_alert` LEFT JOIN `files` `File` ON `news_alert`.`file` = `File`.`file` WHERE news_alert.to >= NOW()" +const ExpectedListNewsAlertsQuery = "SELECT `news_alerts`.`news_alerts`,`news_alerts`.`file`,`news_alerts`.`name`,`news_alerts`.`link`,`news_alerts`.`created`,`news_alerts`.`from`,`news_alerts`.`to`,`File`.`file` AS `File__file`,`File`.`name` AS `File__name`,`File`.`path` AS `File__path`,`File`.`downloads` AS `File__downloads`,`File`.`url` AS `File__url`,`File`.`downloaded` AS `File__downloaded` FROM `news_alerts` LEFT JOIN `files` `File` ON `news_alerts`.`file` = `File`.`file` WHERE news_alert.to >= NOW()" func (s *NewsSuite) Test_ListNewsAlertsError() { s.mock.ExpectQuery(regexp.QuoteMeta(ExpectedListNewsAlertsQuery)).WillReturnError(gorm.ErrInvalidDB) @@ -247,7 +247,7 @@ func (s *NewsSuite) Test_ListNewsAlertsNone_noFilter() { require.Nil(s.T(), response) } func (s *NewsSuite) Test_ListNewsAlertsNone_Filter() { - s.mock.ExpectQuery(regexp.QuoteMeta(ExpectedListNewsAlertsQuery + " AND news_alert.news_alert > ?")).WithArgs(42).WillReturnError(gorm.ErrRecordNotFound) + s.mock.ExpectQuery(regexp.QuoteMeta(ExpectedListNewsAlertsQuery + " AND news_alerts.news_alert > ?")).WithArgs(42).WillReturnError(gorm.ErrRecordNotFound) server := CampusServer{db: s.DB, deviceBuf: s.deviceBuf} response, err := server.ListNewsAlerts(metadata.NewIncomingContext(context.Background(), metadata.MD{}), &pb.ListNewsAlertsRequest{LastNewsAlertId: 42}) diff --git a/server/model/cafeteria_rating.go b/server/model/cafeteria_rating.go index cfa5f686..9eb437ae 100644 --- a/server/model/cafeteria_rating.go +++ b/server/model/cafeteria_rating.go @@ -4,8 +4,8 @@ import ( "time" ) -// CafeteriaRating stores all Available cafeterias in the format of the eat-api -type CafeteriaRating struct { +// CanteenRating stores all Available cafeterias in the format of the eat-api +type CanteenRating struct { CafeteriaRating int64 `gorm:"primary_key;AUTO_INCREMENT;column:cafeteriaRating;type:int;not null;" json:"canteenrating"` Points int32 `gorm:"column:points;type:int;not null;" json:"points"` Comment string `gorm:"column:comment;type:text;" json:"comment" ` @@ -13,8 +13,3 @@ type CafeteriaRating struct { Timestamp time.Time `gorm:"column:timestamp;type:timestamp;not null;" json:"timestamp" ` Image string `gorm:"column:image;type:text;" json:"image"` } - -// TableName sets the insert table name for this struct type -func (n *CafeteriaRating) TableName() string { - return "cafeteria_rating" -} diff --git a/server/model/cafeteria_rating_tag.go b/server/model/cafeteria_rating_tag.go index 15e964b6..225fe195 100644 --- a/server/model/cafeteria_rating_tag.go +++ b/server/model/cafeteria_rating_tag.go @@ -1,14 +1,9 @@ package model -// CafeteriaRatingTag struct is a row record of the either the dish_tag_rating-table or the cafeteria_rating_tags-table in the database -type CafeteriaRatingTag struct { - CafeteriaRatingTag int64 `gorm:"primary_key;AUTO_INCREMENT;column:CafeteriaRatingTag;type:int;not null;" json:"CanteenRatingTag" ` +// CanteenRatingTag struct is a row record of the either the dish_tag_ratings-table or the cafeteria_rating_tags-table in the database +type CanteenRatingTag struct { + CafeteriaRatingTag int64 `gorm:"primary_key;AUTO_INCREMENT;column:CanteenRatingTag;type:int;not null;" json:"CanteenRatingTag" ` CorrespondingRating int64 `gorm:"foreignKey:cafeteriaRatingID;column:correspondingRating;type:int;not null;" json:"correspondingRating"` Points int32 `gorm:"column:points;type:int;not null;" json:"points"` TagID int64 `gorm:"foreignKey:cafeteriaRatingTagOption;column:tagID;type:int;not null;" json:"tagID"` } - -// TableName sets the insert table name for this struct type -func (n *CafeteriaRatingTag) TableName() string { - return "cafeteria_rating_tag" -} diff --git a/server/model/cafeteria_rating_tag_option.go b/server/model/cafeteria_rating_tag_option.go index e5d27d49..45c52c23 100644 --- a/server/model/cafeteria_rating_tag_option.go +++ b/server/model/cafeteria_rating_tag_option.go @@ -1,13 +1,8 @@ package model -// CafeteriaRatingTagOption stores all available options for tags which can be used to quickly rate cafeterias -type CafeteriaRatingTagOption struct { +// CanteenRatingTagOption stores all available options for tags which can be used to quickly rate cafeterias +type CanteenRatingTagOption struct { CafeteriaRatingsTagOption int64 `gorm:"primary_key;AUTO_INCREMENT;column:cafeteriaRatingTagOption;type:int;not null;" json:"canteenRatingTagOption"` DE string `gorm:"column:DE;text;default:de;not null;" json:"DE"` EN string `gorm:"column:EN;text;default:en;not null;" json:"EN"` } - -// TableName sets the insert table name for this struct type -func (n *CafeteriaRatingTagOption) TableName() string { - return "cafeteria_rating_tag_option" -} diff --git a/server/model/cafeteria.go b/server/model/canteen.go similarity index 66% rename from server/model/cafeteria.go rename to server/model/canteen.go index a5c59582..39b328b3 100644 --- a/server/model/cafeteria.go +++ b/server/model/canteen.go @@ -1,15 +1,10 @@ package model -// Cafeteria stores all Available cafeterias in the format of the eat-api -type Cafeteria struct { +// Canteen stores all Available cafeterias in the format of the eat-api +type Canteen struct { Cafeteria int64 `gorm:"primary_key;AUTO_INCREMENT;column:cafeteria;type:int;not null;" json:"canteen" ` Name string `gorm:"column:name;type:mediumtext;not null;" json:"name" ` Address string `gorm:"column:address;type:text;not null;" json:"address" ` Latitude float32 `gorm:"column:latitude;type:float;not null;" json:"latitude" ` Longitude float32 `gorm:"column:longitude;type:float;not null;" json:"longitude"` } - -// TableName sets the insert table name for this struct type -func (n *Cafeteria) TableName() string { - return "cafeteria" -} diff --git a/server/model/canteen_head_count.go b/server/model/canteen_head_count.go index 391400e5..8fca651f 100644 --- a/server/model/canteen_head_count.go +++ b/server/model/canteen_head_count.go @@ -12,8 +12,3 @@ type CanteenHeadCount struct { Percent float32 `gorm:"column:percent;type:float;not null;" json:"percent"` Timestamp time.Time `gorm:"column:timestamp;type:timestamp;not null;" json:"timestamp" ` } - -// TableName sets the insert table name for this struct type -func (n *CanteenHeadCount) TableName() string { - return "canteen_head_count" -} diff --git a/server/model/crontab.go b/server/model/crontab.go index 79d310af..8be64559 100644 --- a/server/model/crontab.go +++ b/server/model/crontab.go @@ -4,11 +4,6 @@ import ( "github.com/guregu/null" ) -// TableName overrides the table name used by Crontab to `crontab` (Would otherwise auto-migrate to crontabs) -func (Crontab) TableName() string { - return "crontab" -} - // Crontab struct is a row record of the crontab table in the tca database type Crontab struct { Cron int64 `gorm:"primary_key;AUTO_INCREMENT;column:cron;type:int;" json:"cron"` diff --git a/server/model/dish.go b/server/model/dish.go index 7ab5c4d7..c992b9d2 100644 --- a/server/model/dish.go +++ b/server/model/dish.go @@ -21,5 +21,5 @@ type Dish struct { // TableName sets the insert table name for this struct type func (n *Dish) TableName() string { - return "dish" + return "dishes" } diff --git a/server/model/dish_name_tag.go b/server/model/dish_name_tag.go index 1dc52ab4..7e9d0b13 100644 --- a/server/model/dish_name_tag.go +++ b/server/model/dish_name_tag.go @@ -6,8 +6,3 @@ type DishNameTag struct { Points int32 `gorm:"column:points;type:int;not null;" json:"points"` TagNameID int64 `gorm:"foreignKey:tagRatingID;column:tagNameID;type:int;not null;" json:"tagnameID"` } - -// TableName sets the insert table name for this struct type -func (n *DishNameTag) TableName() string { - return "dish_name_tag" -} diff --git a/server/model/dish_name_tag_option.go b/server/model/dish_name_tag_option.go index 143eb8a4..ff1074e1 100644 --- a/server/model/dish_name_tag_option.go +++ b/server/model/dish_name_tag_option.go @@ -5,8 +5,3 @@ type DishNameTagOption struct { DE string `gorm:"column:DE;type:text;not null;" json:"DE"` 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" -} diff --git a/server/model/dish_rating.go b/server/model/dish_rating.go index 7b8e7f93..662b82b0 100644 --- a/server/model/dish_rating.go +++ b/server/model/dish_rating.go @@ -13,8 +13,3 @@ type DishRating struct { Timestamp time.Time `gorm:"column:timestamp;type:timestamp;not null;" json:"timestamp"` Image string `gorm:"column:image;type:text;" json:"image"` } - -// TableName sets the insert table name for this struct type -func (n *DishRating) TableName() string { - return "dish_rating" -} diff --git a/server/model/dish_rating_tag.go b/server/model/dish_rating_tag.go index de2bda74..e0240278 100644 --- a/server/model/dish_rating_tag.go +++ b/server/model/dish_rating_tag.go @@ -6,8 +6,3 @@ type DishRatingTag struct { Points int32 `gorm:"column:points;type:int;not null;" json:"points"` TagID int64 `gorm:"foreignKey:dishRatingTagOption;column:tagID;type:int;not null;" json:"tagID"` } - -// TableName sets the insert table name for this struct type -func (n *DishRatingTag) TableName() string { - return "dish_rating_tag" -} diff --git a/server/model/dish_rating_tag_option.go b/server/model/dish_rating_tag_option.go index c1cbece0..9c0ea8de 100644 --- a/server/model/dish_rating_tag_option.go +++ b/server/model/dish_rating_tag_option.go @@ -6,8 +6,3 @@ type DishRatingTagOption struct { DE string `gorm:"column:DE;type:text;default:de;not null;" json:"DE"` EN string `gorm:"column:EN;type:text;default:en;not null;" json:"EN"` } - -// TableName sets the insert table name for this struct type -func (n *DishRatingTagOption) TableName() string { - return "dish_rating_tag_option" -} diff --git a/server/model/dish_to_dish_name_tag.go b/server/model/dish_to_dish_name_tag.go index 279ff1c5..079038d1 100644 --- a/server/model/dish_to_dish_name_tag.go +++ b/server/model/dish_to_dish_name_tag.go @@ -5,8 +5,3 @@ type DishToDishNameTag struct { DishID int64 `gorm:"column:dishID;foreignKey:dish;type:int;not null;" json:"dishID"` NameTagID int64 `gorm:"foreignKey:dishNameTagOption;column:nameTagID;type:int;not null;" json:"nameTagID"` } - -// TableName sets the insert table name for this struct type -func (n *DishToDishNameTag) TableName() string { - return "dish_to_dish_name_tag" -} diff --git a/server/model/dishes_of_the_week.go b/server/model/dishes_of_the_week.go index 219c306d..61d33d19 100644 --- a/server/model/dishes_of_the_week.go +++ b/server/model/dishes_of_the_week.go @@ -7,8 +7,3 @@ type DishesOfTheWeek struct { Day int32 `gorm:"column:day;type:int;not null;" json:"day"` DishID int64 `gorm:"column:dishID;foreignKey:dish;type:int;not null;" json:"dishID"` } - -// TableName sets the insert table name for this struct type -func (n *DishesOfTheWeek) TableName() string { - return "dishes_of_the_week" -} diff --git a/server/model/dish_name_tag_option_excluded.go b/server/model/excluded_dish_name_tag_option.go similarity index 65% rename from server/model/dish_name_tag_option_excluded.go rename to server/model/excluded_dish_name_tag_option.go index f957ed11..446c1bdb 100644 --- a/server/model/dish_name_tag_option_excluded.go +++ b/server/model/excluded_dish_name_tag_option.go @@ -1,12 +1,7 @@ package model -type DishNameTagOptionExcluded struct { +type ExcludedDishNameTagOption 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" -} diff --git a/server/model/dish_name_tag_option_included.go b/server/model/included_dish_name_tag_option.go similarity index 65% rename from server/model/dish_name_tag_option_included.go rename to server/model/included_dish_name_tag_option.go index ddd7683d..5a44828b 100644 --- a/server/model/dish_name_tag_option_included.go +++ b/server/model/included_dish_name_tag_option.go @@ -1,12 +1,7 @@ package model -type DishNameTagOptionIncluded struct { +type IncludedDishNameTagOption 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" -} diff --git a/server/model/kino.go b/server/model/kino.go deleted file mode 100644 index f8eec7a0..00000000 --- a/server/model/kino.go +++ /dev/null @@ -1,31 +0,0 @@ -package model - -import ( - "time" - - "github.com/guregu/null" -) - -// Kino stores all movies -type Kino struct { - Id int64 `gorm:"primary_key;AUTO_INCREMENT;column:kino;type:int;not null;"` - Date time.Time `gorm:"column:date;type:datetime;not null;"` - Created time.Time `gorm:"column:created;type:timestamp;not null;default:CURRENT_TIMESTAMP"` - Title string `gorm:"column:title;type:text;not null;"` - Year string `gorm:"column:year;type:varchar(4);not null;"` - Runtime string `gorm:"column:runtime;type:varchar(40);not null;"` - Genre string `gorm:"column:genre;type:varchar(100);not null;"` - Director string `gorm:"column:director;type:text;not null;"` - Actors string `gorm:"column:actors;type:text;not null;"` - ImdbRating string `gorm:"column:rating;type:varchar(4);not null;"` - Description string `gorm:"column:description;type:text;not null;"` - Trailer null.String `gorm:"column:trailer"` - FileID int64 `gorm:"column:cover"` - File File `gorm:"foreignKey:FileID;references:file"` - Link string `gorm:"column:link;type:varchar(190);not null;unique;"` -} - -// TableName sets the insert table name for this struct type -func (n *Kino) TableName() string { - return "kino" -} diff --git a/server/model/movie.go b/server/model/movie.go new file mode 100644 index 00000000..d662150f --- /dev/null +++ b/server/model/movie.go @@ -0,0 +1,23 @@ +package model + +import ( + "time" +) + +// Movie stores all movies +type Movie struct { + Movie int64 `gorm:"primary_key;AUTO_INCREMENT;column:kino;type:int;not null;"` + Date time.Time `gorm:"column:date;type:datetime;not null;"` + Created time.Time `gorm:"column:created;type:timestamp;not null;default:CURRENT_TIMESTAMP"` + Title string `gorm:"column:title;type:text;not null;"` + Year string `gorm:"column:year;type:varchar(4);not null;"` + Runtime string `gorm:"column:runtime;type:varchar(40);not null;"` + Genre string `gorm:"column:genre;type:varchar(100);not null;"` + Director string `gorm:"column:director;type:text;not null;"` + Actors string `gorm:"column:actors;type:text;not null;"` + ImdbRating string `gorm:"column:rating;type:varchar(4);not null;"` + Description string `gorm:"column:description;type:text;not null;"` + FileID int64 `gorm:"column:cover;not null"` + File File `gorm:"foreignKey:FileID;references:file;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"` + Link string `gorm:"column:link;type:varchar(190);not null;unique;"` +} diff --git a/server/model/news.go b/server/model/news.go index 5de7ace7..54efb265 100755 --- a/server/model/news.go +++ b/server/model/news.go @@ -27,8 +27,3 @@ type News struct { FileID null.Int `gorm:"column:file;type:int;"` File *File `gorm:"foreignKey:FileID;references:file;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"` } - -// TableName sets the insert table name for this struct type -func (n *News) TableName() string { - return "news" -} diff --git a/server/model/news_alert.go b/server/model/news_alert.go index 076c1ae1..053f1470 100644 --- a/server/model/news_alert.go +++ b/server/model/news_alert.go @@ -26,8 +26,3 @@ type NewsAlert struct { From time.Time `gorm:"column:from;type:datetime;default:CURRENT_TIMESTAMP;" json:"from"` To time.Time `gorm:"column:to;type:datetime;default:CURRENT_TIMESTAMP;" json:"to"` } - -// TableName sets the insert table name for this struct type -func (n *NewsAlert) TableName() string { - return "news_alert" -} diff --git a/server/model/news_source.go b/server/model/news_source.go index 62cc4ca2..e9da6ee3 100644 --- a/server/model/news_source.go +++ b/server/model/news_source.go @@ -15,7 +15,6 @@ var ( _ = uuid.UUID{} ) -// 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;"` @@ -24,8 +23,3 @@ type NewsSource struct { File File `gorm:"foreignKey:FileID;references:file;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"` Hook null.String `gorm:"column:hook;type:char;size:12;"` } - -// TableName sets the insert table name for this struct type -func (n *NewsSource) TableName() string { - return "newsSource" -} diff --git a/server/model/update_note.go b/server/model/update_note.go index ad83708f..8ce7bbc3 100755 --- a/server/model/update_note.go +++ b/server/model/update_note.go @@ -6,8 +6,3 @@ type UpdateNote struct { VersionName string `gorm:"column:version_name;type:text;"` Message string `gorm:"column:message;type:text;"` } - -// TableName sets the insert table name for this struct type -func (n *UpdateNote) TableName() string { - return "update_note" -}