Skip to content

Commit

Permalink
made sure that models match the database (#421)
Browse files Browse the repository at this point in the history
* made sure that `Timestamp` has the appropriate defaults

* fixed `email_id` being migrated to not null a while ago

* fixed more nullability collumns

* more index and nullness fixes

* made sure that `uni_kino_link` is on the correct field

* made sure that `uni_kino_link` is on the correct field

* made sure that devices reflect the database state

* removed the nulls from the feedback table

* fixed the timestamp type from the models

* removed more differences

* does this solve `email_id`?

* Revert "does this solve `email_id`?"

This reverts commit 43a7343.

* made sure that there is no float vs double vs decimal confusion for lat/lon

* fixed there being a difference between `:CURRENT_TIMESTAMP` and `:current_timestamp()`

the second one is needed because of mysql
  • Loading branch information
CommanderStorm authored Aug 23, 2024
1 parent 263f0e8 commit 1bfce50
Show file tree
Hide file tree
Showing 23 changed files with 80 additions and 80 deletions.
4 changes: 2 additions & 2 deletions server/backend/cron/dish_name_download.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ type CafeteriaWithID struct {
}

type CanteenLocation struct {
Longitude float32 `json:"longitude"`
Latitude float32 `json:"latitude"`
Longitude float64 `json:"longitude"`
Latitude float64 `json:"latitude"`
Address string `json:"address"`
}

Expand Down
30 changes: 15 additions & 15 deletions server/backend/migration/20220713000000.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import (
// 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" `
Name string `gorm:"column:name;type:text;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"`
Latitude float64 `gorm:"column:latitude;type:double;not null;" json:"latitude" `
Longitude float64 `gorm:"column:longitude;type:double;not null;" json:"longitude"`
}

// TableName sets the insert table name for this struct type
Expand All @@ -28,7 +28,7 @@ type InitialCafeteriaRating struct {
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" `
Timestamp time.Time `gorm:"column:timestamp;type:timestamp;not null;default:current_timestamp();OnUpdate:current_timestamp();" json:"timestamp" `
Image string `gorm:"column:image;type:text;" json:"image"`
}

Expand Down Expand Up @@ -150,7 +150,7 @@ type InitialDishRating struct {
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"`
Timestamp time.Time `gorm:"column:timestamp;type:timestamp;not null;default:current_timestamp();OnUpdate:current_timestamp();" json:"timestamp"`
Image string `gorm:"column:image;type:text;" json:"image"`
}

Expand Down Expand Up @@ -186,10 +186,10 @@ func (n *InitialDishToDishNameTag) TableName() string {
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" `
Average float64 `gorm:"column:average;type:double;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"`
Std float64 `gorm:"column:std;type:double;not null;" json:"std"`
}

// TableName sets the insert table name for this struct type
Expand All @@ -202,10 +202,10 @@ 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"`
Average float64 `gorm:"column:average;type:double;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"`
Std float64 `gorm:"column:std;type:double;not null;" json:"std"`
}

// TableName sets the insert table name for this struct type
Expand All @@ -218,10 +218,10 @@ 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" `
Average float64 `gorm:"column:average;type:double;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"`
Std float64 `gorm:"column:std;type:double;not null;" json:"std"`
}

// TableName sets the insert table name for this struct type
Expand All @@ -234,10 +234,10 @@ 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" `
Average float64 `gorm:"column:average;type:double;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"`
Std float64 `gorm:"column:std;type:double;not null;" json:"std"`
}

// TableName sets the insert table name for this struct type
Expand All @@ -251,10 +251,10 @@ type InitialDishRatingTagAverage struct {
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" `
Average float64 `gorm:"column:average;type:double;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"`
Std float64 `gorm:"column:std;type:double;not null;" json:"std"`
}

// TableName sets the insert table name for this struct type
Expand Down
2 changes: 1 addition & 1 deletion server/backend/migration/20221210000000.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type InitialCanteenHeadCount struct {
Count uint32 `gorm:"column:count;type:int;not null;" json:"count"`
MaxCount uint32 `gorm:"column:max_count;type:int;not null;" json:"max_count"`
Percent float32 `gorm:"column:percent;type:float;not null;" json:"percent"`
Timestamp time.Time `gorm:"column:timestamp;type:timestamp;not null;" json:"timestamp" `
Timestamp time.Time `gorm:"column:timestamp;type:timestamp;not null;default:current_timestamp();OnUpdate:current_timestamp();" json:"timestamp" `
}

