feat(store): store maintenance windows for monitors and groups
Groups cover their subgroups; a recursive query resolves which windows apply to a monitor. Status page descriptions may be longer now that they are Markdown. Refs #71 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
This commit is contained in:
1 parent
c5f7005829
commit
259b3b8e05
6 files changed
+458
No files matched your search
@@ -0,0 +1,49 @@
|
||||
-- +goose Up
|
||||
-- Planned maintenance. starts_at is the first occurrence; repeats keep its
|
||||
-- wall-clock time in time_zone (see package maintenance).
|
||||
CREATE TABLE maintenance_windows (
|
||||
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
org_id uuid NOT NULL REFERENCES orgs (id) ON DELETE CASCADE,
|
||||
title text NOT NULL CHECK (length(title) BETWEEN 1 AND 200),
|
||||
description text NOT NULL DEFAULT '' CHECK (length(description) <= 20000),
|
||||
starts_at timestamptz NOT NULL,
|
||||
duration_seconds integer NOT NULL CHECK (duration_seconds BETWEEN 60 AND 2592000),
|
||||
time_zone text NOT NULL,
|
||||
recurrence text NOT NULL CHECK (recurrence IN ('none', 'daily', 'weekly', 'monthly')),
|
||||
every integer NOT NULL DEFAULT 1 CHECK (every BETWEEN 1 AND 365),
|
||||
weekdays smallint[] NOT NULL DEFAULT '{}',
|
||||
until timestamptz,
|
||||
created_at timestamptz NOT NULL DEFAULT now(),
|
||||
updated_at timestamptz NOT NULL DEFAULT now(),
|
||||
UNIQUE (id, org_id)
|
||||
);
|
||||
|
||||
-- A target is a monitor or a group; a group covers its subgroups.
|
||||
CREATE TABLE maintenance_targets (
|
||||
window_id uuid NOT NULL,
|
||||
org_id uuid NOT NULL,
|
||||
monitor_id uuid,
|
||||
group_id uuid,
|
||||
CHECK ((monitor_id IS NULL) <> (group_id IS NULL)),
|
||||
FOREIGN KEY (window_id, org_id) REFERENCES maintenance_windows (id, org_id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (monitor_id, org_id) REFERENCES monitors (id, org_id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (group_id, org_id) REFERENCES monitor_groups (id, org_id) ON DELETE CASCADE,
|
||||
UNIQUE NULLS NOT DISTINCT (window_id, monitor_id, group_id)
|
||||
);
|
||||
CREATE INDEX maintenance_targets_monitor_idx ON maintenance_targets (monitor_id) WHERE monitor_id IS NOT NULL;
|
||||
CREATE INDEX maintenance_targets_group_idx ON maintenance_targets (group_id) WHERE group_id IS NOT NULL;
|
||||
|
||||
ALTER TABLE maintenance_windows ENABLE ROW LEVEL SECURITY;
|
||||
ALTER TABLE maintenance_windows FORCE ROW LEVEL SECURITY;
|
||||
CREATE POLICY maintenance_windows_tenant ON maintenance_windows FOR ALL
|
||||
USING (app_scope_system() OR org_id = app_org_id())
|
||||
WITH CHECK (app_scope_system() OR org_id = app_org_id());
|
||||
ALTER TABLE maintenance_targets ENABLE ROW LEVEL SECURITY;
|
||||
ALTER TABLE maintenance_targets FORCE ROW LEVEL SECURITY;
|
||||
CREATE POLICY maintenance_targets_tenant ON maintenance_targets FOR ALL
|
||||
USING (app_scope_system() OR org_id = app_org_id())
|
||||
WITH CHECK (app_scope_system() OR org_id = app_org_id());
|
||||
|
||||
-- +goose Down
|
||||
DROP TABLE maintenance_targets;
|
||||
DROP TABLE maintenance_windows;
|
||||
@@ -0,0 +1,8 @@
|
||||
-- +goose Up
|
||||
-- Descriptions are Markdown now, which needs more room than plain text.
|
||||
ALTER TABLE status_pages DROP CONSTRAINT status_pages_description_check;
|
||||
ALTER TABLE status_pages ADD CONSTRAINT status_pages_description_check CHECK (length(description) <= 10000);
|
||||
|
||||
-- +goose Down
|
||||
ALTER TABLE status_pages DROP CONSTRAINT status_pages_description_check;
|
||||
ALTER TABLE status_pages ADD CONSTRAINT status_pages_description_check CHECK (length(description) <= 2000);
|
||||
Reference in new issue
Block a user