Public source validation / validate (push) Failing after 3m8s
43 lines
2.3 KiB
SQL
43 lines
2.3 KiB
SQL
CREATE TABLE alert_silences (
|
|
id uuid PRIMARY KEY,
|
|
name text NOT NULL CHECK (char_length(name) BETWEEN 1 AND 160),
|
|
reason text NOT NULL CHECK (char_length(reason) BETWEEN 1 AND 500),
|
|
owner text NOT NULL CHECK (char_length(owner) BETWEEN 1 AND 255),
|
|
matchers jsonb NOT NULL CHECK (jsonb_typeof(matchers) = 'object'),
|
|
starts_at timestamptz NOT NULL,
|
|
expires_at timestamptz NOT NULL CHECK (expires_at > starts_at),
|
|
status text NOT NULL DEFAULT 'active' CHECK (status IN ('active', 'expired', 'revoked')),
|
|
created_by text NOT NULL CHECK (char_length(created_by) BETWEEN 1 AND 255),
|
|
created_at timestamptz NOT NULL DEFAULT now(),
|
|
revoked_by text,
|
|
revoked_at timestamptz,
|
|
expired_at timestamptz,
|
|
revision bigint NOT NULL DEFAULT 1 CHECK (revision > 0),
|
|
CHECK ((status = 'revoked' AND revoked_at IS NOT NULL) OR (status <> 'revoked' AND revoked_at IS NULL)),
|
|
CHECK ((status = 'expired' AND expired_at IS NOT NULL) OR (status <> 'expired' AND expired_at IS NULL))
|
|
);
|
|
|
|
CREATE INDEX alert_silences_active_expiry_idx ON alert_silences (expires_at, id) WHERE status = 'active';
|
|
CREATE INDEX alert_silences_listing_idx ON alert_silences (starts_at DESC, id DESC);
|
|
|
|
CREATE TABLE maintenance_windows (
|
|
id uuid PRIMARY KEY,
|
|
name text NOT NULL CHECK (char_length(name) BETWEEN 1 AND 160),
|
|
reason text NOT NULL CHECK (char_length(reason) BETWEEN 1 AND 500),
|
|
selector jsonb NOT NULL CHECK (jsonb_typeof(selector) = 'object'),
|
|
starts_at timestamptz NOT NULL,
|
|
ends_at timestamptz NOT NULL CHECK (ends_at > starts_at),
|
|
status text NOT NULL DEFAULT 'active' CHECK (status IN ('active', 'expired', 'revoked')),
|
|
created_by text NOT NULL CHECK (char_length(created_by) BETWEEN 1 AND 255),
|
|
created_at timestamptz NOT NULL DEFAULT now(),
|
|
revoked_by text,
|
|
revoked_at timestamptz,
|
|
expired_at timestamptz,
|
|
revision bigint NOT NULL DEFAULT 1 CHECK (revision > 0),
|
|
CHECK ((status = 'revoked' AND revoked_at IS NOT NULL) OR (status <> 'revoked' AND revoked_at IS NULL)),
|
|
CHECK ((status = 'expired' AND expired_at IS NOT NULL) OR (status <> 'expired' AND expired_at IS NULL))
|
|
);
|
|
|
|
CREATE INDEX maintenance_windows_active_expiry_idx ON maintenance_windows (ends_at, id) WHERE status = 'active';
|
|
CREATE INDEX maintenance_windows_listing_idx ON maintenance_windows (starts_at DESC, id DESC);
|