2024-11-30 18:04:07 +00:00
|
|
|
CREATE TYPE wenglin_t AS
|
|
|
|
(
|
|
|
|
rating float8,
|
2024-11-28 11:24:15 +00:00
|
|
|
uncertainty float8
|
|
|
|
);
|
|
|
|
|
2024-11-30 18:04:07 +00:00
|
|
|
CREATE TABLE players
|
|
|
|
(
|
|
|
|
id INTEGER GENERATED ALWAYS AS IDENTITY,
|
2024-11-28 11:24:15 +00:00
|
|
|
|
2024-11-30 18:04:07 +00:00
|
|
|
wenglin wenglin_t NOT NULL DEFAULT ROW (25.0, 25.0 / 3),
|
2024-11-28 11:24:15 +00:00
|
|
|
|
|
|
|
telegram_id BIGINT,
|
|
|
|
|
|
|
|
CONSTRAINT telegram_ids_are_unique UNIQUE (telegram_id),
|
|
|
|
PRIMARY KEY (id)
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TYPE outcome_t AS ENUM (
|
|
|
|
'AWins',
|
|
|
|
'BWins',
|
|
|
|
'Tie'
|
2024-11-30 18:04:07 +00:00
|
|
|
);
|
2024-11-28 11:24:15 +00:00
|
|
|
|
2024-11-30 18:04:07 +00:00
|
|
|
CREATE TABLE matches
|
|
|
|
(
|
|
|
|
id INTEGER GENERATED ALWAYS AS IDENTITY,
|
|
|
|
instant timestamptz NOT NULL DEFAULT NOW(),
|
|
|
|
name VARCHAR,
|
2024-11-28 11:24:15 +00:00
|
|
|
|
2024-11-30 18:04:07 +00:00
|
|
|
player_a_id BIGINT NOT NULL,
|
|
|
|
player_a_wenglin_before wenglin_t NOT NULL,
|
|
|
|
player_a_wenglin_after wenglin_t NOT NULL,
|
2024-11-28 11:24:15 +00:00
|
|
|
|
2024-11-30 18:04:07 +00:00
|
|
|
player_b_id BIGINT NOT NULL,
|
|
|
|
player_b_wenglin_before wenglin_t NOT NULL,
|
|
|
|
player_b_wenglin_after wenglin_t NOT NULL,
|
2024-11-28 11:24:15 +00:00
|
|
|
|
2024-11-30 18:04:07 +00:00
|
|
|
outcome outcome_t NOT NULL,
|
2024-11-28 11:24:15 +00:00
|
|
|
|
|
|
|
CONSTRAINT match_unique_name UNIQUE (name),
|
|
|
|
CONSTRAINT not_same_player CHECK (player_a_id != player_b_id),
|
|
|
|
FOREIGN KEY (player_a_id) REFERENCES players (id),
|
|
|
|
FOREIGN KEY (player_b_id) REFERENCES players (id),
|
|
|
|
PRIMARY KEY (id)
|
|
|
|
);
|