add: foreign key support in database

add: more tests
fix: bad tag handling when finding 0 in column
This commit is contained in:
Tobias Reisinger 2020-05-28 02:12:39 +02:00
parent 7f3182ee96
commit 1475f605aa
14 changed files with 214 additions and 276 deletions

View file

@ -31,6 +31,7 @@ create table relays
controller_id INTEGER
NOT NULL
REFERENCES controllers (id)
ON DELETE CASCADE
);
create table schedules
@ -59,11 +60,14 @@ create table junction_tag
(
tag_id INTEGER
NOT NULL
REFERENCES tags (id),
REFERENCES tags (id)
ON DELETE CASCADE,
relay_id INTEGER
REFERENCES relays (id),
REFERENCES relays (id)
ON DELETE CASCADE,
schedule_id INTEGER
REFERENCES schedules (id)
ON DELETE CASCADE
);
create table junction_relay_schedule
@ -71,11 +75,12 @@ create table junction_relay_schedule
weekday SMALLINT
NOT NULL,
relay_id INTEGER
NOT NULL
REFERENCES relays (id),
REFERENCES relays (id)
ON DELETE CASCADE,
schedule_id INTEGER
NOT NULL
DEFAULT 1
REFERENCES schedules (id)
ON DELETE SET DEFAULT
);
INSERT INTO schedules (uid, name, periods) VALUES (x'6f666600000000000000000000000000', 'off', x'00');