2020-08-29 20:58:02 +00:00
|
|
|
-- base migration
|
|
|
|
|
|
|
|
CREATE TABLE controllers
|
2019-08-25 23:02:49 +00:00
|
|
|
(
|
2020-05-05 09:42:02 +00:00
|
|
|
id INTEGER
|
|
|
|
PRIMARY KEY
|
|
|
|
AUTOINCREMENT,
|
|
|
|
uid BLOB
|
|
|
|
NOT NULL
|
|
|
|
UNIQUE,
|
2019-08-25 23:02:49 +00:00
|
|
|
name VARCHAR(128),
|
|
|
|
ip VARCHAR(16),
|
|
|
|
port INTEGER,
|
|
|
|
relay_count INTEGER,
|
2020-04-23 15:00:12 +00:00
|
|
|
active BOOLEAN
|
|
|
|
NOT NULL
|
2019-08-25 23:02:49 +00:00
|
|
|
);
|
|
|
|
|
2020-08-29 20:58:02 +00:00
|
|
|
CREATE TABLE relays
|
2019-08-25 23:02:49 +00:00
|
|
|
(
|
2020-04-23 15:00:12 +00:00
|
|
|
id INTEGER
|
|
|
|
PRIMARY KEY
|
|
|
|
AUTOINCREMENT,
|
|
|
|
name VARCHAR(128),
|
|
|
|
number INTEGER
|
|
|
|
NOT NULL,
|
2020-05-05 09:42:02 +00:00
|
|
|
controller_id INTEGER
|
2020-04-23 15:00:12 +00:00
|
|
|
NOT NULL
|
2020-04-27 21:33:56 +00:00
|
|
|
REFERENCES controllers (id)
|
2020-05-28 00:12:39 +00:00
|
|
|
ON DELETE CASCADE
|
2019-08-25 23:02:49 +00:00
|
|
|
);
|
|
|
|
|
2020-08-29 20:58:02 +00:00
|
|
|
CREATE TABLE schedules
|
2019-08-25 23:02:49 +00:00
|
|
|
(
|
2020-04-19 00:44:35 +00:00
|
|
|
id INTEGER
|
2020-04-23 15:00:12 +00:00
|
|
|
PRIMARY KEY
|
|
|
|
AUTOINCREMENT,
|
2020-05-05 09:42:02 +00:00
|
|
|
uid BLOB
|
2020-04-23 15:00:12 +00:00
|
|
|
NOT NULL
|
|
|
|
UNIQUE,
|
2019-08-25 23:02:49 +00:00
|
|
|
name VARCHAR(128),
|
2020-04-27 21:33:56 +00:00
|
|
|
periods BLOB
|
|
|
|
);
|
|
|
|
|
2020-08-29 20:58:02 +00:00
|
|
|
CREATE TABLE tags
|
2020-04-28 19:50:19 +00:00
|
|
|
(
|
2020-04-27 21:33:56 +00:00
|
|
|
id INTEGER
|
|
|
|
PRIMARY KEY
|
|
|
|
AUTOINCREMENT,
|
|
|
|
tag VARCHAR(128)
|
|
|
|
NOT NULL
|
|
|
|
UNIQUE
|
2020-04-28 19:50:19 +00:00
|
|
|
);
|
2020-04-27 21:33:56 +00:00
|
|
|
|
2020-08-29 20:58:02 +00:00
|
|
|
CREATE TABLE junction_tag
|
2020-04-27 21:33:56 +00:00
|
|
|
(
|
|
|
|
tag_id INTEGER
|
|
|
|
NOT NULL
|
2020-05-28 00:12:39 +00:00
|
|
|
REFERENCES tags (id)
|
|
|
|
ON DELETE CASCADE,
|
2020-04-27 21:33:56 +00:00
|
|
|
relay_id INTEGER
|
2020-05-28 00:12:39 +00:00
|
|
|
REFERENCES relays (id)
|
|
|
|
ON DELETE CASCADE,
|
2020-04-27 21:33:56 +00:00
|
|
|
schedule_id INTEGER
|
|
|
|
REFERENCES schedules (id)
|
2020-05-28 00:12:39 +00:00
|
|
|
ON DELETE CASCADE
|
2020-04-27 21:33:56 +00:00
|
|
|
);
|
|
|
|
|
2020-08-29 20:58:02 +00:00
|
|
|
CREATE TABLE junction_relay_schedule
|
2020-04-27 21:33:56 +00:00
|
|
|
(
|
|
|
|
weekday SMALLINT
|
|
|
|
NOT NULL,
|
|
|
|
relay_id INTEGER
|
2020-05-28 00:12:39 +00:00
|
|
|
REFERENCES relays (id)
|
|
|
|
ON DELETE CASCADE,
|
2020-04-27 21:33:56 +00:00
|
|
|
schedule_id INTEGER
|
2020-05-28 00:12:39 +00:00
|
|
|
DEFAULT 1
|
2020-04-27 21:33:56 +00:00
|
|
|
REFERENCES schedules (id)
|
2020-05-28 00:12:39 +00:00
|
|
|
ON DELETE SET DEFAULT
|
2019-08-25 23:02:49 +00:00
|
|
|
);
|
2019-09-08 21:24:31 +00:00
|
|
|
|
2020-04-19 00:44:35 +00:00
|
|
|
INSERT INTO schedules (uid, name, periods) VALUES (x'6f666600000000000000000000000000', 'off', x'00');
|
2024-04-16 14:31:18 +00:00
|
|
|
INSERT INTO schedules (uid, name, periods) VALUES (x'6f6e0000000000000000000000000000', 'on', x'010000000000');
|