-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit_test.sql
More file actions
49 lines (43 loc) · 1.67 KB
/
init_test.sql
File metadata and controls
49 lines (43 loc) · 1.67 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
CREATE TABLE IF NOT EXISTS sensors (
id bigserial PRIMARY KEY,
name text NOT NULL,
group_id bigint,
x numeric,
y numeric,
z numeric,
value bigint,
format text
);
CREATE INDEX IF NOT EXISTS idx_member ON sensors (name, group_id);
INSERT INTO sensors (name, group_id, x, y, z, value, format)
VALUES
('Group1', 1, 10.0, 20.0, 30.0, 100, 'Celsius'),
('Group1', 2, 10.0, 20.0, 30.0, 100, 'Celsius'),
('Group2', 1, 15.0, 25.0, 35.0, 150, 'Celsius'),
('Group2', 2, 10.0, 20.0, 30.0, 100, 'Celsius');
CREATE TABLE IF NOT EXISTS sensor_data (
id bigserial PRIMARY KEY,
created_at timestamptz,
updated_at timestamptz,
deleted_at timestamptz,
transparency bigint,
value numeric,
scale text,
species text,
sensor_id bigint NOT NULL,
FOREIGN KEY (sensor_id) REFERENCES sensors(id) ON UPDATE CASCADE ON DELETE SET NULL
);
INSERT INTO sensor_data (created_at, updated_at, transparency, value, scale, species, sensor_id)
VALUES
(CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, 50, 200.0, 'Scale1', '[{"Name":"Fish1","Count":5},{"Name":"Fish2","Count":10}]', 1),
(CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, 75, 300.0, 'Scale2', '[{"Name":"Fish3","Count":2},{"Name":"Fish4","Count":3}]', 2),
(CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, 50, 200.0, 'Scale1', '[{"Name":"Fish5","Count":5},{"Name":"Fish6","Count":10}]', 3),
(CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, 75, 300.0, 'Scale2', '[{"Name":"Fish7","Count":5},{"Name":"Fish8","Count":1}]', 4);
CREATE TABLE IF NOT EXISTS sensor_groups (
name text PRIMARY KEY,
sensor_count bigint
);
INSERT INTO sensor_groups (name, sensor_count)
VALUES
('Group1', 2),
('Group2', 0);