Enha: not null fields in db
This commit is contained in:
@ -2,20 +2,17 @@
|
|||||||
|
|
||||||
CREATE TABLE rooms (
|
CREATE TABLE rooms (
|
||||||
id TEXT PRIMARY KEY,
|
id TEXT PRIMARY KEY,
|
||||||
created_at TIMESTAMP NOT NULL,
|
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
creator_name TEXT NOT NULL,
|
creator_name TEXT NOT NULL,
|
||||||
team_turn TEXT NOT NULL DEFAULT '',
|
team_turn TEXT NOT NULL DEFAULT '',
|
||||||
this_turn_limit INTEGER,
|
this_turn_limit INTEGER NOT NULL DEFAULT 0,
|
||||||
opened_this_turn INTEGER,
|
opened_this_turn INTEGER NOT NULL DEFAULT 0,
|
||||||
blue_counter INTEGER,
|
blue_counter INTEGER NOT NULL DEFAULT 0,
|
||||||
red_counter INTEGER,
|
red_counter INTEGER NOT NULL DEFAULT 0,
|
||||||
red_turn BOOLEAN,
|
red_turn BOOLEAN NOT NULL DEFAULT FALSE,
|
||||||
mime_done BOOLEAN,
|
mime_done BOOLEAN NOT NULL DEFAULT FALSE,
|
||||||
is_public BOOLEAN,
|
is_running BOOLEAN NOT NULL DEFAULT FALSE,
|
||||||
is_running BOOLEAN,
|
is_over BOOLEAN NOT NULL DEFAULT FALSE,
|
||||||
language TEXT NOT NULL DEFAULT '',
|
|
||||||
round_time INTEGER,
|
|
||||||
is_over BOOLEAN,
|
|
||||||
team_won TEXT NOT NULL DEFAULT '',
|
team_won TEXT NOT NULL DEFAULT '',
|
||||||
room_pass TEXT NOT NULL DEFAULT ''
|
room_pass TEXT NOT NULL DEFAULT ''
|
||||||
);
|
);
|
||||||
@ -26,7 +23,7 @@ CREATE TABLE players (
|
|||||||
username TEXT NOT NULL,
|
username TEXT NOT NULL,
|
||||||
team TEXT NOT NULL DEFAULT '', -- 'red' or 'blue'
|
team TEXT NOT NULL DEFAULT '', -- 'red' or 'blue'
|
||||||
role TEXT NOT NULL DEFAULT '', -- 'guesser' or 'mime'
|
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)
|
FOREIGN KEY (room_id) REFERENCES rooms(id)
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -35,8 +32,8 @@ CREATE TABLE word_cards (
|
|||||||
room_id TEXT NOT NULL,
|
room_id TEXT NOT NULL,
|
||||||
word TEXT NOT NULL,
|
word TEXT NOT NULL,
|
||||||
color TEXT NOT NULL DEFAULT '',
|
color TEXT NOT NULL DEFAULT '',
|
||||||
revealed BOOLEAN DEFAULT FALSE,
|
revealed BOOLEAN NOT NULL DEFAULT FALSE,
|
||||||
mime_view BOOLEAN DEFAULT FALSE,
|
mime_view BOOLEAN NOT NULL DEFAULT FALSE,
|
||||||
FOREIGN KEY (room_id) REFERENCES rooms(id)
|
FOREIGN KEY (room_id) REFERENCES rooms(id)
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -44,7 +41,7 @@ CREATE TABLE card_marks (
|
|||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
card_id INTEGER NOT NULL,
|
card_id INTEGER NOT NULL,
|
||||||
username TEXT NOT NULL,
|
username TEXT NOT NULL,
|
||||||
active BOOLEAN DEFAULT TRUE,
|
active BOOLEAN NOT NULL DEFAULT TRUE,
|
||||||
FOREIGN KEY (card_id) REFERENCES word_cards(id)
|
FOREIGN KEY (card_id) REFERENCES word_cards(id)
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -57,7 +54,7 @@ CREATE TABLE actions (
|
|||||||
word TEXT NOT NULL DEFAULT '',
|
word TEXT NOT NULL DEFAULT '',
|
||||||
word_color TEXT NOT NULL DEFAULT '',
|
word_color TEXT NOT NULL DEFAULT '',
|
||||||
number_associated TEXT NOT NULL DEFAULT '', -- for clues
|
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)
|
FOREIGN KEY (room_id) REFERENCES rooms(id)
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -67,6 +64,6 @@ CREATE TABLE settings (
|
|||||||
language TEXT NOT NULL DEFAULT 'en',
|
language TEXT NOT NULL DEFAULT 'en',
|
||||||
room_pass TEXT NOT NULL DEFAULT '',
|
room_pass TEXT NOT NULL DEFAULT '',
|
||||||
turn_time INTEGER NOT NULL DEFAULT 60, -- seconds
|
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)
|
FOREIGN KEY (room_id) REFERENCES rooms(id)
|
||||||
);
|
);
|
||||||
|
@ -139,15 +139,12 @@ type Room struct {
|
|||||||
RedCounter uint8 `db:"red_counter"`
|
RedCounter uint8 `db:"red_counter"`
|
||||||
RedTurn bool `db:"red_turn"`
|
RedTurn bool `db:"red_turn"`
|
||||||
MimeDone bool `db:"mime_done"`
|
MimeDone bool `db:"mime_done"`
|
||||||
IsPublic bool `db:"is_public"`
|
|
||||||
IsRunning bool `json:"is_running" db:"is_running"`
|
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"`
|
IsOver bool `db:"is_over"`
|
||||||
TeamWon UserTeam `db:"team_won"`
|
TeamWon UserTeam `db:"team_won"`
|
||||||
RoomPass string `json:"room_pass" db:"room_pass"`
|
RoomPass string `json:"room_pass" db:"room_pass"`
|
||||||
|
RoomLink string `db:"room_link"`
|
||||||
// fields not in db
|
// fields not in db
|
||||||
RoomLink string `db:"-"`
|
|
||||||
ActionHistory []Action `db:"-"`
|
ActionHistory []Action `db:"-"`
|
||||||
RedTeam Team `db:"-"`
|
RedTeam Team `db:"-"`
|
||||||
BlueTeam Team `db:"-"`
|
BlueTeam Team `db:"-"`
|
||||||
@ -384,6 +381,7 @@ type WordCard struct {
|
|||||||
Mark []CardMark `json:"marks"`
|
Mark []CardMark `json:"marks"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// table: settings
|
||||||
type GameSettings struct {
|
type GameSettings struct {
|
||||||
Language string `json:"language" example:"en" form:"language" db:"language"`
|
Language string `json:"language" example:"en" form:"language" db:"language"`
|
||||||
RoomPass string `json:"room_pass" db:"room_pass"`
|
RoomPass string `json:"room_pass" db:"room_pass"`
|
||||||
|
@ -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 {
|
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
|
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 {
|
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
|
return err
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user