From 42f0688f84056dc9bdabded5c4aaf04361c3472b Mon Sep 17 00:00:00 2001 From: Sam Catlow Date: Mon, 16 Nov 2026 10:04:44 +1100 Subject: [PATCH] feat(pg): tables for stored workflow documents, dry runs and drafts (#2008) --- .../platform/pg/migrations/00031_drafts.sql | 55 +++++++++++++++++++ .../runs/{investigate.go => interpreter.go} | 0 2 files changed, 55 insertions(+) create mode 100644 internal/platform/pg/migrations/00031_drafts.sql rename modules/runs/{investigate.go => interpreter.go} (100%) diff --git a/internal/platform/pg/migrations/00031_drafts.sql b/internal/platform/pg/migrations/00031_drafts.sql new file mode 100644 index 000000000..47d467a9f --- /dev/null +++ b/internal/platform/pg/migrations/00031_drafts.sql @@ -0,0 +1,55 @@ +-- +goose Up +-- A workflow is a document, stored by name and version. A run pins the version +-- it started on and executes that document. +CREATE TABLE runs.workflows ( + org_id text NOT NULL, + name text NOT NULL, + version integer NOT NULL, + body text NOT NULL, + created_by text NOT NULL, + created_at timestamptz NOT NULL DEFAULT now(), + PRIMARY KEY (org_id, name, version) +); + +-- A dry run judges every action and executes none that changes something. It +-- carries the unpublished document and policy it runs under in overlay, and +-- pins no stored version. +ALTER TABLE runs.runs + ADD COLUMN dry boolean NOT NULL DEFAULT false, + ADD COLUMN overlay jsonb; + +-- A dry run's decisions are kept for its trail and counted toward nothing: +-- not the action budget, not a class's history. +ALTER TABLE judgement.decisions ADD COLUMN dry boolean NOT NULL DEFAULT false; + +-- A draft bundles the trigger an unmatched group proposes, the workflow that +-- trigger would start and any policy it needs, with the dry run last made of +-- it. One draft per group. +CREATE SCHEMA drafts; + +CREATE TABLE drafts.drafts ( + id uuid PRIMARY KEY, + org_id text NOT NULL, + group_id uuid NOT NULL, + name text NOT NULL, + source text NOT NULL, + event_type text NOT NULL, + filter jsonb NOT NULL, + document text NOT NULL, + policy_kind text NOT NULL CHECK (policy_kind IN ('hard_rules', 'change_request')), + policy text NOT NULL, + dry_run_id uuid, + dry_event_id uuid, + installed_version integer, + published_at timestamptz, + created_at timestamptz NOT NULL DEFAULT now(), + updated_at timestamptz NOT NULL DEFAULT now(), + UNIQUE (org_id, group_id), + UNIQUE (org_id, name) +); + +-- +goose Down +DROP SCHEMA drafts CASCADE; +ALTER TABLE judgement.decisions DROP COLUMN dry; +ALTER TABLE runs.runs DROP COLUMN overlay, DROP COLUMN dry; +DROP TABLE runs.workflows; diff --git a/modules/runs/investigate.go b/modules/runs/interpreter.go similarity index 100% rename from modules/runs/investigate.go rename to modules/runs/interpreter.go