2021-11-04 22:37:16 +00:00
|
|
|
CREATE TABLE controllers
|
|
|
|
(
|
|
|
|
id INTEGER
|
|
|
|
PRIMARY KEY
|
|
|
|
AUTOINCREMENT
|
|
|
|
NOT NULL,
|
|
|
|
uid VARCHAR(36)
|
|
|
|
NOT NULL
|
|
|
|
UNIQUE,
|
|
|
|
name VARCHAR(128),
|
|
|
|
ip VARCHAR(16),
|
|
|
|
port INTEGER,
|
|
|
|
relay_count INTEGER,
|
|
|
|
active BOOLEAN
|
|
|
|
NOT NULL
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE relays
|
|
|
|
(
|
|
|
|
id INTEGER
|
|
|
|
PRIMARY KEY
|
|
|
|
AUTOINCREMENT
|
|
|
|
NOT NULL,
|
|
|
|
name VARCHAR(128),
|
|
|
|
number INTEGER
|
|
|
|
NOT NULL,
|
|
|
|
controller_id INTEGER
|
|
|
|
NOT NULL
|
|
|
|
REFERENCES controllers (id)
|
|
|
|
ON DELETE CASCADE
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE schedules
|
|
|
|
(
|
|
|
|
id INTEGER
|
|
|
|
PRIMARY KEY
|
|
|
|
AUTOINCREMENT
|
|
|
|
NOT NULL,
|
|
|
|
uid BLOB
|
|
|
|
NOT NULL
|
|
|
|
UNIQUE,
|
|
|
|
name VARCHAR(128)
|
|
|
|
NOT NULL,
|
2021-11-05 15:32:30 +00:00
|
|
|
periods BLOB
|
2021-11-04 22:37:16 +00:00
|
|
|
NOT NULL
|
|
|
|
);
|
2021-11-05 15:32:30 +00:00
|
|
|
INSERT INTO schedules (uid, name, periods) VALUES (x'00', 'off', x'');
|
2021-11-06 13:54:45 +00:00
|
|
|
INSERT INTO schedules (uid, name, periods) VALUES (x'01', 'on', x'00000000');
|
2021-11-04 22:37:16 +00:00
|
|
|
|
|
|
|
CREATE TABLE tags
|
|
|
|
(
|
|
|
|
id INTEGER
|
|
|
|
PRIMARY KEY
|
|
|
|
AUTOINCREMENT
|
|
|
|
NOT NULL,
|
|
|
|
tag VARCHAR(128)
|
|
|
|
NOT NULL
|
|
|
|
UNIQUE
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE junction_tag
|
|
|
|
(
|
|
|
|
id INTEGER
|
|
|
|
PRIMARY KEY
|
|
|
|
AUTOINCREMENT
|
|
|
|
NOT NULL,
|
|
|
|
tag_id INTEGER
|
|
|
|
NOT NULL
|
|
|
|
REFERENCES tags (id)
|
|
|
|
ON DELETE CASCADE,
|
|
|
|
relay_id INTEGER
|
|
|
|
REFERENCES relays (id)
|
|
|
|
ON DELETE CASCADE,
|
|
|
|
schedule_id INTEGER
|
|
|
|
REFERENCES schedules (id)
|
|
|
|
ON DELETE CASCADE
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE junction_relay_schedule
|
|
|
|
(
|
|
|
|
id INTEGER
|
|
|
|
PRIMARY KEY
|
|
|
|
AUTOINCREMENT
|
|
|
|
NOT NULL,
|
|
|
|
weekday SMALLINT
|
|
|
|
NOT NULL,
|
|
|
|
relay_id INTEGER
|
|
|
|
REFERENCES relays (id)
|
|
|
|
ON DELETE CASCADE,
|
|
|
|
schedule_id INTEGER
|
|
|
|
DEFAULT 1
|
|
|
|
REFERENCES schedules (id)
|
|
|
|
ON DELETE SET DEFAULT
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE macros
|
|
|
|
(
|
|
|
|
id INTEGER
|
|
|
|
PRIMARY KEY
|
|
|
|
AUTOINCREMENT
|
|
|
|
NOT NULL,
|
|
|
|
uid VARCHAR(36)
|
|
|
|
NOT NULL
|
|
|
|
UNIQUE,
|
|
|
|
name VARCHAR(128)
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE macro_actions
|
|
|
|
(
|
|
|
|
id INTEGER
|
|
|
|
PRIMARY KEY
|
|
|
|
AUTOINCREMENT
|
|
|
|
NOT NULL,
|
|
|
|
macro_id INTEGER
|
|
|
|
NOT NULL
|
|
|
|
REFERENCES macros (id)
|
|
|
|
ON DELETE CASCADE,
|
|
|
|
relay_id INTEGER
|
|
|
|
REFERENCES relays (id)
|
|
|
|
ON DELETE CASCADE,
|
|
|
|
schedule_id INTEGER
|
|
|
|
REFERENCES schedules (id)
|
|
|
|
ON DELETE CASCADE,
|
|
|
|
weekday SMALLINT
|
|
|
|
NOT NULL
|
|
|
|
);
|