-- +goose Up -- Incidents open and close with their monitor; people tell what is going -- on through a title, a status and updates, public on status pages or -- internal. ALTER TABLE incidents ADD COLUMN title text NOT NULL DEFAULT '' CHECK (length(title) <= 200); -- The status of the latest update, NULL before the first. ALTER TABLE incidents ADD COLUMN status text CHECK (status IN ('investigating', 'identified', 'monitoring', 'resolved')); CREATE TABLE incident_updates ( id uuid PRIMARY KEY DEFAULT gen_random_uuid(), org_id uuid NOT NULL REFERENCES orgs (id) ON DELETE CASCADE, incident_id uuid NOT NULL REFERENCES incidents (id) ON DELETE CASCADE, status text NOT NULL CHECK (status IN ('investigating', 'identified', 'monitoring', 'resolved')), message text NOT NULL CHECK (length(message) BETWEEN 1 AND 5000), public boolean NOT NULL DEFAULT true, author_id uuid REFERENCES users (id) ON DELETE SET NULL, created_at timestamptz NOT NULL DEFAULT now() ); CREATE INDEX incident_updates_incident_idx ON incident_updates (incident_id, created_at); ALTER TABLE incident_updates ENABLE ROW LEVEL SECURITY; ALTER TABLE incident_updates FORCE ROW LEVEL SECURITY; CREATE POLICY incident_updates_tenant ON incident_updates 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 incident_updates; ALTER TABLE incidents DROP COLUMN status; ALTER TABLE incidents DROP COLUMN title;