From 027503b8f813bfcfbc9546b4255790a1b18d8ead Mon Sep 17 00:00:00 2001 From: Jonni Liljamo Date: Fri, 17 Feb 2023 12:05:27 +0200 Subject: [PATCH] feat(api): migration create_games --- .../2023-02-17-095727_create_games/down.sql | 3 +++ .../2023-02-17-095727_create_games/up.sql | 14 ++++++++++++++ api/src/schema.rs | 15 +++++++++++++++ 3 files changed, 32 insertions(+) create mode 100644 api/migrations/2023-02-17-095727_create_games/down.sql create mode 100644 api/migrations/2023-02-17-095727_create_games/up.sql diff --git a/api/migrations/2023-02-17-095727_create_games/down.sql b/api/migrations/2023-02-17-095727_create_games/down.sql new file mode 100644 index 0000000..8a8540a --- /dev/null +++ b/api/migrations/2023-02-17-095727_create_games/down.sql @@ -0,0 +1,3 @@ +-- This file should undo anything in `up.sql` + +DROP TABLE games; diff --git a/api/migrations/2023-02-17-095727_create_games/up.sql b/api/migrations/2023-02-17-095727_create_games/up.sql new file mode 100644 index 0000000..16aca6f --- /dev/null +++ b/api/migrations/2023-02-17-095727_create_games/up.sql @@ -0,0 +1,14 @@ +-- Your SQL goes here + +CREATE TABLE games ( + id uuid PRIMARY KEY NOT NULL DEFAULT gen_random_uuid(), + created_at TIMESTAMPTZ NOT NULL DEFAULT current_timestamp, + updated_at TIMESTAMPTZ NOT NULL DEFAULT current_timestamp, + host_id uuid REFERENCES users(id) NOT NULL, + guest_id uuid REFERENCES users(id) DEFAULT NULL, + state SMALLINT NOT NULL, + ended_at TIMESTAMPTZ DEFAULT NULL, + game_data_id uuid REFERENCES gamedata(id) NOT NULL +); + +SELECT diesel_manage_updated_at('games'); diff --git a/api/src/schema.rs b/api/src/schema.rs index f80c4dd..646d624 100644 --- a/api/src/schema.rs +++ b/api/src/schema.rs @@ -25,6 +25,19 @@ diesel::table! { } } +diesel::table! { + games (id) { + id -> Uuid, + created_at -> Timestamptz, + updated_at -> Timestamptz, + host_id -> Uuid, + guest_id -> Nullable, + state -> Int2, + ended_at -> Nullable, + game_data_id -> Uuid, + } +} + diesel::table! { users (id) { id -> Uuid, @@ -38,9 +51,11 @@ diesel::table! { diesel::joinable!(actions -> gamedata (game_data_id)); diesel::joinable!(actions -> users (invoker)); +diesel::joinable!(games -> gamedata (game_data_id)); diesel::allow_tables_to_appear_in_same_query!( actions, gamedata, + games, users, ); -- 2.44.1