-
Notifications
You must be signed in to change notification settings - Fork 0
/
schema.sql
63 lines (51 loc) · 1.44 KB
/
schema.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
CREATE TABLE IF NOT EXISTS category (
uuid blob NOT NULL PRIMARY KEY,
name text NOT NULL,
supercategory blob
);
CREATE TABLE IF NOT EXISTS instance (
uuid blob NOT NULL PRIMARY KEY,
identifier text NOT NULL,
product blob NOT NULL,
FOREIGN KEY (product) REFERENCES product (uuid)
);
CREATE TABLE IF NOT EXISTS loan (
uuid blob NOT NULL PRIMARY KEY,
user blob NOT NULL,
date_start text NOT NULL,
date_end text NOT NULL,
accepted boolean NOT NULL,
description text,
FOREIGN KEY (user) REFERENCES user (uuid)
);
CREATE TABLE IF NOT EXISTS product (
uuid blob NOT NULL PRIMARY KEY,
name text NOT NULL,
category blob NOT NULL,
FOREIGN KEY (category) REFERENCES category (uuid)
);
CREATE TABLE IF NOT EXISTS user (
uuid blob NOT NULL PRIMARY KEY,
name text NOT NULL
);
CREATE TABLE IF NOT EXISTS membership_payments (
uuid blob NOT NULL PRIMARY KEY,
user blob NOT NULL,
membership_type blob NOT NULL,
price numeric NOT NULL,
date_start text NOT NULL,
date_end text NOT NULL,
FOREIGN KEY (user) REFERENCES user (uuid),
FOREIGN KEY (membership_type) REFERENCES membership_type (uuid)
);
CREATE TABLE IF NOT EXISTS membership_type (
uuid blob NOT NULL PRIMARY KEY,
type text NOT NULL
);
CREATE TABLE IF NOT EXISTS loan_instances (
loan blob NOT NULL,
instance blob NOT NULL,
PRIMARY KEY (loan, instance),
FOREIGN KEY (loan) REFERENCES loan (uuid),
FOREIGN KEY (instance) REFERENCES instance (uuid)
);