Packages are accepted once by the instance. Installations configure them at the instance, an organisation or a person; bindings and credentials resolve the person's, then their organisation's, then the instance's. Decisions, approval requests and held chat actions record the installation and scope that acted. The dashboard lists packages separately from installations, shows every installation's scope, and creates, edits and disables installations at their scope.
101 lines
4.3 KiB
SQL
101 lines
4.3 KiB
SQL
-- +goose Up
|
|
CREATE SCHEMA judgement;
|
|
|
|
-- A decision is the judgement of one concrete action, with every verdict in
|
|
-- its body. key identifies the attempt to run the action, so a replayed step
|
|
-- reads the existing decision instead of judging the action again. connector, action, target_kind and environment
|
|
-- identify the action type the decision counts towards.
|
|
CREATE TABLE judgement.decisions (
|
|
id uuid PRIMARY KEY,
|
|
org_id text NOT NULL,
|
|
run_id uuid NOT NULL,
|
|
key text NOT NULL,
|
|
connector text NOT NULL,
|
|
-- installation_id and installation_scope name the installation the action
|
|
-- resolved to, so an audit can say which configuration acted and whose it was.
|
|
installation_id uuid NOT NULL,
|
|
installation_scope text NOT NULL CHECK (installation_scope IN ('instance', 'org', 'person')),
|
|
action text NOT NULL,
|
|
target_kind text NOT NULL,
|
|
environment text NOT NULL,
|
|
level text NOT NULL CHECK (level IN ('act_quietly', 'act_and_tell', 'propose_and_wait', 'escalate', 'never')),
|
|
body json NOT NULL,
|
|
created_at timestamptz NOT NULL DEFAULT now(),
|
|
dry boolean NOT NULL DEFAULT false,
|
|
UNIQUE (org_id, key)
|
|
);
|
|
CREATE INDEX decisions_by_run ON judgement.decisions (org_id, run_id, created_at);
|
|
CREATE INDEX decisions_by_class ON judgement.decisions (org_id, connector, action, target_kind, environment, created_at);
|
|
|
|
CREATE TABLE judgement.action_types (
|
|
id uuid PRIMARY KEY,
|
|
org_id text NOT NULL,
|
|
connector text NOT NULL,
|
|
action text NOT NULL,
|
|
target_kind text NOT NULL,
|
|
environment text NOT NULL,
|
|
read_only boolean NOT NULL,
|
|
level text NOT NULL CHECK (level IN ('act_quietly', 'act_and_tell', 'propose_and_wait', 'escalate', 'never')),
|
|
created_at timestamptz NOT NULL DEFAULT now(),
|
|
reset_at timestamptz,
|
|
tightened_at timestamptz,
|
|
tightened_because text,
|
|
UNIQUE (org_id, connector, action, target_kind, environment)
|
|
);
|
|
|
|
CREATE TABLE judgement.action_type_resets (
|
|
id uuid PRIMARY KEY,
|
|
org_id text NOT NULL,
|
|
action_type_id uuid NOT NULL REFERENCES judgement.action_types (id),
|
|
from_level text NOT NULL,
|
|
to_level text NOT NULL,
|
|
by text NOT NULL,
|
|
at timestamptz NOT NULL DEFAULT now()
|
|
);
|
|
CREATE INDEX action_type_resets_by_action_type ON judgement.action_type_resets (action_type_id, at);
|
|
|
|
CREATE TABLE judgement.action_type_approvals (
|
|
id uuid PRIMARY KEY,
|
|
org_id text NOT NULL,
|
|
action_type_id uuid NOT NULL REFERENCES judgement.action_types (id),
|
|
decision_id uuid NOT NULL UNIQUE,
|
|
by text NOT NULL,
|
|
by_id text NOT NULL DEFAULT '',
|
|
at timestamptz NOT NULL,
|
|
counted boolean NOT NULL DEFAULT true
|
|
);
|
|
CREATE INDEX action_type_approvals_counted ON judgement.action_type_approvals (action_type_id, at) WHERE counted;
|
|
|
|
CREATE TABLE judgement.autonomy_proposals (
|
|
id uuid PRIMARY KEY,
|
|
org_id text NOT NULL,
|
|
action_type_id uuid NOT NULL REFERENCES judgement.action_types (id),
|
|
from_level text NOT NULL,
|
|
to_level text NOT NULL,
|
|
evidence jsonb NOT NULL,
|
|
state text NOT NULL CHECK (state IN ('pending', 'approved', 'denied', 'expired', 'superseded')),
|
|
deadline timestamptz NOT NULL,
|
|
proposed_at timestamptz NOT NULL,
|
|
answered_by text,
|
|
answered_at timestamptz,
|
|
answered_by_id text
|
|
);
|
|
CREATE UNIQUE INDEX autonomy_proposals_one_pending ON judgement.autonomy_proposals (action_type_id) WHERE (state = 'pending');
|
|
CREATE INDEX autonomy_proposals_by_action_type ON judgement.autonomy_proposals (action_type_id, proposed_at);
|
|
|
|
-- Hard rules and change-request rules are Cedar policy sets, one per kind per
|
|
-- organisation. Every version is kept, and the highest version is in force.
|
|
CREATE TABLE judgement.policy_sets (
|
|
id uuid PRIMARY KEY,
|
|
org_id text NOT NULL,
|
|
kind text NOT NULL CHECK (kind IN ('hard_rules', 'change_request')),
|
|
version integer NOT NULL,
|
|
body text NOT NULL,
|
|
created_by text NOT NULL,
|
|
created_at timestamptz NOT NULL DEFAULT now(),
|
|
UNIQUE (org_id, kind, version)
|
|
);
|
|
|
|
-- +goose Down
|
|
DROP SCHEMA judgement CASCADE;
|