diff --git a/migrations/001_initial_schema.up.sql b/migrations/001_initial_schema.up.sql index ed67577..1e4acfe 100644 --- a/migrations/001_initial_schema.up.sql +++ b/migrations/001_initial_schema.up.sql @@ -2,20 +2,17 @@ CREATE TABLE rooms ( id TEXT PRIMARY KEY, - created_at TIMESTAMP NOT NULL, + created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, creator_name TEXT NOT NULL, team_turn TEXT NOT NULL DEFAULT '', - this_turn_limit INTEGER, - opened_this_turn INTEGER, - blue_counter INTEGER, - red_counter INTEGER, - red_turn BOOLEAN, - mime_done BOOLEAN, - is_public BOOLEAN, - is_running BOOLEAN, - language TEXT NOT NULL DEFAULT '', - round_time INTEGER, - is_over BOOLEAN, + this_turn_limit INTEGER NOT NULL DEFAULT 0, + opened_this_turn INTEGER NOT NULL DEFAULT 0, + blue_counter INTEGER NOT NULL DEFAULT 0, + red_counter INTEGER NOT NULL DEFAULT 0, + red_turn BOOLEAN NOT NULL DEFAULT FALSE, + mime_done BOOLEAN NOT NULL DEFAULT FALSE, + is_running BOOLEAN NOT NULL DEFAULT FALSE, + is_over BOOLEAN NOT NULL DEFAULT FALSE, team_won TEXT NOT NULL DEFAULT '', room_pass TEXT NOT NULL DEFAULT '' ); @@ -26,7 +23,7 @@ CREATE TABLE players ( username TEXT NOT NULL, team TEXT NOT NULL DEFAULT '', -- 'red' or 'blue' role TEXT NOT NULL DEFAULT '', -- 'guesser' or 'mime' - is_bot BOOLEAN DEFAULT FALSE, + is_bot BOOLEAN NOT NULL DEFAULT FALSE, FOREIGN KEY (room_id) REFERENCES rooms(id) ); @@ -35,8 +32,8 @@ CREATE TABLE word_cards ( room_id TEXT NOT NULL, word TEXT NOT NULL, color TEXT NOT NULL DEFAULT '', - revealed BOOLEAN DEFAULT FALSE, - mime_view BOOLEAN DEFAULT FALSE, + revealed BOOLEAN NOT NULL DEFAULT FALSE, + mime_view BOOLEAN NOT NULL DEFAULT FALSE, FOREIGN KEY (room_id) REFERENCES rooms(id) ); @@ -44,7 +41,7 @@ CREATE TABLE card_marks ( id INTEGER PRIMARY KEY AUTOINCREMENT, card_id INTEGER NOT NULL, username TEXT NOT NULL, - active BOOLEAN DEFAULT TRUE, + active BOOLEAN NOT NULL DEFAULT TRUE, FOREIGN KEY (card_id) REFERENCES word_cards(id) ); @@ -57,7 +54,7 @@ CREATE TABLE actions ( word TEXT NOT NULL DEFAULT '', word_color TEXT NOT NULL DEFAULT '', number_associated TEXT NOT NULL DEFAULT '', -- for clues - created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY (room_id) REFERENCES rooms(id) ); @@ -67,6 +64,6 @@ CREATE TABLE settings ( language TEXT NOT NULL DEFAULT 'en', room_pass TEXT NOT NULL DEFAULT '', turn_time INTEGER NOT NULL DEFAULT 60, -- seconds - created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY (room_id) REFERENCES rooms(id) ); diff --git a/models/main.go b/models/main.go index e594103..3ff13d0 100644 --- a/models/main.go +++ b/models/main.go @@ -139,15 +139,12 @@ type Room struct { RedCounter uint8 `db:"red_counter"` RedTurn bool `db:"red_turn"` MimeDone bool `db:"mime_done"` - IsPublic bool `db:"is_public"` IsRunning bool `json:"is_running" db:"is_running"` - Language string `json:"language" example:"en" form:"language" db:"language"` - RoundTime uint32 `json:"round_time" db:"round_time"` IsOver bool `db:"is_over"` TeamWon UserTeam `db:"team_won"` RoomPass string `json:"room_pass" db:"room_pass"` + RoomLink string `db:"room_link"` // fields not in db - RoomLink string `db:"-"` ActionHistory []Action `db:"-"` RedTeam Team `db:"-"` BlueTeam Team `db:"-"` @@ -384,6 +381,7 @@ type WordCard struct { Mark []CardMark `json:"marks"` } +// table: settings type GameSettings struct { Language string `json:"language" example:"en" form:"language" db:"language"` RoomPass string `json:"room_pass" db:"room_pass"` diff --git a/repos/rooms.go b/repos/rooms.go index af8a68d..00ee133 100644 --- a/repos/rooms.go +++ b/repos/rooms.go @@ -32,7 +32,7 @@ func (p *RepoProvider) GetRoomByID(ctx context.Context, id string) (*models.Room } func (p *RepoProvider) CreateRoom(ctx context.Context, r *models.Room) error { - _, err := p.DB.ExecContext(ctx, `INSERT INTO rooms (id, created_at, creator_name, team_turn, this_turn_limit, opened_this_turn, blue_counter, red_counter, red_turn, mime_done, is_public, is_running, language, round_time, is_over, team_won, room_pass) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, r.ID, r.CreatedAt, r.CreatorName, r.TeamTurn, r.ThisTurnLimit, r.OpenedThisTurn, r.BlueCounter, r.RedCounter, r.RedTurn, r.MimeDone, r.IsPublic, r.IsRunning, r.Language, r.RoundTime, r.IsOver, r.TeamWon, r.RoomPass) + _, err := p.DB.ExecContext(ctx, `INSERT INTO rooms (id, created_at, creator_name, team_turn, this_turn_limit, opened_this_turn, blue_counter, red_counter, red_turn, mime_done, is_running, round_time, is_over, team_won, room_pass) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, r.ID, r.CreatedAt, r.CreatorName, r.TeamTurn, r.ThisTurnLimit, r.OpenedThisTurn, r.BlueCounter, r.RedCounter, r.RedTurn, r.MimeDone, r.IsRunning, r.RoundTime, r.IsOver, r.TeamWon, r.RoomPass) return err } @@ -42,6 +42,6 @@ func (p *RepoProvider) DeleteRoomByID(ctx context.Context, id string) error { } func (p *RepoProvider) UpdateRoom(ctx context.Context, r *models.Room) error { - _, err := p.DB.ExecContext(ctx, `UPDATE rooms SET team_turn = ?, this_turn_limit = ?, opened_this_turn = ?, blue_counter = ?, red_counter = ?, red_turn = ?, mime_done = ?, is_public = ?, is_running = ?, language = ?, round_time = ?, is_over = ?, team_won = ?, room_pass = ? WHERE id = ?`, r.TeamTurn, r.ThisTurnLimit, r.OpenedThisTurn, r.BlueCounter, r.RedCounter, r.RedTurn, r.MimeDone, r.IsPublic, r.IsRunning, r.Language, r.RoundTime, r.IsOver, r.TeamWon, r.RoomPass, r.ID) + _, err := p.DB.ExecContext(ctx, `UPDATE rooms SET team_turn = ?, this_turn_limit = ?, opened_this_turn = ?, blue_counter = ?, red_counter = ?, red_turn = ?, mime_done = ?, is_running = ?, round_time = ?, is_over = ?, team_won = ?, room_pass = ? WHERE id = ?`, r.TeamTurn, r.ThisTurnLimit, r.OpenedThisTurn, r.BlueCounter, r.RedCounter, r.RedTurn, r.MimeDone, r.IsRunning, r.RoundTime, r.IsOver, r.TeamWon, r.RoomPass, r.ID) return err }