-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_tables.sql
75 lines (59 loc) · 1.95 KB
/
create_tables.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
-- This script was generated by a beta version of the ERD tool in pgAdmin 4.
-- Please log an issue at https://redmine.postgresql.org/projects/pgadmin4/issues/new if you find any bugs, including reproduction steps.
BEGIN;
CREATE TABLE public.cupboards
(
id bigint NOT NULL GENERATED ALWAYS AS IDENTITY ( INCREMENT 1 START 0 MINVALUE 0 MAXVALUE 9223372036854775807 CACHE 1 ),
name text NOT NULL,
type text NOT NULL,
"user" text NOT NULL,
PRIMARY KEY (id)
);
CREATE TABLE public.items
(
id bigint NOT NULL GENERATED ALWAYS AS IDENTITY ( INCREMENT 1 START 0 MINVALUE 0 MAXVALUE 9223372036854775807 CACHE 1 ),
name text NOT NULL,
barcode text,
PRIMARY KEY (id)
);
CREATE TABLE public.users
(
id bigint NOT NULL GENERATED ALWAYS AS IDENTITY ( INCREMENT 1 START 0 MINVALUE 0 MAXVALUE 9223372036854775807 CACHE 1 ),
password text NOT NULL,
username text NOT NULL UNIQUE,
email text NOT NULL,
PRIMARY KEY (id)
);
CREATE TABLE public.cupboards_users
(
id bigint NOT NULL GENERATED ALWAYS AS IDENTITY ( INCREMENT 1 START 0 MINVALUE 0 MAXVALUE 9223372036854775807 CACHE 1 ),
cupboards_id bigint NOT NULL,
users_id bigint NOT NULL,
name text,
PRIMARY KEY (id)
);
CREATE TABLE public.cupboards_items
(
id bigint NOT NULL GENERATED ALWAYS AS IDENTITY ( INCREMENT 1 START 0 MINVALUE 0 MAXVALUE 9223372036854775807 CACHE 1 ),
cupboards_id bigint NOT NULL,
items_id bigint NOT NULL,
expiry_date text,
PRIMARY KEY (id)
);
ALTER TABLE public.cupboards_users
ADD FOREIGN KEY (cupboards_id)
REFERENCES public.cupboards (id)
NOT VALID;
ALTER TABLE public.cupboards_users
ADD FOREIGN KEY (users_id)
REFERENCES public.users (id)
NOT VALID;
ALTER TABLE public.cupboards_items
ADD FOREIGN KEY (cupboards_id)
REFERENCES public.cupboards (id)
NOT VALID;
ALTER TABLE public.cupboards_items
ADD FOREIGN KEY (items_id)
REFERENCES public.items (id)
NOT VALID;
END;