fix: relay-schedules now as database junction

This commit is contained in:
Tobias Reisinger 2020-04-27 23:33:56 +02:00
parent 5b508b3735
commit 5bc849ab40
7 changed files with 188 additions and 47 deletions

View file

@ -14,7 +14,6 @@ create table controllers
ip VARCHAR(16),
port INTEGER,
relay_count INTEGER,
tag varchar(64),
active BOOLEAN
NOT NULL
);
@ -29,10 +28,7 @@ create table relays
NOT NULL,
controller_id VARCHAR(33)
NOT NULL
REFERENCES CONTROLLERS (ID),
schedules_ids INTEGER
REFERENCES SCHEDULES (ID),
tag vARCHAR(64)
REFERENCES controllers (id)
);
create table schedules
@ -44,8 +40,39 @@ create table schedules
NOT NULL
UNIQUE,
name VARCHAR(128),
periods BLOB,
tag vARCHAR(64)
periods BLOB
);
create table tags
id INTEGER
PRIMARY KEY
AUTOINCREMENT,
tag VARCHAR(128)
NOT NULL
UNIQUE
)
create table junction_tag
(
tag_id INTEGER
NOT NULL
REFERENCES tags (id),
relay_id INTEGER
REFERENCES relays (id),
schedule_id INTEGER
REFERENCES schedules (id)
);
create table junction_relay_schedule
(
weekday SMALLINT
NOT NULL,
relay_id INTEGER
NOT NULL
REFERENCES relays (id),
schedule_id INTEGER
NOT NULL
REFERENCES schedules (id)
);
INSERT INTO schedules (uid, name, periods) VALUES (x'6f666600000000000000000000000000', 'off', x'00');