58 lines
2.7 KiB
SQL
58 lines
2.7 KiB
SQL
-- +goose Up
|
|
CREATE SCHEMA proposals;
|
|
|
|
-- A proposal is a change Archie drafts with its evidence: a root-cause fix, a
|
|
-- new trigger and workflow, a workflow change or a raised ceiling. change holds
|
|
-- what publishing it writes, and base_version the version of the target it was
|
|
-- drafted against, so a target changed since is detected. A policy or ceiling
|
|
-- change needs a person with authority, and any other change needs the owner.
|
|
-- A rejection keeps its reason so the next proposal can take it into account.
|
|
-- prompted_by lists the events that led to it, which a published trigger runs
|
|
-- for.
|
|
CREATE TABLE proposals.proposals (
|
|
id uuid PRIMARY KEY,
|
|
org_id text NOT NULL,
|
|
kind text NOT NULL CHECK (kind IN ('root_cause_fix', 'trigger', 'workflow_change', 'ceiling_raise', 'policy_change')),
|
|
state text NOT NULL CHECK (state IN ('pending', 'approved', 'rejected', 'published', 'superseded', 'withdrawn')),
|
|
needs text NOT NULL CHECK (needs IN ('owner', 'authority')),
|
|
title text NOT NULL,
|
|
summary text NOT NULL,
|
|
evidence jsonb NOT NULL,
|
|
change jsonb NOT NULL,
|
|
target_kind text NOT NULL,
|
|
target_id text NOT NULL DEFAULT '',
|
|
base_version integer,
|
|
prompted_by uuid[] NOT NULL DEFAULT '{}',
|
|
origin_run_id uuid,
|
|
proposed_by_id text NOT NULL,
|
|
created_at timestamptz NOT NULL DEFAULT now(),
|
|
answered_by_id text,
|
|
answered_at timestamptz,
|
|
answer_reason text NOT NULL DEFAULT '',
|
|
published_at timestamptz,
|
|
CHECK ((answered_at IS NULL) = (answered_by_id IS NULL)),
|
|
CHECK ((state IN ('pending', 'withdrawn', 'superseded')) OR (answered_at IS NOT NULL)),
|
|
CHECK ((state = 'published') = (published_at IS NOT NULL))
|
|
);
|
|
CREATE INDEX proposals_by_state ON proposals.proposals (org_id, state, created_at DESC);
|
|
CREATE INDEX proposals_by_target ON proposals.proposals (org_id, target_kind, target_id, created_at DESC);
|
|
|
|
-- The actions a proposal will take when it is approved, in order. Each is
|
|
-- judged when the proposal is made and shown with it, and approving the
|
|
-- proposal approves them. digest binds the approval to the exact action.
|
|
CREATE TABLE proposals.actions (
|
|
proposal_id uuid NOT NULL REFERENCES proposals.proposals (id) ON DELETE CASCADE,
|
|
seq integer NOT NULL,
|
|
installation_id uuid NOT NULL,
|
|
action text NOT NULL,
|
|
target_kind text NOT NULL,
|
|
target_id text NOT NULL,
|
|
input jsonb NOT NULL,
|
|
digest text NOT NULL,
|
|
decision_id uuid NOT NULL,
|
|
PRIMARY KEY (proposal_id, seq)
|
|
);
|
|
|
|
-- +goose Down
|
|
DROP SCHEMA proposals CASCADE;
|