// TableName sets the insert table name for this struct type
Expand Down
20 changes: 10 additions & 10 deletions server/backend/migration/20231015000000.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import (
type CafeteriaRatingAverage struct {
CafeteriaRatingAverage int64 `gorm:"primary_key;AUTO_INCREMENT;column:cafeteriaRatingAverage;type:int;not null;"`
CafeteriaID int64 `gorm:"column:cafeteriaID;foreignKey:cafeteria;type:int;not null;"`
Average float64 `gorm:"column:average;type:float;not null;"`
Average float64 `gorm:"column:average;type:double;not null;"`
Min int32 `gorm:"column:min;type:int;not null;"`
Max int32 `gorm:"column:max;type:int;not null;"`
Std float64 `gorm:"column:std;type:float;not null;"`
Std float64 `gorm:"column:std;type:double;not null;"`
}

// TableName sets the insert table name for this struct type
Expand All @@ -27,10 +27,10 @@ type DishRatingAverage struct {
DishRatingAverage int64 `gorm:"primary_key;AUTO_INCREMENT;column:dishRatingAverage;type:int;not null;"`
CafeteriaID int64 `gorm:"column:cafeteriaID;foreignKey:cafeteria;type:int;not null;"`
DishID int64 `gorm:"column:dishID;foreignKey:dish;type:int;not null;"`
Average float64 `gorm:"column:average;type:float;not null;"`
Average float64 `gorm:"column:average;type:double;not null;"`
Min int32 `gorm:"column:min;type:int;not null;"`
Max int32 `gorm:"column:max;type:int;not null;"`
Std float64 `gorm:"column:std;type:float;not null;"`
Std float64 `gorm:"column:std;type:double;not null;"`
}

// TableName sets the insert table name for this struct type
Expand All @@ -44,10 +44,10 @@ type DishRatingTagAverage struct {
CafeteriaID int64 `gorm:"column:cafeteriaID;foreignKey:cafeteria;type:int;not null;"`
TagID int64 `gorm:"column:tagID;foreignKey:tagID;type:int;not null;"`
DishID int64 `gorm:"column:dishID;foreignKey:dishID;type:int;not null;"`
Average float32 `gorm:"column:average;type:float;not null;"`
Average float64 `gorm:"column:average;type:double;not null;"`
Min int8 `gorm:"column:min;type:int;not null;"`
Max int8 `gorm:"column:max;type:int;not null;"`
Std float32 `gorm:"column:std;type:float;not null;"`
Std float64 `gorm:"column:std;type:double;not null;"`
}

// TableName sets the insert table name for this struct type
Expand All @@ -60,10 +60,10 @@ type CafeteriaRatingTagsAverage 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"`
Average float64 `gorm:"column:average;type:double;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"`
Std float64 `gorm:"column:std;type:double;not null;" json:"std"`
}

// TableName sets the insert table name for this struct type
Expand All @@ -76,10 +76,10 @@ type DishNameTagAverage 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" `
Average float64 `gorm:"column:average;type:double;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"`
Std float64 `gorm:"column:std;type:double;not null;" json:"std"`
}

// TableName sets the insert table name for this struct type
Expand Down
18 changes: 9 additions & 9 deletions server/backend/migration/static_data/source-schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,13 @@ create table if not exists faculty
create table if not exists feedback
(
id int auto_increment primary key,
email_id text charset utf8 null,
receiver text charset utf8 null,
email_id text charset utf8 not null,
receiver text charset utf8 not null,
reply_to text charset utf8 null,
feedback text charset utf8 null,
feedback text charset utf8 not null,
image_count int null,
latitude decimal(11, 8) null,
longitude decimal(11, 8) null,
latitude double null,
longitude double null,
timestamp datetime /* mariadb-5.3 */ default current_timestamp() null
) auto_increment = 293;

