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
|
|
|
|
2024-05-16 20:15:14 +00:00
|
|
|
CREATE TABLE checks (
|
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-05-23 16:33:30 +00:00
|
|
|
filter TEXT NOT NULL,
|
2024-05-18 20:18:28 +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-05-16 20:15:14 +00:00
|
|
|
CONSTRAINT unique_checks_name UNIQUE (name)
|
2024-02-29 22:42:56 +00:00
|
|
|
) STRICT;
|
2024-05-18 20:18:28 +00:00
|
|
|
-- +migrate StatementBegin
|
|
|
|
CREATE TRIGGER checks_updated_timestamp AFTER UPDATE ON checks BEGIN
|
|
|
|
UPDATE checks SET updated_at = strftime('%Y-%m-%dT%H:%M:%fZ') WHERE id = NEW.id;
|
|
|
|
END;
|
|
|
|
-- +migrate StatementEnd
|
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;
|
2024-05-18 20:18:28 +00:00
|
|
|
-- +migrate StatementBegin
|
|
|
|
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;
|
|
|
|
-- +migrate StatementEnd
|
2024-02-27 11:04:05 +00:00
|
|
|
|
2024-05-16 20:15:14 +00:00
|
|
|
CREATE TABLE check_worker_groups (
|
2024-02-29 22:42:56 +00:00
|
|
|
worker_group_id TEXT NOT NULL,
|
2024-05-16 20:15:14 +00:00
|
|
|
check_id TEXT NOT NULL,
|
2024-02-27 14:55:35 +00:00
|
|
|
|
2024-05-16 20:15:14 +00:00
|
|
|
PRIMARY KEY (worker_group_id,check_id),
|
|
|
|
CONSTRAINT fk_check_worker_groups_worker_group FOREIGN KEY (worker_group_id) REFERENCES worker_groups(id) ON DELETE CASCADE,
|
|
|
|
CONSTRAINT fk_check_worker_groups_check FOREIGN KEY (check_id) REFERENCES checks(id) ON DELETE CASCADE
|
2024-02-29 22:42:56 +00:00
|
|
|
) STRICT;
|
2024-02-27 11:04:05 +00:00
|
|
|
|
2024-05-16 20:15:14 +00:00
|
|
|
|
|
|
|
CREATE TABLE triggers (
|
|
|
|
id TEXT NOT NULL,
|
|
|
|
name TEXT NOT NULL,
|
|
|
|
script TEXT NOT NULL,
|
|
|
|
|
|
|
|
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')),
|
|
|
|
|
|
|
|
PRIMARY KEY (id),
|
|
|
|
CONSTRAINT unique_triggers_name UNIQUE (name)
|
|
|
|
) STRICT;
|
2024-05-18 20:18:28 +00:00
|
|
|
-- +migrate StatementBegin
|
|
|
|
CREATE TRIGGER triggers_updated_timestamp AFTER UPDATE ON triggers BEGIN
|
|
|
|
UPDATE triggers SET updated_at = strftime('%Y-%m-%dT%H:%M:%fZ') WHERE id = NEW.id;
|
|
|
|
END;
|
|
|
|
-- +migrate StatementEnd
|
|
|
|
|
2024-05-23 16:33:30 +00:00
|
|
|
CREATE TABLE targets (
|
|
|
|
id TEXT NOT NULL,
|
|
|
|
name TEXT NOT NULL,
|
|
|
|
"group" TEXT NOT NULL,
|
|
|
|
|
|
|
|
visibility TEXT NOT NULL,
|
|
|
|
state TEXT NOT NULL,
|
|
|
|
|
|
|
|
metadata TEXT NOT NULL,
|
|
|
|
|
|
|
|
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')),
|
|
|
|
|
|
|
|
PRIMARY KEY (id),
|
|
|
|
CONSTRAINT unique_targets_name UNIQUE (name)
|
|
|
|
) STRICT;
|
|
|
|
-- +migrate StatementBegin
|
|
|
|
CREATE TRIGGER targets_updated_timestamp AFTER UPDATE ON targets BEGIN
|
|
|
|
UPDATE targets SET updated_at = strftime('%Y-%m-%dT%H:%M:%fZ') WHERE id = NEW.id;
|
|
|
|
END;
|
|
|
|
-- +migrate StatementEnd
|
|
|
|
|
|
|
|
CREATE TABLE target_histories (
|
2024-05-25 17:52:37 +00:00
|
|
|
target_id TEXT NOT NULL,
|
|
|
|
worker_group_id TEXT NOT NULL,
|
|
|
|
check_id TEXT NOT NULL,
|
2024-05-16 20:15:14 +00:00
|
|
|
|
|
|
|
status TEXT NOT NULL,
|
|
|
|
note TEXT NOT NULL,
|
|
|
|
|
|
|
|
created_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ')),
|
|
|
|
|
2024-05-25 17:52:37 +00:00
|
|
|
PRIMARY KEY (target_id, worker_group_id, check_id, created_at),
|
|
|
|
CONSTRAINT fk_target_histories_target FOREIGN KEY (target_id) REFERENCES targets(id) ON DELETE CASCADE,
|
|
|
|
CONSTRAINT fk_target_histories_worker_group FOREIGN KEY (worker_group_id) REFERENCES worker_groups(id) ON DELETE CASCADE,
|
|
|
|
CONSTRAINT fk_target_histories_check FOREIGN KEY (check_id) REFERENCES checks(id) ON DELETE CASCADE
|
2024-02-29 22:42:56 +00:00
|
|
|
) STRICT;
|
2024-02-27 11:04:05 +00:00
|
|
|
|
|
|
|
-- +migrate Down
|
2024-02-27 14:43:20 +00:00
|
|
|
DROP TABLE oauth2_states;
|
2024-05-16 20:15:14 +00:00
|
|
|
DROP TABLE check_worker_groups;
|
2024-02-27 11:04:05 +00:00
|
|
|
DROP TABLE worker_groups;
|
2024-05-18 20:18:28 +00:00
|
|
|
DROP TRIGGER worker_groups_updated_timestamp;
|
2024-05-16 20:15:14 +00:00
|
|
|
DROP TABLE checks;
|
2024-05-18 20:18:28 +00:00
|
|
|
DROP TRIGGER checks_updated_timestamp;
|
2024-05-16 20:15:14 +00:00
|
|
|
DROP TABLE triggers;
|
2024-05-18 20:18:28 +00:00
|
|
|
DROP TRIGGER triggers_updated_timestamp;
|