From 216633fca88a9901ea066136777ef0ddd0bff124 Mon Sep 17 00:00:00 2001 From: Frank Elsinga Date: Tue, 5 Sep 2023 14:19:11 +0200 Subject: [PATCH 01/15] renaming kino -> movie of the db --- server/backend/migration/2023090510000000.go | 71 ++++++++++++++++++++ server/backend/migration/migration.go | 1 + server/model/movie.go | 23 +++++++ 3 files changed, 95 insertions(+) create mode 100644 server/backend/migration/2023090510000000.go create mode 100644 server/model/movie.go diff --git a/server/backend/migration/2023090510000000.go b/server/backend/migration/2023090510000000.go new file mode 100644 index 00000000..92453e62 --- /dev/null +++ b/server/backend/migration/2023090510000000.go @@ -0,0 +1,71 @@ +package migration + +import ( + "github.com/go-gormigrate/gormigrate/v2" + "gorm.io/gorm" +) + +// Movie stores all movies +type Movie struct { + Id int32 `gorm:"primary_key;AUTO_INCREMENT;column:id;type:int;not null;"` + Cover Files `gorm:"column:cover;type:int;not null"` +} + +// Kino stores all movies +type Kino struct { + Cover Files `gorm:"column:cover;type:int;not null"` + Trailer string `gorm:"column:trailer;type:text;"` +} + +// TableName sets the insert table name for this struct type +func (n *Kino) TableName() string { + return "kino" +} + +type Files struct{} + +// TableName sets the insert table name for this struct type +func (f *Files) TableName() string { + return "files" +} + +// migrate2023090510000000 +// removes the unused trailer column +// makes the Cover FK into a not null field +// renames kino -> movie +// fixes the id being named kino +func (m TumDBMigrator) migrate2023090510000000() *gormigrate.Migration { + return &gormigrate.Migration{ + ID: "migrate2023090510000000", + Migrate: func(tx *gorm.DB) error { + // fix the movie table + if err := tx.Migrator().RenameTable(&Kino{}, &Movie{}); err != nil { + return err + } + if err := tx.Migrator().DropColumn(&Movie{}, "trailer"); err != nil { + return err + } + if err := tx.Migrator().RenameColumn(&Movie{}, "kino", "id"); err != nil { + return err + } + if err := tx.Migrator().AlterColumn(&Movie{}, "cover"); err != nil { + return err + } + return nil + }, + + Rollback: func(tx *gorm.DB) error { + // rollback the kino table + if err := tx.Migrator().RenameTable(&Kino{}, &Movie{}); err != nil { + return err + } + if err := tx.Migrator().RenameColumn(&Movie{}, "id", "kino"); err != nil { + return err + } + if err := tx.AutoMigrate(Kino{}); err != nil { + return err + } + return nil + }, + } +} diff --git a/server/backend/migration/migration.go b/server/backend/migration/migration.go index 1613c268..757b7cfc 100644 --- a/server/backend/migration/migration.go +++ b/server/backend/migration/migration.go @@ -41,6 +41,7 @@ func (m TumDBMigrator) Migrate() error { m.migrate20220713000000(), m.migrate20221119131300(), m.migrate20221210000000(), + m.migrate2023090510000000(), m.migrate20230904000000(), m.migrate20230825000000(), }) diff --git a/server/model/movie.go b/server/model/movie.go new file mode 100644 index 00000000..69615cd2 --- /dev/null +++ b/server/model/movie.go @@ -0,0 +1,23 @@ +package model + +import ( + "time" +) + +// Movie stores all movies +type Movie struct { + Id int32 `gorm:"primary_key;AUTO_INCREMENT;column:id;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;"` + FilesID int32 `gorm:"column:cover;not null"` + Files Files `gorm:"foreignKey:FilesID;references:file;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"` + Link string `gorm:"column:link;type:varchar(190);not null;unique;"` +} From 0afb7725993e848405a67268b2bee928ff21f7d8 Mon Sep 17 00:00:00 2001 From: Frank Elsinga Date: Tue, 12 Sep 2023 21:10:25 +0200 Subject: [PATCH 02/15] removal of ticketing --- server/backend/migration/20230912000000.go | 79 ++++++++++++++++++++++ server/backend/migration/migration.go | 1 + 2 files changed, 80 insertions(+) create mode 100644 server/backend/migration/20230912000000.go diff --git a/server/backend/migration/20230912000000.go b/server/backend/migration/20230912000000.go new file mode 100644 index 00000000..3ef8bda4 --- /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 (m TumDBMigrator) 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/migration.go b/server/backend/migration/migration.go index 757b7cfc..8957cceb 100644 --- a/server/backend/migration/migration.go +++ b/server/backend/migration/migration.go @@ -42,6 +42,7 @@ func (m TumDBMigrator) Migrate() error { m.migrate20221119131300(), m.migrate20221210000000(), m.migrate2023090510000000(), + m.migrate20230912000000(), m.migrate20230904000000(), m.migrate20230825000000(), }) From c58af8967c8a0ae6835381defb27a3ca9b75a052 Mon Sep 17 00:00:00 2001 From: Frank Elsinga Date: Tue, 12 Sep 2023 21:23:09 +0200 Subject: [PATCH 03/15] removed the chat from the database --- server/backend/migration/20230826000000.go | 72 ++++++++++++++++++++++ server/backend/migration/migration.go | 1 + 2 files changed, 73 insertions(+) create mode 100644 server/backend/migration/20230826000000.go diff --git a/server/backend/migration/20230826000000.go b/server/backend/migration/20230826000000.go new file mode 100644 index 00000000..5c8f88cb --- /dev/null +++ b/server/backend/migration/20230826000000.go @@ -0,0 +1,72 @@ +package migration + +import ( + "github.com/go-gormigrate/gormigrate/v2" + "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"` +} + +// migrate20230826000000 +// Removes all traces of the chat from the database. +func (m TumDBMigrator) migrate20230826000000() *gormigrate.Migration { + return &gormigrate.Migration{ + ID: "20230826000000", + Migrate: func(tx *gorm.DB) error { + // 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 + } + return tx.Exec("create index chat_chatroom_members_b3c09425 on chat_room2members (member);").Error + }, + } +} diff --git a/server/backend/migration/migration.go b/server/backend/migration/migration.go index 8957cceb..54b89e18 100644 --- a/server/backend/migration/migration.go +++ b/server/backend/migration/migration.go @@ -41,6 +41,7 @@ func (m TumDBMigrator) Migrate() error { m.migrate20220713000000(), m.migrate20221119131300(), m.migrate20221210000000(), + m.migrate20230826000000(), m.migrate2023090510000000(), m.migrate20230912000000(), m.migrate20230904000000(), From a136d733a491863c4b87e906d832be887533ada2 Mon Sep 17 00:00:00 2001 From: Frank Elsinga Date: Sun, 22 Oct 2023 16:31:27 +0200 Subject: [PATCH 04/15] rebase --- server/backend/migration/2023090510000000.go | 6 +- server/backend/migration/20231023000000.go | 72 ++++++++++++++++++++ server/backend/migration/migration.go | 3 +- 3 files changed, 77 insertions(+), 4 deletions(-) create mode 100644 server/backend/migration/20231023000000.go diff --git a/server/backend/migration/2023090510000000.go b/server/backend/migration/2023090510000000.go index 92453e62..523c3d5b 100644 --- a/server/backend/migration/2023090510000000.go +++ b/server/backend/migration/2023090510000000.go @@ -29,14 +29,14 @@ func (f *Files) TableName() string { return "files" } -// migrate2023090510000000 +// migrate20230905100000 // removes the unused trailer column // makes the Cover FK into a not null field // renames kino -> movie // fixes the id being named kino -func (m TumDBMigrator) migrate2023090510000000() *gormigrate.Migration { +func (m TumDBMigrator) migrate20230905100000() *gormigrate.Migration { return &gormigrate.Migration{ - ID: "migrate2023090510000000", + ID: "migrate20230905100000", Migrate: func(tx *gorm.DB) error { // fix the movie table if err := tx.Migrator().RenameTable(&Kino{}, &Movie{}); err != nil { diff --git a/server/backend/migration/20231023000000.go b/server/backend/migration/20231023000000.go new file mode 100644 index 00000000..e7d1a6fa --- /dev/null +++ b/server/backend/migration/20231023000000.go @@ -0,0 +1,72 @@ +package migration + +import ( + "github.com/go-gormigrate/gormigrate/v2" + "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 all traces of the chat from the database. +func (m TumDBMigrator) migrate20231023000000() *gormigrate.Migration { + return &gormigrate.Migration{ + ID: "20231023000000", + Migrate: func(tx *gorm.DB) error { + // 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 + } + return tx.Exec("create index chat_chatroom_members_b3c09425 on chat_room2members (member);").Error + }, + } +} diff --git a/server/backend/migration/migration.go b/server/backend/migration/migration.go index a0363627..ba48c9a1 100644 --- a/server/backend/migration/migration.go +++ b/server/backend/migration/migration.go @@ -49,7 +49,7 @@ func (m TumDBMigrator) Migrate() error { m.migrate20221119131300(), m.migrate20221210000000(), m.migrate20230826000000(), - m.migrate2023090510000000(), + m.migrate20230905100000(), m.migrate20230912000000(), m.migrate20230904000000(), m.migrate20230825000000(), @@ -58,6 +58,7 @@ func (m TumDBMigrator) Migrate() error { m.migrate20230904100000(), m.migrate20230826000000(), m.migrate20231003000000(), + m.migrate20231023000000(), }) err := mig.Migrate() return err From 13588a096ed563b92b3a63d6c973b1c71852f6f6 Mon Sep 17 00:00:00 2001 From: Frank Elsinga Date: Sun, 22 Oct 2023 16:33:04 +0200 Subject: [PATCH 05/15] rebase --- server/backend/migration/migration.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/server/backend/migration/migration.go b/server/backend/migration/migration.go index ba48c9a1..802268df 100644 --- a/server/backend/migration/migration.go +++ b/server/backend/migration/migration.go @@ -48,10 +48,8 @@ func (m TumDBMigrator) Migrate() error { m.migrate20220713000000(), m.migrate20221119131300(), m.migrate20221210000000(), - m.migrate20230826000000(), m.migrate20230905100000(), m.migrate20230912000000(), - m.migrate20230904000000(), m.migrate20230825000000(), m.migrate20230904000000(), m.migrate20230530000000(), From 408c5d025a781acb6ee3b9309ca2fe71ecd13c8f Mon Sep 17 00:00:00 2001 From: Frank Elsinga Date: Sun, 22 Oct 2023 16:34:49 +0200 Subject: [PATCH 06/15] rebase --- .../migration/{2023090510000000.go => 20230905100000.go} | 0 server/model/movie.go | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename server/backend/migration/{2023090510000000.go => 20230905100000.go} (100%) diff --git a/server/backend/migration/2023090510000000.go b/server/backend/migration/20230905100000.go similarity index 100% rename from server/backend/migration/2023090510000000.go rename to server/backend/migration/20230905100000.go diff --git a/server/model/movie.go b/server/model/movie.go index 69615cd2..547adb71 100644 --- a/server/model/movie.go +++ b/server/model/movie.go @@ -18,6 +18,6 @@ type Movie struct { ImdbRating string `gorm:"column:rating;type:varchar(4);not null;"` Description string `gorm:"column:description;type:text;not null;"` FilesID int32 `gorm:"column:cover;not null"` - Files Files `gorm:"foreignKey:FilesID;references:file;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"` + Files File `gorm:"foreignKey:FilesID;references:file;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"` Link string `gorm:"column:link;type:varchar(190);not null;unique;"` } From 41938b924ad2889421ca2aa9fcce56b3a1580026 Mon Sep 17 00:00:00 2001 From: Frank Elsinga Date: Mon, 23 Oct 2023 22:27:11 +0200 Subject: [PATCH 07/15] rebase --- server/backend/migration/20230905100000.go | 2 +- server/backend/migration/20230912000000.go | 2 +- server/backend/migration/20231023000000.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/server/backend/migration/20230905100000.go b/server/backend/migration/20230905100000.go index 523c3d5b..08658b51 100644 --- a/server/backend/migration/20230905100000.go +++ b/server/backend/migration/20230905100000.go @@ -34,7 +34,7 @@ func (f *Files) TableName() string { // makes the Cover FK into a not null field // renames kino -> movie // fixes the id being named kino -func (m TumDBMigrator) migrate20230905100000() *gormigrate.Migration { +func migrate20230905100000() *gormigrate.Migration { return &gormigrate.Migration{ ID: "migrate20230905100000", Migrate: func(tx *gorm.DB) error { diff --git a/server/backend/migration/20230912000000.go b/server/backend/migration/20230912000000.go index 3ef8bda4..4af8324c 100644 --- a/server/backend/migration/20230912000000.go +++ b/server/backend/migration/20230912000000.go @@ -7,7 +7,7 @@ import ( // migrate20230912000000 // Removes ticketsales from the db -func (m TumDBMigrator) migrate20230912000000() *gormigrate.Migration { +func migrate20230912000000() *gormigrate.Migration { return &gormigrate.Migration{ ID: "20230912000000", Migrate: func(tx *gorm.DB) error { diff --git a/server/backend/migration/20231023000000.go b/server/backend/migration/20231023000000.go index e7d1a6fa..7c58e101 100644 --- a/server/backend/migration/20231023000000.go +++ b/server/backend/migration/20231023000000.go @@ -13,7 +13,7 @@ type device2stats struct { // migrate20231023000000 // Removes all traces of the chat from the database. -func (m TumDBMigrator) migrate20231023000000() *gormigrate.Migration { +func migrate20231023000000() *gormigrate.Migration { return &gormigrate.Migration{ ID: "20231023000000", Migrate: func(tx *gorm.DB) error { From 7c78a7bd5f723732e2bcfd7e082923931c1ad4d4 Mon Sep 17 00:00:00 2001 From: Frank Elsinga Date: Mon, 23 Oct 2023 22:39:27 +0200 Subject: [PATCH 08/15] merged all chat cronjobs --- server/backend/migration/20230825000000.go | 31 ---------------------- server/backend/migration/20231023000000.go | 25 +++++++++++++++-- 2 files changed, 23 insertions(+), 33 deletions(-) delete mode 100644 server/backend/migration/20230825000000.go 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/20231023000000.go b/server/backend/migration/20231023000000.go index 7c58e101..e7310c27 100644 --- a/server/backend/migration/20231023000000.go +++ b/server/backend/migration/20231023000000.go @@ -1,7 +1,9 @@ package migration import ( + "github.com/TUM-Dev/Campus-Backend/server/model" "github.com/go-gormigrate/gormigrate/v2" + "github.com/guregu/null" "gorm.io/gorm" ) @@ -12,11 +14,20 @@ type device2stats struct { } // migrate20231023000000 -// Removes all traces of the chat from the database. +// - 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 @@ -66,7 +77,17 @@ func migrate20231023000000() *gormigrate.Migration { if err := tx.Exec("create index chat_chatroom_members_29801a33 on chat_room2members (room);").Error; err != nil { return err } - return tx.Exec("create index chat_chatroom_members_b3c09425 on chat_room2members (member);").Error + 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 }, } } From 214a24aa6e38ac10f703c5931caf3c76305c9fc4 Mon Sep 17 00:00:00 2001 From: Frank Elsinga Date: Mon, 23 Oct 2023 22:54:20 +0200 Subject: [PATCH 09/15] basics for the big rename --- server/backend/migration/20220713000000.go | 16 ++++- server/backend/migration/20230905100000.go | 71 ---------------------- server/backend/migration/20231024000000.go | 37 +++++++++++ server/backend/migration/migration.go | 7 +-- 4 files changed, 55 insertions(+), 76 deletions(-) delete mode 100644 server/backend/migration/20230905100000.go create mode 100644 server/backend/migration/20231024000000.go diff --git a/server/backend/migration/20220713000000.go b/server/backend/migration/20220713000000.go index 82a5da06..3c5f6f00 100644 --- a/server/backend/migration/20220713000000.go +++ b/server/backend/migration/20220713000000.go @@ -6,6 +6,20 @@ import ( "gorm.io/gorm" ) +// Cafeteria stores all Available cafeterias in the format of the eat-api +type Cafeteria 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" +} + //migrate20210709193000 func migrate20220713000000() *gormigrate.Migration { @@ -14,7 +28,7 @@ func migrate20220713000000() *gormigrate.Migration { Migrate: func(tx *gorm.DB) error { if err := tx.AutoMigrate( - &model.Cafeteria{}, + &Cafeteria{}, &model.CafeteriaRating{}, &model.CafeteriaRatingAverage{}, &model.CafeteriaRatingTag{}, diff --git a/server/backend/migration/20230905100000.go b/server/backend/migration/20230905100000.go deleted file mode 100644 index 08658b51..00000000 --- a/server/backend/migration/20230905100000.go +++ /dev/null @@ -1,71 +0,0 @@ -package migration - -import ( - "github.com/go-gormigrate/gormigrate/v2" - "gorm.io/gorm" -) - -// Movie stores all movies -type Movie struct { - Id int32 `gorm:"primary_key;AUTO_INCREMENT;column:id;type:int;not null;"` - Cover Files `gorm:"column:cover;type:int;not null"` -} - -// Kino stores all movies -type Kino struct { - Cover Files `gorm:"column:cover;type:int;not null"` - Trailer string `gorm:"column:trailer;type:text;"` -} - -// TableName sets the insert table name for this struct type -func (n *Kino) TableName() string { - return "kino" -} - -type Files struct{} - -// TableName sets the insert table name for this struct type -func (f *Files) TableName() string { - return "files" -} - -// migrate20230905100000 -// removes the unused trailer column -// makes the Cover FK into a not null field -// renames kino -> movie -// fixes the id being named kino -func migrate20230905100000() *gormigrate.Migration { - return &gormigrate.Migration{ - ID: "migrate20230905100000", - Migrate: func(tx *gorm.DB) error { - // fix the movie table - if err := tx.Migrator().RenameTable(&Kino{}, &Movie{}); err != nil { - return err - } - if err := tx.Migrator().DropColumn(&Movie{}, "trailer"); err != nil { - return err - } - if err := tx.Migrator().RenameColumn(&Movie{}, "kino", "id"); err != nil { - return err - } - if err := tx.Migrator().AlterColumn(&Movie{}, "cover"); err != nil { - return err - } - return nil - }, - - Rollback: func(tx *gorm.DB) error { - // rollback the kino table - if err := tx.Migrator().RenameTable(&Kino{}, &Movie{}); err != nil { - return err - } - if err := tx.Migrator().RenameColumn(&Movie{}, "id", "kino"); err != nil { - return err - } - if err := tx.AutoMigrate(Kino{}); err != nil { - return err - } - return nil - }, - } -} diff --git a/server/backend/migration/20231024000000.go b/server/backend/migration/20231024000000.go new file mode 100644 index 00000000..0646a4ee --- /dev/null +++ b/server/backend/migration/20231024000000.go @@ -0,0 +1,37 @@ +package migration + +import ( + "github.com/go-gormigrate/gormigrate/v2" + "gorm.io/gorm" +) + +type wrongTableName struct { + Original string + New string +} + +var wrongTableNames = []wrongTableName{} + +// 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 4899b068..e8c779e1 100644 --- a/server/backend/migration/migration.go +++ b/server/backend/migration/migration.go @@ -12,7 +12,7 @@ import ( func autoMigrate(db *gorm.DB) error { err := db.AutoMigrate( - &model.Cafeteria{}, + &model.Canteen{}, &model.CafeteriaRating{}, &model.CafeteriaRatingAverage{}, &model.CafeteriaRatingTag{}, @@ -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,15 +73,14 @@ func manualMigrate(db *gorm.DB) error { migrate20220713000000(), migrate20221119131300(), migrate20221210000000(), - migrate20230905100000(), migrate20230912000000(), - migrate20230825000000(), migrate20230904000000(), migrate20230530000000(), migrate20230904100000(), migrate20230826000000(), migrate20231003000000(), migrate20231023000000(), + migrate20231024000000(), } return gormigrate.New(db, gormigrateOptions, migrations).Migrate() } From b16e371b2ce9708ebbb01e61345ccc1b2e16d411 Mon Sep 17 00:00:00 2001 From: Frank Elsinga Date: Mon, 23 Oct 2023 22:54:58 +0200 Subject: [PATCH 10/15] kino renaming --- server/backend/cron/movies.go | 4 +-- server/backend/migration/20231024000000.go | 4 ++- server/backend/movie.go | 4 +-- server/model/kino.go | 31 ---------------------- server/model/movie.go | 6 ++--- 5 files changed, 10 insertions(+), 39 deletions(-) delete mode 100644 server/model/kino.go 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/20231024000000.go b/server/backend/migration/20231024000000.go index 0646a4ee..adfdccfb 100644 --- a/server/backend/migration/20231024000000.go +++ b/server/backend/migration/20231024000000.go @@ -10,7 +10,9 @@ type wrongTableName struct { New string } -var wrongTableNames = []wrongTableName{} +var wrongTableNames = []wrongTableName{ + {"kino", "movies"}, +} // migrate20231024000000 // - replaces all instances of misleadingly named tables with the correct ones 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/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 index 547adb71..19987a6e 100644 --- a/server/model/movie.go +++ b/server/model/movie.go @@ -6,7 +6,7 @@ import ( // Movie stores all movies type Movie struct { - Id int32 `gorm:"primary_key;AUTO_INCREMENT;column:id;type:int;not null;"` + Movie int64 `gorm:"primary_key;AUTO_INCREMENT;column:movie;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;"` @@ -17,7 +17,7 @@ type Movie struct { 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;"` - FilesID int32 `gorm:"column:cover;not null"` - Files File `gorm:"foreignKey:FilesID;references:file;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"` + 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;"` } From b6b7e7689c788c847285f361479ac40a3b60b1f8 Mon Sep 17 00:00:00 2001 From: Frank Elsinga Date: Mon, 23 Oct 2023 22:55:24 +0200 Subject: [PATCH 11/15] general renaming --- server/backend/migration/20231024000000.go | 1 + server/model/crontab.go | 5 ----- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/server/backend/migration/20231024000000.go b/server/backend/migration/20231024000000.go index adfdccfb..004ddaa9 100644 --- a/server/backend/migration/20231024000000.go +++ b/server/backend/migration/20231024000000.go @@ -11,6 +11,7 @@ type wrongTableName struct { } var wrongTableNames = []wrongTableName{ + {"crontab", "crontabs"}, {"kino", "movies"}, } 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"` From 81c8fdc7ad23db4ecbae947edd1b7cc7a6a2f56d Mon Sep 17 00:00:00 2001 From: Frank Elsinga Date: Mon, 23 Oct 2023 22:56:56 +0200 Subject: [PATCH 12/15] movie --- server/model/movie.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/model/movie.go b/server/model/movie.go index 19987a6e..d662150f 100644 --- a/server/model/movie.go +++ b/server/model/movie.go @@ -6,7 +6,7 @@ import ( // Movie stores all movies type Movie struct { - Movie int64 `gorm:"primary_key;AUTO_INCREMENT;column:movie;type:int;not null;"` + 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;"` From f3490d71aa85638ef85619d9aad5066a225beee2 Mon Sep 17 00:00:00 2001 From: Frank Elsinga Date: Mon, 23 Oct 2023 23:04:00 +0200 Subject: [PATCH 13/15] canteens --- server/backend/cafeteria.go | 18 +++++++++--------- .../backend/cron/average_rating_computation.go | 2 +- server/backend/cron/dish_name_download.go | 10 +++++----- server/backend/migration/20220713000000.go | 10 +++++----- server/backend/migration/20231003000000.go | 2 +- server/backend/migration/20231024000000.go | 10 ++++++++++ server/backend/migration/migration.go | 10 +++++----- server/model/cafeteria_rating.go | 9 ++------- server/model/cafeteria_rating_tag.go | 11 +++-------- server/model/cafeteria_rating_tag_option.go | 9 ++------- server/model/{cafeteria.go => canteen.go} | 9 ++------- server/model/dish.go | 2 +- server/model/dish_name_tag.go | 5 ----- server/model/dish_name_tag_option.go | 5 ----- ...ded.go => excluded_dish_name_tag_option.go} | 7 +------ ...ded.go => included_dish_name_tag_option.go} | 7 +------ 16 files changed, 48 insertions(+), 78 deletions(-) rename server/model/{cafeteria.go => canteen.go} (66%) rename server/model/{dish_name_tag_option_excluded.go => excluded_dish_name_tag_option.go} (65%) rename server/model/{dish_name_tag_option_included.go => included_dish_name_tag_option.go} (65%) diff --git a/server/backend/cafeteria.go b/server/backend/cafeteria.go index 6f3e57c7..e86268f5 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) @@ -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.") } diff --git a/server/backend/cron/average_rating_computation.go b/server/backend/cron/average_rating_computation.go index 9c3324bb..e6dfdd80 100644 --- a/server/backend/cron/average_rating_computation.go +++ b/server/backend/cron/average_rating_computation.go @@ -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/migration/20220713000000.go b/server/backend/migration/20220713000000.go index 3c5f6f00..f310564f 100644 --- a/server/backend/migration/20220713000000.go +++ b/server/backend/migration/20220713000000.go @@ -29,16 +29,16 @@ func migrate20220713000000() *gormigrate.Migration { if err := tx.AutoMigrate( &Cafeteria{}, - &model.CafeteriaRating{}, + &model.CanteenRating{}, &model.CafeteriaRatingAverage{}, - &model.CafeteriaRatingTag{}, + &model.CanteenRatingTag{}, &model.CafeteriaRatingTagAverage{}, - &model.CafeteriaRatingTagOption{}, + &model.CanteenRatingTagOption{}, &model.Dish{}, &model.DishesOfTheWeek{}, &model.DishNameTagOption{}, - &model.DishNameTagOptionIncluded{}, - &model.DishNameTagOptionExcluded{}, + &model.IncludedDishNameTagOption{}, + &model.ExcludedDishNameTagOption{}, &model.DishNameTag{}, &model.DishNameTagAverage{}, &model.DishRating{}, 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/20231024000000.go b/server/backend/migration/20231024000000.go index 004ddaa9..9cebb37e 100644 --- a/server/backend/migration/20231024000000.go +++ b/server/backend/migration/20231024000000.go @@ -13,6 +13,16 @@ type wrongTableName struct { var wrongTableNames = []wrongTableName{ {"crontab", "crontabs"}, {"kino", "movies"}, + {"dish_name_tag_option_included", "included_dish_name_tag_options"}, + {"dish_name_tag_option", "dish_name_tag_options"}, + {"cafeteria", "canteens"}, + {"cafeteria_rating", "canteen_ratings"}, + {"cafeteria_rating_tag", "canteen_rating_tags"}, + {"cafeteria_rating_tag_option", "canteen_rating_tag_options"}, + {"dish", "dishes"}, + {"dish_name_tag", "dish_name_tags"}, + {"dish_name_tag_option_excluded", "excluded_dish_name_tag_options"}, + {"dish_name_tag_option_included", "included_dish_name_tag_option"}, } // migrate20231024000000 diff --git a/server/backend/migration/migration.go b/server/backend/migration/migration.go index e8c779e1..31017e7c 100644 --- a/server/backend/migration/migration.go +++ b/server/backend/migration/migration.go @@ -13,11 +13,11 @@ import ( func autoMigrate(db *gorm.DB) error { err := db.AutoMigrate( &model.Canteen{}, - &model.CafeteriaRating{}, + &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{}, 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..a38a074e 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_rating-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/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_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" -} From 3a43c8108aa975d37a6fd19bbfcde1485d41ae93 Mon Sep 17 00:00:00 2001 From: Frank Elsinga Date: Mon, 23 Oct 2023 23:27:54 +0200 Subject: [PATCH 14/15] further renamin --- client/local/client.go | 2 +- server/backend/cafeteria.go | 18 +++++++++--------- .../backend/cron/average_rating_computation.go | 12 ++++++------ server/backend/migration/20231024000000.go | 12 ++++++++++-- server/backend/news.go | 6 +++--- server/backend/news_test.go | 8 ++++---- server/model/cafeteria_rating_tag.go | 2 +- server/model/canteen_head_count.go | 5 ----- server/model/dish_rating.go | 5 ----- server/model/dish_rating_tag.go | 5 ----- server/model/dish_rating_tag_option.go | 5 ----- server/model/dish_to_dish_name_tag.go | 5 ----- server/model/dishes_of_the_week.go | 5 ----- server/model/news.go | 5 ----- server/model/news_alert.go | 5 ----- server/model/news_source.go | 6 ------ server/model/update_note.go | 5 ----- 17 files changed, 34 insertions(+), 77 deletions(-) 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 e86268f5..ca80bc92 100644 --- a/server/backend/cafeteria.go +++ b/server/backend/cafeteria.go @@ -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 } @@ -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 e6dfdd80..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 { diff --git a/server/backend/migration/20231024000000.go b/server/backend/migration/20231024000000.go index 9cebb37e..0c39d020 100644 --- a/server/backend/migration/20231024000000.go +++ b/server/backend/migration/20231024000000.go @@ -13,16 +13,24 @@ type wrongTableName struct { var wrongTableNames = []wrongTableName{ {"crontab", "crontabs"}, {"kino", "movies"}, - {"dish_name_tag_option_included", "included_dish_name_tag_options"}, - {"dish_name_tag_option", "dish_name_tag_options"}, {"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 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_tag.go b/server/model/cafeteria_rating_tag.go index a38a074e..225fe195 100644 --- a/server/model/cafeteria_rating_tag.go +++ b/server/model/cafeteria_rating_tag.go @@ -1,6 +1,6 @@ package model -// CanteenRatingTag struct is a row record of the either the dish_tag_rating-table or the cafeteria_rating_tags-table in the database +// 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"` 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/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/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" -} From d30d66d64b08b71cb294c591a9056a0bd73cfc78 Mon Sep 17 00:00:00 2001 From: Frank Elsinga Date: Tue, 24 Oct 2023 00:30:01 +0200 Subject: [PATCH 15/15] made sure that migrate20220713000000 is stable against model changes --- server/backend/migration/20220713000000.go | 288 +++++++++++++++++++-- 1 file changed, 265 insertions(+), 23 deletions(-) diff --git a/server/backend/migration/20220713000000.go b/server/backend/migration/20220713000000.go index f310564f..b40ef531 100644 --- a/server/backend/migration/20220713000000.go +++ b/server/backend/migration/20220713000000.go @@ -1,13 +1,15 @@ package migration import ( + "time" + "github.com/TUM-Dev/Campus-Backend/server/model" "github.com/go-gormigrate/gormigrate/v2" "gorm.io/gorm" ) -// Cafeteria stores all Available cafeterias in the format of the eat-api -type Cafeteria struct { +// InitialCafeteria stores all Available cafeterias in the format of the eat-api +type InitialCafeteria 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" ` @@ -16,37 +18,277 @@ type Cafeteria struct { } // TableName sets the insert table name for this struct type -func (n *Cafeteria) TableName() string { +func (n *InitialCafeteria) TableName() string { return "cafeteria" } -//migrate20210709193000 +// InitialCafeteriaRating stores all Available cafeterias in the format of the eat-api +type InitialCafeteriaRating 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" ` + CafeteriaID int64 `gorm:"column:cafeteriaID;foreignKey:cafeteria;type:int;not null;" json:"canteenID"` + 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 *InitialCafeteriaRating) TableName() string { + return "cafeteria_rating" +} + +// InitialCafeteriaRatingTag struct is a row record of the either the dish_tag_rating-table or the cafeteria_rating_tags-table in the database +type InitialCafeteriaRatingTag struct { + CafeteriaRatingTag int64 `gorm:"primary_key;AUTO_INCREMENT;column:CafeteriaRatingTag;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 *InitialCafeteriaRatingTag) TableName() string { + return "cafeteria_rating_tag" +} + +// InitialCafeteriaRatingTagOption stores all available options for tags which can be used to quickly rate cafeterias +type InitialCafeteriaRatingTagOption 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 *InitialCafeteriaRatingTagOption) TableName() string { + return "cafeteria_rating_tag_option" +} + +// InitialDish represents one dish fin a specific cafeteria +type InitialDish struct { + Dish int64 `gorm:"primary_key;AUTO_INCREMENT;column:dish;type:int;not null;" json:"dish"` + Name string `gorm:"column:name;type:text;not null;" json:"name" ` + Type string `gorm:"column:type;type:text;not null;" json:"type" ` + CafeteriaID int64 `gorm:"column:cafeteriaID;foreignKey:cafeteria;type:int;not null;" json:"cafeteriaID"` +} + +// TableName sets the insert table name for this struct type +func (n *InitialDish) TableName() string { + return "dish" +} + +type InitialDishesOfTheWeek struct { + DishesOfTheWeek int64 `gorm:"primary_key;AUTO_INCREMENT;column:dishesOfTheWeek;type:int;not null;" json:"dishesOfTheWeek"` + Year int32 `gorm:"column:year;type:int;not null;" json:"year"` + Week int32 `gorm:"column:week;type:int;not null;" json:"week"` + 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 *InitialDishesOfTheWeek) TableName() string { + return "dishes_of_the_week" +} + +type InitialDishNameTagOption struct { + DishNameTagOption int64 `gorm:"primary_key;AUTO_INCREMENT;column:dishNameTagOption;type:int;not null;" json:"dishNameTagOption"` + 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 *InitialDishNameTagOption) TableName() string { + return "dish_name_tag_option" +} + +type InitialDishRatingTagOption struct { + DishRatingTagOption int64 `gorm:"primary_key;AUTO_INCREMENT;column:dishRatingTagOption;type:int;not null;" json:"dishRatingTagOption"` + 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 *InitialDishRatingTagOption) TableName() string { + return "dish_rating_tag_option" +} + +type InitialDishNameTag struct { + DishNameTag int64 `gorm:"primary_key;AUTO_INCREMENT;column:DishNameTag;type:int;not null;" json:"DishNameTag"` + CorrespondingRating int64 `gorm:"foreignKey:dish;column:correspondingRating;type:int;not null;" json:"correspondingRating"` + 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 *InitialDishNameTag) TableName() string { + return "dish_name_tag" +} + +type InitialDishNameTagOptionExcluded 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 *InitialDishNameTagOptionExcluded) TableName() string { + return "dish_name_tag_option_excluded" +} + +type InitialDishNameTagOptionIncluded 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 *InitialDishNameTagOptionIncluded) TableName() string { + return "dish_name_tag_option_included" +} + +type InitialDishRating struct { + DishRating int64 `gorm:"primary_key;AUTO_INCREMENT;column:dishRating;type:int;not null;" json:"dishRating"` + Points int32 `gorm:"column:points;type:int;not null;" json:"points"` + CafeteriaID int64 `gorm:"column:cafeteriaID;foreignKey:cafeteria;type:int;not null;" json:"cafeteriaID"` + DishID int64 `gorm:"column:dishID;foreignKey:dish;type:int;not null;" json:"dishID"` + Comment string `gorm:"column:comment;type:text;" json:"comment"` + 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 *InitialDishRating) TableName() string { + return "dish_rating" +} + +type InitialDishRatingTag struct { + DishRatingTag int64 `gorm:"primary_key;AUTO_INCREMENT;column:dishRatingTag;type:int;not null;" json:"dishRatingTag"` + CorrespondingRating int64 `gorm:"foreignKey:cafeteriaRating;column:parentRating;type:int;not null;" json:"parentRating"` + 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 *InitialDishRatingTag) TableName() string { + return "dish_rating_tag" +} + +type InitialDishToDishNameTag struct { + DishToDishNameTag int64 `gorm:"primary_key;AUTO_INCREMENT;column:dishToDishNameTag;type:int;not null;" json:"dishToDishNameTag"` + 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 *InitialDishToDishNameTag) TableName() string { + return "dish_to_dish_name_tag" +} + +// InitialCafeteriaRatingAverage stores all precomputed values for the cafeteria ratings +type InitialCafeteriaRatingAverage struct { + CafeteriaRatingAverage int64 `gorm:"primary_key;AUTO_INCREMENT;column:cafeteriaRatingAverage;type:int;not null;" json:"canteenRatingAverage" ` + CafeteriaID int64 `gorm:"column:cafeteriaID;foreignKey:cafeteria;type:int;not null;" json:"canteenID"` + Average float64 `gorm:"column:average;type:float;not null;" json:"average" ` + Min int32 `gorm:"column:min;type:int;not null;" json:"min"` + Max int32 `gorm:"column:max;type:int;not null;" json:"max"` + Std float64 `gorm:"column:std;type:float;not null;" json:"std"` +} + +// TableName sets the insert table name for this struct type +func (n *InitialCafeteriaRatingAverage) TableName() string { + return "cafeteria_rating_average" +} + +// InitialCafeteriaRatingTagAverage stores all precomputed values for the cafeteria ratings +type InitialCafeteriaRatingTagAverage struct { + CafeteriaRatingTagsAverage int64 `gorm:"primary_key;AUTO_INCREMENT;column:cafeteriaRatingTagsAverage;type:int;not null;" json:"canteenRatingTagsAverage"` + CafeteriaID int64 `gorm:"column:cafeteriaID;foreignKey:cafeteria;type:int;not null;" json:"canteenID"` + TagID int64 `gorm:"column:tagID;foreignKey:cafeteriaRatingTagOption;type:int;not null;" json:"tagID"` + Average float32 `gorm:"column:average;type:float;not null;" json:"average"` + Min int8 `gorm:"column:min;type:int;not null;" json:"min"` + Max int8 `gorm:"column:max;type:int;not null;" json:"max"` + Std float32 `gorm:"column:std;type:float;not null;" json:"std"` +} + +// TableName sets the insert table name for this struct type +func (n *InitialCafeteriaRatingTagAverage) TableName() string { + return "cafeteria_rating_tag_average" +} + +// InitialDishNameTagAverage stores all precomputed values for the DishName ratings +type InitialDishNameTagAverage struct { + DishNameTagAverage int64 `gorm:"primary_key;AUTO_INCREMENT;column:dishNameTagAverage;type:int;not null;" json:"dishNameTagAverage" ` + CafeteriaID int64 `gorm:"column:cafeteriaID;foreignKey:cafeteria;type:int;not null;" json:"cafeteriaID"` + TagID int64 `gorm:"column:tagID;foreignKey:DishNameTagOption;type:int;not null;" json:"tagID"` + Average float32 `gorm:"column:average;type:float;not null;" json:"average" ` + Min int8 `gorm:"column:min;type:int;not null;" json:"min"` + Max int8 `gorm:"column:max;type:int;not null;" json:"max"` + Std float32 `gorm:"column:std;type:float;not null;" json:"std"` +} + +// TableName sets the insert table name for this struct type +func (n *InitialDishNameTagAverage) TableName() string { + return "dish_name_tag_average" +} + +// InitialDishRatingAverage stores all precomputed values for the cafeteria ratings +type InitialDishRatingAverage struct { + DishRatingAverage int64 `gorm:"primary_key;AUTO_INCREMENT;column:dishRatingAverage;type:int;not null;" json:"dishRatingAverage" ` + CafeteriaID int64 `gorm:"column:cafeteriaID;foreignKey:cafeteria;type:int;not null;" json:"cafeteriaID"` + DishID int64 `gorm:"column:dishID;foreignKey:dish;type:int;not null;" json:"dishID"` + Average float64 `gorm:"column:average;type:float;not null;" json:"average" ` + Min int32 `gorm:"column:min;type:int;not null;" json:"min"` + Max int32 `gorm:"column:max;type:int;not null;" json:"max"` + Std float64 `gorm:"column:std;type:float;not null;" json:"std"` +} + +// TableName sets the insert table name for this struct type +func (n *InitialDishRatingAverage) TableName() string { + return "dish_rating_average" +} + +// InitialDishRatingTagAverage stores all precomputed values for the cafeteria ratings +type InitialDishRatingTagAverage struct { + DishRatingTagsAverage int64 `gorm:"primary_key;AUTO_INCREMENT;column:dishRatingTagsAverage;type:int;not null;" json:"dishRatingTagsAverage" ` + CafeteriaID int64 `gorm:"column:cafeteriaID;foreignKey:cafeteria;type:int;not null;" json:"cafeteriaID"` + TagID int64 `gorm:"column:tagID;foreignKey:tagID;type:int;not null;" json:"tagID"` + DishID int64 `gorm:"column:dishID;foreignKey:dishID;type:int;not null;" json:"dishID"` + Average float32 `gorm:"column:average;type:float;not null;" json:"average" ` + Min int8 `gorm:"column:min;type:int;not null;" json:"min"` + Max int8 `gorm:"column:max;type:int;not null;" json:"max"` + Std float32 `gorm:"column:std;type:float;not null;" json:"std"` +} + +// TableName sets the insert table name for this struct type +func (n *InitialDishRatingTagAverage) TableName() string { + return "dish_rating_tag_average" +} +// migrate20220713000000 +// - adds all canteen related models func migrate20220713000000() *gormigrate.Migration { return &gormigrate.Migration{ ID: "20220713000000", Migrate: func(tx *gorm.DB) error { if err := tx.AutoMigrate( - &Cafeteria{}, - &model.CanteenRating{}, - &model.CafeteriaRatingAverage{}, - &model.CanteenRatingTag{}, - &model.CafeteriaRatingTagAverage{}, - &model.CanteenRatingTagOption{}, - &model.Dish{}, - &model.DishesOfTheWeek{}, - &model.DishNameTagOption{}, - &model.IncludedDishNameTagOption{}, - &model.ExcludedDishNameTagOption{}, - &model.DishNameTag{}, - &model.DishNameTagAverage{}, - &model.DishRating{}, - &model.DishRatingAverage{}, - &model.DishRatingTag{}, - &model.DishRatingTagAverage{}, - &model.DishRatingTagOption{}, - &model.DishToDishNameTag{}, + &InitialCafeteria{}, + &InitialCafeteriaRating{}, + &InitialCafeteriaRatingTag{}, + &InitialCafeteriaRatingTagOption{}, + &InitialDish{}, + &InitialDishesOfTheWeek{}, + &InitialDishNameTagOption{}, + &InitialDishNameTagOptionIncluded{}, + &InitialDishNameTagOptionExcluded{}, + &InitialDishNameTag{}, + &InitialDishRating{}, + &InitialDishRatingTag{}, + &InitialDishRatingTagOption{}, + &InitialDishToDishNameTag{}, + &InitialCafeteriaRatingAverage{}, + &InitialCafeteriaRatingTagAverage{}, + &InitialDishNameTagAverage{}, + &InitialDishRatingAverage{}, + &InitialDishRatingTagAverage{}, ); err != nil { return err }