zdravko/database/sqlite/migrations/2024-02-27-initial.sql

71 lines
2.1 KiB
MySQL
Raw Normal View History

2024-02-27 11:04:05 +00:00
-- +migrate Up
2024-02-27 14:43:20 +00:00
CREATE TABLE oauth2_states (
2024-02-29 22:42:56 +00:00
state TEXT NOT NULL,
expires_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ')),
2024-02-27 14:55:35 +00:00
2024-02-27 11:04:05 +00:00
PRIMARY KEY (state)
2024-02-29 22:42:56 +00:00
) STRICT;
2024-02-27 11:04:05 +00:00
CREATE TABLE monitors (
2024-02-29 22:42:56 +00:00
id TEXT NOT NULL,
name TEXT NOT NULL,
schedule TEXT NOT NULL,
script TEXT NOT NULL,
2024-02-27 11:04:05 +00:00
2024-02-29 22:42:56 +00:00
created_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ')),
updated_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ')),
2024-02-27 11:04:05 +00:00
2024-02-29 22:42:56 +00:00
PRIMARY KEY (id),
2024-02-27 11:04:05 +00:00
CONSTRAINT unique_monitors_name UNIQUE (name)
2024-02-29 22:42:56 +00:00
) STRICT;
--CREATE TRIGGER monitors_updated_timestamp AFTER UPDATE ON monitors BEGIN
-- update monitors set updated_at = strftime('%Y-%m-%dT%H:%M:%fZ') where id = new.id;
--END;
2024-02-27 11:04:05 +00:00
CREATE TABLE worker_groups (
2024-02-29 22:42:56 +00:00
id TEXT NOT NULL,
name TEXT NOT NULL,
2024-02-27 11:04:05 +00:00
2024-02-29 22:42:56 +00:00
created_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ')),
updated_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ')),
2024-02-27 11:04:05 +00:00
2024-02-29 22:42:56 +00:00
PRIMARY KEY (id),
2024-02-27 11:04:05 +00:00
CONSTRAINT unique_worker_groups_name UNIQUE (name)
2024-02-29 22:42:56 +00:00
) STRICT;
--CREATE TRIGGER worker_groups_updated_timestamp AFTER UPDATE ON worker_groups BEGIN
-- update worker_groups set updated_at = strftime('%Y-%m-%dT%H:%M:%fZ') where id = new.id;
--END;
2024-02-27 11:04:05 +00:00
CREATE TABLE monitor_worker_groups (
2024-02-29 22:42:56 +00:00
worker_group_id TEXT NOT NULL,
monitor_id TEXT NOT NULL,
2024-02-27 14:55:35 +00:00
2024-02-29 22:42:56 +00:00
PRIMARY KEY (worker_group_id,monitor_id),
CONSTRAINT fk_monitor_worker_groups_worker_group FOREIGN KEY (worker_group_id) REFERENCES worker_groups(id),
CONSTRAINT fk_monitor_worker_groups_monitor FOREIGN KEY (monitor_id) REFERENCES monitors(id)
) STRICT;
2024-02-27 11:04:05 +00:00
2024-02-27 14:43:20 +00:00
CREATE TABLE monitor_histories (
2024-02-29 22:42:56 +00:00
monitor_id TEXT NOT NULL,
worker_group_id TEXT NOT NULL,
status TEXT NOT NULL,
note TEXT NOT NULL,
2024-02-27 11:04:05 +00:00
2024-02-29 22:42:56 +00:00
created_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ')),
2024-02-27 11:04:05 +00:00
2024-02-29 22:42:56 +00:00
PRIMARY KEY (monitor_id, worker_group_id, created_at),
CONSTRAINT fk_monitor_histories_monitor FOREIGN KEY (monitor_id) REFERENCES monitors(id),
CONSTRAINT fk_monitor_histories_worker_group FOREIGN KEY (worker_group_id) REFERENCES worker_groups(id)
) STRICT;
2024-02-27 11:04:05 +00:00
-- +migrate Down
2024-02-27 14:43:20 +00:00
DROP TABLE oauth2_states;
2024-02-27 11:04:05 +00:00
DROP TABLE monitor_worker_groups;
DROP TABLE worker_groups;
DROP TABLE monitor_histories;
DROP TABLE monitors;