Open History to see the last commit
1-- One shared board. The game row holds counters and the reset generation.
2CREATE TABLE IF NOT EXISTS games (
3 game_id integer PRIMARY KEY CHECK (game_id = 1),
4 started_at bigint NOT NULL,
5 edges_placed integer NOT NULL DEFAULT 0,
6 scores integer[] NOT NULL DEFAULT ARRAY[0, 0, 0, 0],
7 complete boolean NOT NULL DEFAULT FALSE
8);
9
10-- Owners use three bits each: 0 is empty; 1-4 identify the team. Only tiles
11-- on the bottom/right boundary store the extra outer edges (three bytes each).
12CREATE TABLE IF NOT EXISTS board_tiles (
13 game_id integer NOT NULL REFERENCES games (game_id),
14 tile_id integer NOT NULL CHECK (tile_id >= 0 AND tile_id < 15625),
15 revision integer NOT NULL DEFAULT 0,
16 edges bytea NOT NULL,
17 boxes bytea NOT NULL CHECK (octet_length(boxes) = 24),
18 PRIMARY KEY (game_id, tile_id),
19 CHECK (octet_length(edges) = 48 + CASE WHEN tile_id / 125 = 124 THEN
20 3
21 ELSE
22 0
23 END + CASE WHEN tile_id % 125 = 124 THEN
24 3
25 ELSE
26 0
27 END)
28);
29
30-- A persistent token bucket per signed player identity. Refills are computed
31-- lazily from timestamps; no background refill timer or in-memory bucket.
32CREATE TABLE IF NOT EXISTS player_quotas (
33 game_id integer NOT NULL REFERENCES games (game_id),
34 player_id uuid NOT NULL,
35 -- Database setup installs the upper bound from the shared game configuration.
36 tokens integer NOT NULL CHECK (tokens >= 0),
37 last_refill_at bigint NOT NULL,
38 last_seen_at bigint NOT NULL,
39 PRIMARY KEY (game_id, player_id)
40);