From aac71f7a39f36f8f79742a83f31b4d51fd857dfe Mon Sep 17 00:00:00 2001 From: Jonni Liljamo Date: Fri, 17 Feb 2023 10:54:06 +0200 Subject: [PATCH] feat(api): migration create_gamedata --- .../down.sql | 3 ++ .../2023-02-17-085226_create_gamedata/up.sql | 14 ++++++++ api/src/schema.rs | 32 +++++++++++++++++++ 3 files changed, 49 insertions(+) create mode 100644 api/migrations/2023-02-17-085226_create_gamedata/down.sql create mode 100644 api/migrations/2023-02-17-085226_create_gamedata/up.sql diff --git a/api/migrations/2023-02-17-085226_create_gamedata/down.sql b/api/migrations/2023-02-17-085226_create_gamedata/down.sql new file mode 100644 index 0000000..535b4e5 --- /dev/null +++ b/api/migrations/2023-02-17-085226_create_gamedata/down.sql @@ -0,0 +1,3 @@ +-- This file should undo anything in `up.sql` + +DROP TABLE gamedata; diff --git a/api/migrations/2023-02-17-085226_create_gamedata/up.sql b/api/migrations/2023-02-17-085226_create_gamedata/up.sql new file mode 100644 index 0000000..a764a0d --- /dev/null +++ b/api/migrations/2023-02-17-085226_create_gamedata/up.sql @@ -0,0 +1,14 @@ +-- Your SQL goes here + +CREATE TABLE gamedata ( + id uuid PRIMARY KEY NOT NULL DEFAULT gen_random_uuid(), + created_at TIMESTAMP NOT NULL DEFAULT current_timestamp, + updated_at TIMESTAMP NOT NULL DEFAULT current_timestamp, + turn SMALLINT NOT NULL, + host_hand json, + host_deck json, + guest_hand json, + guest_deck json +); + +SELECT diesel_manage_updated_at('gamedata'); diff --git a/api/src/schema.rs b/api/src/schema.rs index ed5f622..82994af 100644 --- a/api/src/schema.rs +++ b/api/src/schema.rs @@ -1,5 +1,29 @@ // @generated automatically by Diesel CLI. +diesel::table! { + actions (id) { + id -> Uuid, + created_at -> Timestamp, + updated_at -> Timestamp, + invoker -> Uuid, + data -> Json, + timestamp -> Timestamp, + } +} + +diesel::table! { + gamedata (id) { + id -> Uuid, + created_at -> Timestamp, + updated_at -> Timestamp, + turn -> Int2, + host_hand -> Nullable, + host_deck -> Nullable, + guest_hand -> Nullable, + guest_deck -> Nullable, + } +} + diesel::table! { users (id) { id -> Uuid, @@ -10,3 +34,11 @@ diesel::table! { password -> Varchar, } } + +diesel::joinable!(actions -> users (invoker)); + +diesel::allow_tables_to_appear_in_same_query!( + actions, + gamedata, + users, +); -- 2.44.1