21 lines
937 B
SQL
21 lines
937 B
SQL
-- Optimistic locking for the match actor, the hosting IRC account for
|
|
-- rejoining after a restart, and an undo log for rating changes.
|
|
ALTER TABLE match ADD COLUMN IF NOT EXISTS revision integer NOT NULL DEFAULT 0;
|
|
ALTER TABLE match ADD COLUMN IF NOT EXISTS irc_account text;
|
|
|
|
CREATE TABLE IF NOT EXISTS rating_change (
|
|
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
match_id uuid NOT NULL REFERENCES match(id) ON DELETE CASCADE,
|
|
subject text NOT NULL,
|
|
subject_id text NOT NULL,
|
|
before integer NOT NULL,
|
|
after integer NOT NULL,
|
|
won boolean NOT NULL,
|
|
created_at timestamptz NOT NULL DEFAULT now()
|
|
);
|
|
CREATE INDEX IF NOT EXISTS idx_rating_change_match ON rating_change (match_id);
|
|
CREATE INDEX IF NOT EXISTS idx_rating_change_subject ON rating_change (subject_id);
|
|
|
|
-- Matches the previous process left mid-flight are resumed by the runtime.
|
|
CREATE INDEX IF NOT EXISTS idx_match_game_match_state ON match_game (match_id, state);
|