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
|
CREATE TABLE products(
id SERIAL PRIMARY KEY,
name TEXT NOT NULL,
type TEXT NOT NULL,
height INTEGER NOT NULL,
width INTEGER NOT NULL,
depth INTEGER NOT NULL,
max_storage_duration INTERVAL NULL
);
CREATE TYPE PARTNER_TYPE AS ENUM('SUPPLIER', 'ISSUER');
CREATE TABLE partners(
id SERIAL PRIMARY KEY,
name TEXT NOT NULL,
tax_number TEXT NOT NULL,
type PARTNER_TYPE NOT NULL,
address TEXT NOT NULL
);
CREATE TABLE partner_contacts(
id SERIAL PRIMARY KEY,
partner_id INTEGER NOT NULL REFERENCES partners(id),
surname TEXT NOT NULL,
name TEXT NOT NULL,
position TEXT NOT NULL,
phone TEXT NOT NULL,
email TEXT NOT NULL
);
CREATE TABLE storage_slots(
id SERIAL PRIMARY KEY,
location TEXT NOT NULL,
height INTEGER NOT NULL,
width INTEGER NOT NULL,
depth INTEGER NOT NULL
);
CREATE TABLE product_slots(
id SERIAL PRIMARY KEY,
product_id INTEGER NOT NULL REFERENCES products(id),
slot_id INTEGER NOT NULL REFERENCES storage_slots(id),
amount INTEGER NOT NULL CHECK (amount > 0),
status TEXT NOT NULL,
placement_time TIMESTAMP NOT NULL
);
CREATE TYPE OPERATION_TYPE AS ENUM('SUPPLY', 'ISSUE');
CREATE TABLE operations(
id SERIAL PRIMARY KEY,
partner_id INTEGER NOT NULL REFERENCES partners(id),
responsible_id INTEGER NOT NULL REFERENCES partner_contacts(id),
type OPERATION_TYPE NOT NULL,
status TEXT NOT NULL,
date_created TIMESTAMP NOT NULL,
date_finished TIMESTAMP NULL
);
CREATE TABLE operation_products(
id SERIAL PRIMARY KEY,
operation_id INTEGER NOT NULL REFERENCES operations(id),
product_id INTEGER NOT NULL REFERENCES products(id),
amount INTEGER NOT NULL CHECK (amount > 0)
);
|