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

59 lines
1.4 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-27 11:04:05 +00:00
state TEXT,
expiry DATETIME,
PRIMARY KEY (state)
);
CREATE TABLE monitors (
slug TEXT,
name TEXT,
schedule TEXT,
script TEXT,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP,
deleted_at DATETIME,
PRIMARY KEY (slug),
CONSTRAINT unique_monitors_name UNIQUE (name)
);
CREATE TABLE worker_groups (
slug TEXT,
name TEXT,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP,
deleted_at DATETIME,
PRIMARY KEY (slug),
CONSTRAINT unique_worker_groups_name UNIQUE (name)
);
CREATE TABLE monitor_worker_groups (
worker_group_slug TEXT,
monitor_slug TEXT,
PRIMARY KEY (worker_group_slug,monitor_slug),
CONSTRAINT fk_monitor_worker_groups_worker_group FOREIGN KEY (worker_group_slug) REFERENCES worker_groups(slug),
CONSTRAINT fk_monitor_worker_groups_monitor FOREIGN KEY (monitor_slug) REFERENCES monitors(slug)
);
2024-02-27 14:43:20 +00:00
CREATE TABLE monitor_histories (
2024-02-27 11:04:05 +00:00
monitor_slug TEXT,
status TEXT,
note TEXT,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (monitor_slug, created_at),
CONSTRAINT fk_monitors_history FOREIGN KEY (monitor_slug) REFERENCES monitors(slug)
);
-- +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;