From d5b3128f13bdad19cf99451bdb994387f885d731 Mon Sep 17 00:00:00 2001 From: Eero Holmala Date: Mon, 29 May 2023 12:21:14 +0300 Subject: [PATCH] Backend: Move Sql from dev to Backend.DataAccess/Sql --- .../Sql/coresim/insert.psql | 1 + .../Sql/coresim/schema.psql | 26 +++++++++++++++++ web/Backend.DataAccess/Sql/items/schema.sql | 28 +++++++++++++++++++ 3 files changed, 55 insertions(+) create mode 100644 web/Backend.DataAccess/Sql/coresim/insert.psql create mode 100644 web/Backend.DataAccess/Sql/coresim/schema.psql create mode 100644 web/Backend.DataAccess/Sql/items/schema.sql diff --git a/web/Backend.DataAccess/Sql/coresim/insert.psql b/web/Backend.DataAccess/Sql/coresim/insert.psql new file mode 100644 index 0000000..b136b29 --- /dev/null +++ b/web/Backend.DataAccess/Sql/coresim/insert.psql @@ -0,0 +1 @@ +INSERT INTO public.PERSON (person_firstname, person_lastname, person_age, alive, nation_id) VALUES ('lohojequ', 'Vanrokick', 55, true, 1); diff --git a/web/Backend.DataAccess/Sql/coresim/schema.psql b/web/Backend.DataAccess/Sql/coresim/schema.psql new file mode 100644 index 0000000..63df6d8 --- /dev/null +++ b/web/Backend.DataAccess/Sql/coresim/schema.psql @@ -0,0 +1,26 @@ +-- Add UUID extension +CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; + +CREATE TABLE IF NOT EXISTS public.NATION ( + nation_id SERIAL UNIQUE, + nation_name VARCHAR(50) NOT NULL, + PRIMARY KEY (nation_id) +); + +CREATE TABLE IF NOT EXISTS public.PERSON ( + person_id uuid UNIQUE NOT NULL DEFAULT uuid_generate_v4(), + person_firstname VARCHAR(36), + person_lastname VARCHAR(36), + person_age INTEGER DEFAULT 0 CHECK (person_age >= 0), + alive BOOLEAN NOT NULL DEFAULT true, + nation_id INTEGER REFERENCES public.NATION(nation_id) ON UPDATE CASCADE, + PRIMARY KEY (person_id) +); + +CREATE TABLE IF NOT EXISTS public.WORKORDER ( + wo_id uuid UNIQUE NOT NULL DEFAULT uuid_generate_v4(), + wo_description TEXT, + wo_complete BOOLEAN NOT NULL DEFAULT false, + person_id uuid NOT NULL REFERENCES public.PERSON(person_id) ON UPDATE CASCADE, + PRIMARY KEY (wo_id) +); \ No newline at end of file diff --git a/web/Backend.DataAccess/Sql/items/schema.sql b/web/Backend.DataAccess/Sql/items/schema.sql new file mode 100644 index 0000000..44c8cb2 --- /dev/null +++ b/web/Backend.DataAccess/Sql/items/schema.sql @@ -0,0 +1,28 @@ +-- User Access And Permissions + +-- Tables +CREATE TABLE IF NOT EXISTS public.user ( + id INTEGER PRIMARY KEY, + created_date DATETIME NOT NULL DEFAULT NOW(), + updated_date DATETIME NOT NULL DEFAULT NOW(), + last_login DATETIME, + username VARCHAR(255) NOT NULL, + email_id INT NOT NULL +); + +CREATE TABLE IF NOT EXISTS public.email ( + id TEXT PRIMARY KEY, + created_date DATETIME NOT NULL DEFAULT NOW(), + updated_date DATETIME NOT NULL DEFAULT NOW(), + user_id INT FOREIGN KEY +); + +CREATE TABLE IF NOT EXISTS public.items ( + id INTEGER PRIMARY KEY, + created_date DATETIME NOT NULL DEFAULT NOW(), + updated_date DATETIME NOT NULL DEFAULT NOW(), + user_id INT FOREIGN KEY + img_url TEXT, + flavor_text TEXT, + stats JSON DEFAULT '{}' +); \ No newline at end of file