Expand Down Expand Up @@ -302,12 +302,12 @@ create table if not exists devices
uuid varchar(50) not null,
created timestamp /* mariadb-5.3 */ null,
lastAccess timestamp /* mariadb-5.3 */ default current_timestamp() not null on update current_timestamp(),
lastApi mediumtext default ('') not null,
lastApi text default ('') not null,
developer enum ('true', 'false') default 'false' not null,
osVersion mediumtext default ('') not null,
appVersion mediumtext default ('') not null,
osVersion text default ('') not null,
appVersion text default ('') not null,
counter int default 0 not null,
pk longtext null,
pk text null,
pkActive enum ('true', 'false') default 'false' not null,
gcmToken text null,
gcmStatus varchar(200) null,
Expand Down
6 changes: 3 additions & 3 deletions server/model/cafeteria.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package model
// 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" `
Name string `gorm:"column:name;type:text;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"`
Latitude float64 `gorm:"column:latitude;type:double;not null;" json:"latitude" `
Longitude float64 `gorm:"column:longitude;type:double;not null;" json:"longitude"`
}

// TableName sets the insert table name for this struct type
Expand Down
2 changes: 1 addition & 1 deletion server/model/cafeteria_rating.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type CafeteriaRating struct {
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" `
Timestamp time.Time `gorm:"column:timestamp;type:timestamp;not null;default:current_timestamp();OnUpdate:current_timestamp();" json:"timestamp" `
Image string `gorm:"column:image;type:text;" json:"image"`
}

Expand Down
4 changes: 2 additions & 2 deletions server/model/cafeteria_rating_statistic.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package model
// CafeteriaRatingStatistic is a view for statistics of cafeteria ratings
type CafeteriaRatingStatistic struct {
CafeteriaID int64 `gorm:"column:cafeteriaID;foreignKey:cafeteria;type:int;not null;"`
Average float64 `gorm:"column:average;type:float;not null;"`
Average float64 `gorm:"column:average;type:double;not null;"`
Min int32 `gorm:"column:min;type:int;not null;"`
Max int32 `gorm:"column:max;type:int;not null;"`
Std float64 `gorm:"column:std;type:float;not null;"`
Std float64 `gorm:"column:std;type:double;not null;"`
}
4 changes: 2 additions & 2 deletions server/model/cafeteria_rating_tag_statistic.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ package model
type CafeteriaRatingTagsStatistic struct {
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"`
Average float64 `gorm:"column:average;type:double;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"`
Std float64 `gorm:"column:std;type:double;not null;" json:"std"`
}
2 changes: 1 addition & 1 deletion server/model/canteen_head_count.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type CanteenHeadCount struct {
Count uint32 `gorm:"column:count;type:int;not null;" json:"count"`
MaxCount uint32 `gorm:"column:max_count;type:int;not null;" json:"max_count"`
Percent float32 `gorm:"column:percent;type:float;not null;" json:"percent"`
Timestamp time.Time `gorm:"column:timestamp;type:timestamp;not null;" json:"timestamp" `
Timestamp time.Time `gorm:"column:timestamp;type:timestamp;not null;default:current_timestamp();OnUpdate:current_timestamp();" json:"timestamp" `
}

// TableName sets the insert table name for this struct type
Expand Down
6 changes: 3 additions & 3 deletions server/model/crontab.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ func (Crontab) TableName() string {
// 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"`
Interval int32 `gorm:"column:interval;type:int;default:7200;" json:"interval"`
LastRun int32 `gorm:"column:lastRun;type:int;default:0;" json:"last_run"`
Type null.String `gorm:"column:type;type:enum ('news', 'mensa', 'movie', 'roomfinder', 'alarm', 'fileDownload','dishNameDownload', 'iosNotifications', 'iosActivityReset', 'canteenHeadCount', 'newExamResultsHook', 'scrapeStudentClubs');" json:"type"`
Interval int32 `gorm:"column:interval;type:int;default:7200;not null" json:"interval"`
LastRun int32 `gorm:"column:lastRun;type:int;default:0;not null" json:"last_run"`
Type null.String `gorm:"column:type;type:enum ('news','mensa','ticketsale','alarm','fileDownload','canteenHeadCount','iosNotifications','iosActivityReset','newExamResultsHook','movie','feedbackEmail','dishNameDownload','scrapeStudentClubs');" json:"type"`
ID null.Int `gorm:"column:id;type:int;" json:"id"`
}
Loading

0 comments on commit 1bfce50

Please sign in to comment.