-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init-db.sql
75 lines (63 loc) · 2.17 KB
/
init-db.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
--
-- Create Database
--
create table plant_dbs
(
id bigserial not null
constraint plant_dbs_pkey
primary key,
name text
);
alter table plant_dbs owner to postgres;
create table grow_config_dbs
(
id bigserial not null
constraint grow_config_dbs_pkey
primary key,
titel text,
description text,
germination_days bigint,
growing_days bigint,
plant_id bigint
constraint grow_config_dbs_plant_id_fkey
references plant_dbs
);
alter table grow_config_dbs owner to postgres;
create table tray_config_dbs
(
id bigserial not null
constraint tray_config_dbs_pkey
primary key,
plant_id bigint
constraint tray_config_dbs_plant_id_fkey
references plant_dbs,
started_at timestamp with time zone
);
alter table tray_config_dbs owner to postgres;
create table tray_dbs
(
id bigserial not null
constraint tray_dbs_pkey
primary key,
slot bigint,
is_active boolean,
grow_config_id bigint
constraint tray_dbs_grow_config_id_fkey
references grow_config_dbs,
tray_config_id bigint
constraint tray_dbs_tray_config_id_fkey
references tray_config_dbs
);
alter table tray_dbs owner to postgres;
--
-- Insert Data --
--
INSERT INTO public.plant_dbs (id, name) VALUES (1, 'Alfalfa');
INSERT INTO public.plant_dbs (id, name) VALUES (2, 'Mungo');
INSERT INTO public.plant_dbs (id, name) VALUES (3, 'Rucola');
INSERT INTO public.grow_config_dbs (id, titel, description, germination_days, growing_days, plant_id) VALUES (1, 'Alfalfa Config 123', 'Alfalfa Config 1', 3, 5, 1);
INSERT INTO public.tray_config_dbs (id, plant_id, started_at) VALUES (1, 1, '2021-01-14 11:45:19.721000');
INSERT INTO public.tray_config_dbs (id, plant_id, started_at) VALUES (2, 2, '2021-01-14 12:01:13.169474');
INSERT INTO public.tray_config_dbs (id, plant_id, started_at) VALUES (3, 1, '2021-01-01 23:00:00.000000');
INSERT INTO public.tray_dbs (id, slot, is_active, grow_config_id, tray_config_id) VALUES (1, 1, true, 1, 1);
INSERT INTO public.tray_dbs (id, slot, is_active, grow_config_id, tray_config_id) VALUES (2, 12, null, null, null);