-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabaseGuide.txt
More file actions
54 lines (51 loc) · 1.33 KB
/
databaseGuide.txt
File metadata and controls
54 lines (51 loc) · 1.33 KB
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
users:
CREATE TABLE users (
id serial PRIMARY KEY,
username varchar(255),
email varchar (255),
password varchar(255),
created_at timestamp with time zone NOT NULL,
updated_at timestamp with time zone NOT NULL
);
cylinders:
CREATE TABLE cylinders (
id serial PRIMARY KEY,
name varchar(255),
weight_device_id varchar(255),
pressure_device_id varchar(255),
created_at timestamp with time zone NOT NULL,
updated_at timestamp with time zone NOT NULL
);
cylinders_records:
CREATE TABLE cylinders_records (
date timestamp with time zone NOT NULL,
device_id varchar(255) NOT NULL,
type varchar(255) NOT NULL,
value float NOT NULL,
cylinder_id int NOT NULL
);
ALTER TABLE cylinders_records
ADD CONSTRAINT fk_cylinder_id
FOREIGN KEY (cylinder_id)
REFERENCES cylinders (id)
ON UPDATE CASCADE
ON DELETE CASCADE;
users_cylinders:
CREATE TABLE users_cylinders (
created_at timestamp with time zone NOT NULL,
updated_at timestamp with time zone NOT NULL,
user_id int NOT NULL,
cylinder_id int NOT NULL
);
ALTER TABLE users_cylinders
ADD CONSTRAINT fk_user_id
FOREIGN KEY (user_id)
REFERENCES users(id)
ON UPDATE CASCADE
ON DELETE CASCADE;
ALTER TABLE users_cylinders
ADD CONSTRAINT fk_cylinder_id
FOREIGN KEY (cylinder_id)
REFERENCES cylinders(id)
ON UPDATE CASCADE
ON DELETE CASCADE;