feat(runs,events,ui): identify workflows by immutable UUID (#2125)
This commit is contained in:
46 files changed
+1284
-512
No files matched your search
@@ -144,10 +144,10 @@ func (o *operations) Wait() {
|
||||
// installStarter puts the workflow that ships with the binary in place. It
|
||||
// belongs to the organisation, so it waits until setup has created one.
|
||||
func installStarter(ctx context.Context, engine *runs.Engine) error {
|
||||
if _, err := engine.Install(ctx, orgID, "investigate", runs.InvestigateDocument(), string(governance.SystemID)); err != nil {
|
||||
if _, err := engine.InstallShipped(ctx, orgID, "investigate", runs.InvestigateDocument(), string(governance.SystemID)); err != nil {
|
||||
return fmt.Errorf("install the investigate workflow: %w", err)
|
||||
}
|
||||
if _, err := engine.Install(ctx, orgID, runs.ProposalWorkflow, runs.ProposalDocument(), string(governance.SystemID)); err != nil {
|
||||
if _, err := engine.InstallShipped(ctx, orgID, runs.ProposalWorkflow, runs.ProposalDocument(), string(governance.SystemID)); err != nil {
|
||||
return fmt.Errorf("install the proposal workflow: %w", err)
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -98,7 +98,7 @@ CREATE TABLE events.triggers (
|
||||
source_id uuid REFERENCES events.sources (id),
|
||||
event_type text NOT NULL,
|
||||
filter jsonb NOT NULL DEFAULT '{}',
|
||||
workflow text NOT NULL,
|
||||
workflow_id uuid NOT NULL,
|
||||
enabled boolean NOT NULL DEFAULT true,
|
||||
updated_at timestamptz NOT NULL DEFAULT now(),
|
||||
schedule_every_s integer CHECK (schedule_every_s >= 60),
|
||||
|
||||
@@ -4,7 +4,7 @@ CREATE SCHEMA runs;
|
||||
CREATE TABLE runs.runs (
|
||||
id uuid PRIMARY KEY,
|
||||
org_id text NOT NULL,
|
||||
workflow text NOT NULL,
|
||||
workflow_id uuid,
|
||||
start_key text,
|
||||
input jsonb NOT NULL,
|
||||
state text NOT NULL CHECK (state IN ('queued', 'running', 'waiting', 'succeeded', 'failed', 'cancelled', 'parked', 'waiting_approval', 'declined')),
|
||||
@@ -27,7 +27,9 @@ CREATE TABLE runs.runs (
|
||||
parent_run_id uuid REFERENCES runs.runs (id) ON DELETE CASCADE,
|
||||
parent_signal text,
|
||||
call_depth integer NOT NULL DEFAULT 0,
|
||||
UNIQUE (org_id, start_key)
|
||||
UNIQUE (org_id, start_key),
|
||||
-- Only a test run of a document that isn't a workflow yet has no workflow.
|
||||
CHECK (dry OR workflow_id IS NOT NULL)
|
||||
);
|
||||
CREATE INDEX runs_claimable ON runs.runs (created_at) WHERE (state IN ('queued', 'waiting', 'running'));
|
||||
CREATE INDEX runs_runs_parent ON runs.runs (parent_run_id) WHERE (parent_run_id IS NOT NULL);
|
||||
@@ -51,16 +53,33 @@ CREATE TABLE runs.signals (
|
||||
PRIMARY KEY (run_id, key)
|
||||
);
|
||||
|
||||
-- A workflow is a document, stored by name and version. A run records the
|
||||
-- version it started with and executes that version.
|
||||
-- A workflow is identified by its id, fixed when it is created; its name is a
|
||||
-- label that can change. A deleted workflow keeps its row and versions, so its
|
||||
-- runs still show what they ran, and its name can be given to a new workflow.
|
||||
-- A disabled workflow can't be started by a trigger, by another workflow or
|
||||
-- manually.
|
||||
CREATE TABLE runs.workflows (
|
||||
id uuid PRIMARY KEY,
|
||||
org_id text NOT NULL,
|
||||
name text NOT NULL,
|
||||
version integer NOT NULL,
|
||||
body text NOT NULL,
|
||||
created_by text NOT NULL,
|
||||
enabled boolean NOT NULL DEFAULT true,
|
||||
created_at timestamptz NOT NULL DEFAULT now(),
|
||||
PRIMARY KEY (org_id, name, version)
|
||||
deleted_at timestamptz
|
||||
);
|
||||
CREATE UNIQUE INDEX workflows_live_name ON runs.workflows (org_id, name) WHERE (deleted_at IS NULL);
|
||||
|
||||
-- A version is one published workflow document. A run records the version it
|
||||
-- started with and executes that version. calls maps each workflow name the
|
||||
-- document calls or hands off to onto the id it resolved to when the version
|
||||
-- was published, so renaming the called workflow doesn't change what runs.
|
||||
CREATE TABLE runs.workflow_versions (
|
||||
workflow_id uuid NOT NULL REFERENCES runs.workflows (id),
|
||||
version integer NOT NULL,
|
||||
body text NOT NULL,
|
||||
calls jsonb NOT NULL DEFAULT '{}',
|
||||
created_by text NOT NULL,
|
||||
created_at timestamptz NOT NULL DEFAULT now(),
|
||||
PRIMARY KEY (workflow_id, version)
|
||||
);
|
||||
|
||||
-- A draft is the unpublished edit of a workflow. It is stored so the edit
|
||||
@@ -68,25 +87,14 @@ CREATE TABLE runs.workflows (
|
||||
-- version. revision increments on every write, and a write that specifies an
|
||||
-- older revision is refused, so two editors can't overwrite each other's
|
||||
-- changes. base_version is the published version the draft started from, or 0
|
||||
-- for a new workflow.
|
||||
-- for a workflow not yet published.
|
||||
CREATE TABLE runs.workflow_drafts (
|
||||
org_id text NOT NULL,
|
||||
name text NOT NULL,
|
||||
workflow_id uuid PRIMARY KEY REFERENCES runs.workflows (id),
|
||||
body text NOT NULL,
|
||||
base_version integer NOT NULL,
|
||||
revision integer NOT NULL DEFAULT 1,
|
||||
updated_by text NOT NULL,
|
||||
updated_at timestamptz NOT NULL DEFAULT now(),
|
||||
PRIMARY KEY (org_id, name)
|
||||
);
|
||||
|
||||
-- A workflow with no row here is enabled. A disabled workflow can't be started
|
||||
-- by a trigger, by another workflow or manually.
|
||||
CREATE TABLE runs.workflow_settings (
|
||||
org_id text NOT NULL,
|
||||
name text NOT NULL,
|
||||
enabled boolean NOT NULL,
|
||||
PRIMARY KEY (org_id, name)
|
||||
updated_at timestamptz NOT NULL DEFAULT now()
|
||||
);
|
||||
|
||||
-- +goose Down
|
||||
|
||||
Reference in new issue
Block a user