-
Notifications
You must be signed in to change notification settings - Fork 0
/
init_debug.sql
147 lines (127 loc) · 3.89 KB
/
init_debug.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
CREATE TABLE IF NOT EXISTS vgroup (
id serial PRIMARY KEY,
name VARCHAR NOT NULL
);
CREATE TABLE IF NOT EXISTS taskset (
id serial PRIMARY KEY,
vgroup_id integer NOT NULL references vgroup(id),
name VARCHAR NOT NULL
);
CREATE TABLE IF NOT EXISTS vuser (
id serial PRIMARY KEY,
login VARCHAR NOT NULL,
passwd VARCHAR NOT NULL,
created_at TIMESTAMPTZ NOT NULL,
picutre bytea
);
CREATE TYPE token_type AS ENUM (
'normal',
'device',
'display'
);
CREATE TABLE IF NOT EXISTS tokens (
id SERIAL PRIMARY KEY,
vuser_id integer REFERENCES vuser(id),
token TEXT NOT NULL,
token_t token_type NOT NULL
);
CREATE TABLE IF NOT EXISTS pairing_codes (
pairing_code VARCHAR PRIMARY KEY,
expiration_date TIMESTAMPTZ NOT NULL,
token_id int REFERENCES tokens(id)
);
CREATE TYPE role_type AS ENUM (
'guest',
'member',
'admin'
);
CREATE TABLE IF NOT EXISTS user_groups (
vuser_id integer NOT NULL REFERENCES vuser(id),
vgroup_id integer NOT NULL REFERENCES vgroup(id),
role role_type NOT NULL,
PRIMARY KEY (vuser_id, vgroup_id)
);
CREATE TABLE IF NOT EXISTS groups_invitations (
id serial PRIMARY KEY,
vgroup_id integer NOT NULL REFERENCES vgroup(id),
invitation_code VARCHAR NOT NULL,
expiration_date TIMESTAMPTZ NOT NULL
);
CREATE TABLE IF NOT EXISTS task (
id serial PRIMARY KEY,
title VARCHAR NOT NULL,
content VARCHAR NOT NULL,
completed BOOLEAN NOT NULL,
taskset_id INTEGER NOT NULL REFERENCES taskset(id),
last_update TIMESTAMPTZ DEFAULT NOW() NOT NULL
);
CREATE TABLE IF NOT EXISTS task_assign (
task_id INTEGER NOT NULL REFERENCES task(id),
user_assign INTEGER NOT NULL REFERENCES vuser(id),
assign_time TIMESTAMPTZ NOT NULL,
PRIMARY KEY (task_id, user_assign)
);
CREATE TYPE device_type AS ENUM (
'thermometer',
'other'
);
CREATE TABLE IF NOT EXISTS device (
id serial PRIMARY KEY,
vgroup_id INTEGER NOT NULL REFERENCES vgroup(id),
name VARCHAR NOT NULL,
dev_t device_type NOT NULL,
token Text NOT NULL,
initialized BOOLEAN NOT NULL,
last_updated TIMESTAMPTZ DEFAULT NOW() NOT NULL
);
CREATE TABLE IF NOT EXISTS device_measurements (
device_id int REFERENCES device(id),
measurement_label VARCHAR NOT NULL,
measurement_value REAL NOT NULL,
measurement_time TIMESTAMPTZ DEFAULT NOW() NOT NULL,
PRIMARY KEY (device_id, measurement_time)
);
CREATE TABLE IF NOT EXISTS thermometer (
device_id int PRIMARY KEY REFERENCES device(id),
last_temp real,
last_humidity real
);
INSERT INTO vgroup (name)
VALUES
( 'Friends' ),
( 'Family' );
INSERT INTO taskset (vgroup_id, name)
VALUES
( 1, 'Places to visit' ),
( 1, 'Party members' ),
( 2, 'Shopping list' );
INSERT INTO vuser (login, passwd, created_at, picutre)
VALUES
( 'Wiktor', '$2b$04$bD9NepMRGZGD2inNzenRNuRd01ZxjMjikNtQSvXgHseGfadszNq8e', NOW(), NULL ),
( 'Marek', '$2b$04$bD9NepMRGZGD2inNzenRNuRd01ZxjMjikNtQSvXgHseGfadszNq8e', NOW(), NULL ),
( 'Magda', '$2b$04$bD9NepMRGZGD2inNzenRNuRd01ZxjMjikNtQSvXgHseGfadszNq8e', NOW(), NULL ),
( 'Krzysiek', '$2b$04$bD9NepMRGZGD2inNzenRNuRd01ZxjMjikNtQSvXgHseGfadszNq8e', NOW(), NULL );
INSERT INTO user_groups (vuser_id, vgroup_id, role)
VALUES
( 1, 1, 'member' ),
( 2, 2, 'member' ),
( 2, 1, 'member' ),
( 3, 1, 'member' ),
( 4, 1, 'member' );
INSERT INTO task (title, content, taskset_id, completed)
VALUES
( 'Pętla Kowale', 'Odwiedzić tę niesamowitą pętlę tramwajową', 1, false),
( 'Kładka Muchobór', 'Nowa kładka, a jeszcze tam nie byłem', 1, false),
( 'Park Tołpy', 'Po prostu park', 1, true ),
( 'Antoni Suligowski', '', 2, false ),
( 'Jacek Arbaz', '', 2, false ),
( 'Bartek Młotek', 'Przynieś ciastka', 2, false ),
( 'Tosia Nowak', 'Nocuje!', 2, true ),
( 'Masło z solą', 'Lixdark', 3, true ),
( 'Łosoś', 'Do ogłupiania miast', 3, true ),
( 'Chlebek', 'Po prostu', 3, false);
INSERT INTO task_assign (task_id, user_assign, assign_time)
VALUES
( 1, 1, NOW()),
( 1, 2, NOW()),
( 2, 4, NOW());