CREATE TABLE app_flags_games ( game_id UUID PRIMARY KEY NOT NULL DEFAULT gen_random_uuid(), game_seed UUID NOT NULL DEFAULT gen_random_uuid(), uid VARCHAR DEFAULT NULL, tags VARCHAR[] NOT NULL, seconds INT NOT NULL, question_amount INT NOT NULL, question_current INT DEFAULT 1 NOT NULL, questions_errors INT DEFAULT 0 NOT NULL, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, last_activity TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, FOREIGN KEY (uid) REFERENCES users (uid) ); CREATE TABLE app_flags_games_shared_data ( id SERIAL PRIMARY KEY UNIQUE, uid VARCHAR NOT NULL, share_key VARCHAR NOT NULL, game_seed UUID NOT NULL DEFAULT gen_random_uuid(), questions INT DEFAULT 0 NOT NULL, tags VARCHAR[] NOT NULL, seconds INT NOT NULL, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, FOREIGN KEY (uid) REFERENCES users (uid) ); CREATE TABLE app_flags_games_answers ( game_id UUID NOT NULL, question INT NOT NULL, errors INT NOT NULL, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, FOREIGN KEY (game_id) REFERENCES app_flags_games (game_id), CONSTRAINT app_flags_games_answers_unique UNIQUE (game_id, question) );