Skip to content

Commit

Permalink
cleanup models (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
dheidemann committed Jul 31, 2024
1 parent c4fef82 commit b48fe59
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 58 deletions.
1 change: 0 additions & 1 deletion server/db/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ func Init(ctx context.Context, tracer *trace.TracerProvider) (*bun.DB, *sql.DB,
(*models.User)(nil),
(*models.Building)(nil),
(*models.Room)(nil),
(*models.Answer)(nil),
(*models.Setting)(nil)}

for _, relation := range relations {
Expand Down
25 changes: 0 additions & 25 deletions server/models/answer.go

This file was deleted.

14 changes: 7 additions & 7 deletions server/models/building.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import (
type Building struct {
bun.BaseModel `bun:"table:buildings,alias:b"`

ID int32 `bun:"id,pk,autoincrement"`
Name string `bun:"name,notnull"`
Street string `bun:"street,notnull"`
Number string `bun:"number,notnull"`
City string `bun:"city,notnull"`
Zip int32 `bun:"zip,notnull"`
Osm string `bun:"osm,notnull"`
ID int32 `bun:",pk,autoincrement"`
Name string `bun:",notnull,type:varchar(255)"`
Street string `bun:",notnull,type:varchar(255)"`
Number string `bun:",notnull,type:varchar(255)"`
City string `bun:",notnull,type:varchar(255)"`
Zip int32 `bun:",notnull"`
Osm string `bun:",notnull,type:varchar(255)"`

Rooms []*Room `bun:"rel:has-many,join:id=building_id"`
}
8 changes: 4 additions & 4 deletions server/models/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ type Event struct {
bun.BaseModel `bun:"table:events,alias:e"`

ID int32 `bun:",pk,autoincrement"`
Title string `bun:",notnull"`
Title string `bun:",notnull,type:varchar(255)"`
Description string
TopicName string `bun:",notnull"`
TypeName string `bun:",notnull"`
TopicName string `bun:",notnull,type:varchar(50)"`
TypeName string `bun:",notnull,type:varchar(50)"`
From time.Time `bun:",notnull"`
To time.Time `bun:",notnull"`
NeedsTutors bool `bun:",notnull"`
Expand All @@ -39,7 +39,7 @@ type EventToTutor struct {
Event *Event `bun:"rel:belongs-to,join:event_id=id"`
TutorMail string `bun:",pk"`
Tutor *Tutor `bun:"rel:belongs-to,join:tutor_mail=mail"`
RoomNumber string `bun:",pk"`
RoomNumber string `bun:",pk,type:varchar(50)"`
BuildingID int32 `bun:",pk"`
Room *Room `bun:"rel:belongs-to,join:room_number=number,join:building_id=building_id"`
}
Expand Down
6 changes: 3 additions & 3 deletions server/models/label.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
type Label struct {
bun.BaseModel `bun:"table:labels,alias:l"`

Name string `bun:",pk"`
Color string
Kind string `bun:",notnull"`
Name string `bun:",pk,type:varchar(50)"`
Color string `bun:",type:varchar(7)"`
Kind string `bun:",notnull,type:varchar(20)"`
}
8 changes: 4 additions & 4 deletions server/models/room.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
type Room struct {
bun.BaseModel `bun:"table:rooms,alias:r"`

Number string `bun:",pk,notnull"`
Name string
Number string `bun:",pk,notnull,type:varchar(50)"`
Name string `bun:",type:varchar(255)"`
Capacity int16
Floor int8
BuildingID int32 `bun:",pk"`
Expand All @@ -26,10 +26,10 @@ func (*Room) BeforeCreateTable(ctx context.Context, query *bun.CreateTableQuery)
}

type RoomToEvent struct {
RoomNumber string `bun:",pk"`
RoomNumber string `bun:",pk,type:varchar(50)"`
BuildingID int32 `bun:",pk"`
Room *Room `bun:"rel:belongs-to,join:room_number=number,join:building_id=building_id"`
EventID int32 `bun:"event_id,pk"`
EventID int32 `bun:",pk"`
Event *Event `bun:"rel:belongs-to,join:event_id=id"`
}

Expand Down
2 changes: 1 addition & 1 deletion server/models/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ type Setting struct {

Key string `bun:",pk,type:varchar(255)"`
Value string `bun:",notnull"`
Type string `bun:"notnull,type:varchar(50)"`
Type string `bun:",notnull,type:varchar(50)"`
}
7 changes: 3 additions & 4 deletions server/models/student.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,17 @@ type Student struct {
Score int8
Accepted bool

EventsRegistered []Event `bun:"m2m:student_to_events,join:Student=Event"`
Answers []Answer `bun:"rel:has-many,join:mail=student_mail"`
EventsRegistered []Event `bun:"m2m:student_to_events,join:Student=Event"`
}

func (Student) IsUser() {}

type StudentToEvent struct {
StudentMail string `bun:",pk"`
StudentMail string `bun:",pk,type:varchar(255)"`
Student *Student `bun:"rel:belongs-to,join:student_mail=mail"`
EventID int32 `bun:",pk"`
Event *Event `bun:"rel:belongs-to,join:event_id=id"`
RoomNumber string `bun:",pk"`
RoomNumber string `bun:",pk,type:varchar(50)"`
BuildingID int32 `bun:",pk"`
Room *Room `bun:"rel:belongs-to,join:room_number=number,join:building_id=building_id"`
}
Expand Down
2 changes: 1 addition & 1 deletion server/models/tutor.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type Tutor struct {
func (Tutor) IsUser() {}

type TutorToEvent struct {
TutorMail string `bun:",pk"`
TutorMail string `bun:",pk,type:varchar(255)"`
Tutor *Tutor `bun:"rel:belongs-to,join:tutor_mail=mail"`
EventID int32 `bun:",pk"`
Event *Event `bun:"rel:belongs-to,join:event_id=id"`
Expand Down
16 changes: 8 additions & 8 deletions server/models/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import (
type User struct {
bun.BaseModel `bun:"table:users,alias:u"`

Mail string `bun:"mail,pk,notnull"`
Fn string `bun:"fn,notnull"`
Sn string `bun:"sn"`
Confirmed bool `bun:"confirmed,notnull"`
SessionID int32 `bun:"session_id"`
LastLogin time.Time `bun:"last_login,default:current_timestamp"`
PasswordHash string `bun:"password_hash"`
CreatedAt time.Time `bun:"created_at,default:current_timestamp"`
Mail string `bun:",pk,notnull,type:varchar(255)"`
Fn string `bun:",notnull,type:varchar(255)"`
Sn string `bun:"type:varchar(255)"`
Confirmed bool `bun:"confirmed,notnull"`
SessionID int32
LastLogin time.Time `bun:",default:current_timestamp"`
PasswordHash string `bun:"type:varchar(64)"`
CreatedAt time.Time `bun:",default:current_timestamp"`
}

0 comments on commit b48fe59

Please sign in to comment.