From e4658a4a790b8f2c2e8b1ed9f97e4442d306afb2 Mon Sep 17 00:00:00 2001 From: Fedorov Vladimir Date: Sat, 25 Jul 2026 22:04:07 +0700 Subject: [PATCH] add games teams links --- .../20260725140814_crerate_games_table.sql | 18 ++++++++++++++++++ .../20260725141619_crerate_teams_table.sql | 19 +++++++++++++++++++ .../20260725145354_crerate_links_table.sql | 14 ++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 migrations/20260725140814_crerate_games_table.sql create mode 100644 migrations/20260725141619_crerate_teams_table.sql create mode 100644 migrations/20260725145354_crerate_links_table.sql diff --git a/migrations/20260725140814_crerate_games_table.sql b/migrations/20260725140814_crerate_games_table.sql new file mode 100644 index 0000000..4f92962 --- /dev/null +++ b/migrations/20260725140814_crerate_games_table.sql @@ -0,0 +1,18 @@ +-- +goose Up +CREATE TABLE + IF NOT EXISTS games ( + id SERIAL PRIMARY KEY, + name VARCHAR(255) NOT NULL, + description TEXT, + start_at TIMESTAMP NOT NULL, + scenario_id INTEGER NOT NULL, + status VARCHAR(50) DEFAULT 'ready', + created_at TIMESTAMP NOT NULL DEFAULT NOW (), + started_at TIMESTAMP, + ended_at TIMESTAMP, + + CONSTRAINT fk_games_scenario FOREIGN KEY (scenario_id) REFERENCES scenarios (id) ON DELETE RESTRICT + ); + +-- +goose Down +DROP TABLE IF EXISTS games; diff --git a/migrations/20260725141619_crerate_teams_table.sql b/migrations/20260725141619_crerate_teams_table.sql new file mode 100644 index 0000000..c441df6 --- /dev/null +++ b/migrations/20260725141619_crerate_teams_table.sql @@ -0,0 +1,19 @@ +-- +goose Up +CREATE TABLE + IF NOT EXISTS teams ( + id SERIAL PRIMARY KEY, + name VARCHAR(255) NOT NULL, + status VARCHAR(50) DEFAULT 'register', + creator_id INTEGER NOT NULL, + game_id INTEGER NOT NULL, + scenario_id INTEGER NOT NULL, + password TEXT, + created_at TIMESTAMP NOT NULL DEFAULT NOW (), + + CONSTRAINT fk_teams_game FOREIGN KEY (game_id) REFERENCES games (id) ON DELETE RESTRICT, + CONSTRAINT fk_teams_creator FOREIGN KEY (creator_id) REFERENCES users (id) ON DELETE RESTRICT, + CONSTRAINT fk_teams_scenario FOREIGN KEY (scenario_id) REFERENCES scenarios (id) ON DELETE RESTRICT + ); + +-- +goose Down +DROP TABLE IF EXISTS teams; diff --git a/migrations/20260725145354_crerate_links_table.sql b/migrations/20260725145354_crerate_links_table.sql new file mode 100644 index 0000000..379918e --- /dev/null +++ b/migrations/20260725145354_crerate_links_table.sql @@ -0,0 +1,14 @@ +-- +goose Up +CREATE TABLE + IF NOT EXISTS links ( + id SERIAL PRIMARY KEY, + team_id INTEGER, + game_id INTEGER, + created_at TIMESTAMP NOT NULL DEFAULT NOW (), + + CONSTRAINT fk_links_team FOREIGN KEY (team_id) REFERENCES teams (id) ON DELETE RESTRICT, + CONSTRAINT fk_links_game FOREIGN KEY (game_id) REFERENCES games (id) ON DELETE RESTRICT + ); + +-- +goose Down +DROP TABLE IF EXISTS links;