common/migrations/20231120000000_init.up.sql

160 lines
2.5 KiB
MySQL
Raw Normal View History

2021-11-04 22:37:16 +00:00
CREATE TABLE controllers
(
2022-04-02 23:35:51 +00:00
id
INTEGER
PRIMARY KEY
AUTOINCREMENT
NOT NULL,
uid
2023-11-24 21:45:44 +00:00
BLOB
2022-04-02 23:35:51 +00:00
NOT NULL
UNIQUE,
name
VARCHAR(128)
NOT NULL,
relay_count
2023-11-24 21:45:44 +00:00
INTEGER
NOT NULL,
2022-04-02 23:35:51 +00:00
active
BOOLEAN
NOT NULL
2021-11-04 22:37:16 +00:00
);
CREATE TABLE relays
(
2022-04-02 23:35:51 +00:00
id
INTEGER
PRIMARY KEY
AUTOINCREMENT
NOT NULL,
name
VARCHAR(128)
NOT NULL,
number
INTEGER
NOT NULL,
controller_id
INTEGER
NOT NULL
REFERENCES controllers (id)
ON DELETE CASCADE
2021-11-04 22:37:16 +00:00
);
CREATE TABLE schedules
(
2022-04-02 23:35:51 +00:00
id
INTEGER
PRIMARY KEY
AUTOINCREMENT
NOT NULL,
uid
BLOB
NOT NULL
UNIQUE,
name
VARCHAR(128)
NOT NULL,
periods
BLOB
NOT NULL
2021-11-04 22:37:16 +00:00
);
CREATE TABLE tags
(
2022-04-02 23:35:51 +00:00
id
INTEGER
PRIMARY KEY
AUTOINCREMENT
NOT NULL,
tag
VARCHAR(128)
NOT NULL
UNIQUE
2021-11-04 22:37:16 +00:00
);
CREATE TABLE junction_tag
(
2022-04-02 23:35:51 +00:00
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
2021-11-04 22:37:16 +00:00
);
CREATE TABLE junction_relay_schedule
(
2022-04-02 23:35:51 +00:00
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
2021-11-04 22:37:16 +00:00
);
CREATE TABLE macros
(
2022-04-02 23:35:51 +00:00
id
INTEGER
PRIMARY KEY
AUTOINCREMENT
NOT NULL,
uid
VARCHAR(36)
NOT NULL
UNIQUE,
name
VARCHAR(128)
NOT NULL
2021-11-04 22:37:16 +00:00
);
CREATE TABLE macro_actions
(
2022-04-02 23:35:51 +00:00
id
INTEGER
PRIMARY KEY
AUTOINCREMENT
NOT NULL,
macro_id
INTEGER
NOT NULL
REFERENCES macros (id)
ON DELETE CASCADE,
relay_id
INTEGER
NOT NULL
REFERENCES relays (id)
ON DELETE CASCADE,
schedule_id
INTEGER
NOT NULL
REFERENCES schedules (id)
ON DELETE CASCADE,
weekday
SMALLINT
NOT NULL
2021-11-04 22:37:16 +00:00
);