Some checks failed
CI / Rustfmt (push) Successful in 22s
CI / Cargo Audit & Deny (push) Successful in 36s
CI / Security Blocking Checks (push) Successful in 6s
CI / Web Blocking Checks (push) Successful in 53s
CI / Web Advisory Checks (push) Successful in 34s
Publish Images / Resolve Publish Metadata (push) Successful in 1s
CI / Security Advisory Checks (push) Successful in 38s
CI / Clippy (push) Successful in 2m7s
Publish Images / Publish Docker Dist Bundle (push) Failing after 19s
Publish Images / Publish web (amd64) (push) Successful in 49s
Publish Images / Publish web (arm64) (push) Successful in 3m31s
CI / Tests (push) Successful in 8m48s
Publish Images / Build Rust Bundles (amd64) (push) Successful in 12m42s
Publish Images / Build Rust Bundles (arm64) (push) Successful in 12m19s
Publish Images / Publish agent (amd64) (push) Successful in 26s
Publish Images / Publish api (amd64) (push) Successful in 38s
Publish Images / Publish notifier (amd64) (push) Successful in 42s
Publish Images / Publish executor (amd64) (push) Successful in 46s
Publish Images / Publish agent (arm64) (push) Successful in 56s
Publish Images / Publish api (arm64) (push) Successful in 1m52s
Publish Images / Publish executor (arm64) (push) Successful in 2m2s
Publish Images / Publish notifier (arm64) (push) Successful in 2m3s
Publish Images / Publish manifest attune/agent (push) Successful in 6s
Publish Images / Publish manifest attune/api (push) Successful in 11s
Publish Images / Publish manifest attune/executor (push) Successful in 10s
Publish Images / Publish manifest attune/notifier (push) Successful in 8s
Publish Images / Publish manifest attune/web (push) Successful in 8s
146 lines
6.1 KiB
SQL
146 lines
6.1 KiB
SQL
-- Migration: Workflow System
|
|
-- Description: Creates workflow_definition and workflow_execution tables
|
|
-- (workflow_task_execution consolidated into execution.workflow_task JSONB)
|
|
--
|
|
-- NOTE: The execution table is converted to a TimescaleDB hypertable in
|
|
-- migration 000009. Hypertables cannot be the target of FK constraints,
|
|
-- so workflow_execution.execution is a plain BIGINT with no FK.
|
|
-- execution.workflow_def also has no FK (added as plain BIGINT in 000005)
|
|
-- since execution is a hypertable and FKs from hypertables are only
|
|
-- supported for simple cases — we omit it for consistency.
|
|
-- Version: 20250101000006
|
|
|
|
-- ============================================================================
|
|
-- WORKFLOW DEFINITION TABLE
|
|
-- ============================================================================
|
|
|
|
CREATE TABLE workflow_definition (
|
|
id BIGSERIAL PRIMARY KEY,
|
|
ref VARCHAR(255) NOT NULL UNIQUE,
|
|
pack BIGINT NOT NULL REFERENCES pack(id) ON DELETE CASCADE,
|
|
pack_ref VARCHAR(255) NOT NULL,
|
|
label VARCHAR(255) NOT NULL,
|
|
description TEXT,
|
|
version VARCHAR(50) NOT NULL,
|
|
param_schema JSONB,
|
|
out_schema JSONB,
|
|
definition JSONB NOT NULL,
|
|
tags TEXT[] DEFAULT '{}',
|
|
created TIMESTAMPTZ DEFAULT NOW() NOT NULL,
|
|
updated TIMESTAMPTZ DEFAULT NOW() NOT NULL
|
|
);
|
|
|
|
-- Indexes
|
|
CREATE INDEX idx_workflow_def_pack ON workflow_definition(pack);
|
|
CREATE INDEX idx_workflow_def_ref ON workflow_definition(ref);
|
|
CREATE INDEX idx_workflow_def_tags ON workflow_definition USING gin(tags);
|
|
|
|
-- Trigger
|
|
CREATE TRIGGER update_workflow_definition_updated
|
|
BEFORE UPDATE ON workflow_definition
|
|
FOR EACH ROW
|
|
EXECUTE FUNCTION update_updated_column();
|
|
|
|
-- Comments
|
|
COMMENT ON TABLE workflow_definition IS 'Stores workflow definitions (YAML parsed to JSON)';
|
|
COMMENT ON COLUMN workflow_definition.ref IS 'Unique workflow reference (e.g., pack_name.workflow_name)';
|
|
COMMENT ON COLUMN workflow_definition.definition IS 'Complete workflow specification including tasks, variables, and transitions';
|
|
COMMENT ON COLUMN workflow_definition.param_schema IS 'JSON schema for workflow input parameters';
|
|
COMMENT ON COLUMN workflow_definition.out_schema IS 'JSON schema for workflow output';
|
|
|
|
-- ============================================================================
|
|
-- WORKFLOW EXECUTION TABLE
|
|
-- ============================================================================
|
|
|
|
CREATE TABLE workflow_execution (
|
|
id BIGSERIAL PRIMARY KEY,
|
|
execution BIGINT NOT NULL, -- references execution(id); no FK because execution is a hypertable
|
|
workflow_def BIGINT NOT NULL REFERENCES workflow_definition(id) ON DELETE CASCADE,
|
|
current_tasks TEXT[] DEFAULT '{}',
|
|
completed_tasks TEXT[] DEFAULT '{}',
|
|
failed_tasks TEXT[] DEFAULT '{}',
|
|
skipped_tasks TEXT[] DEFAULT '{}',
|
|
variables JSONB DEFAULT '{}',
|
|
task_graph JSONB NOT NULL,
|
|
status execution_status_enum NOT NULL DEFAULT 'requested',
|
|
error_message TEXT,
|
|
paused BOOLEAN DEFAULT false NOT NULL,
|
|
pause_reason TEXT,
|
|
created TIMESTAMPTZ DEFAULT NOW() NOT NULL,
|
|
updated TIMESTAMPTZ DEFAULT NOW() NOT NULL
|
|
);
|
|
|
|
-- Indexes
|
|
CREATE INDEX idx_workflow_exec_execution ON workflow_execution(execution);
|
|
CREATE INDEX idx_workflow_exec_workflow_def ON workflow_execution(workflow_def);
|
|
CREATE INDEX idx_workflow_exec_status ON workflow_execution(status);
|
|
CREATE INDEX idx_workflow_exec_paused ON workflow_execution(paused) WHERE paused = true;
|
|
|
|
-- Trigger
|
|
CREATE TRIGGER update_workflow_execution_updated
|
|
BEFORE UPDATE ON workflow_execution
|
|
FOR EACH ROW
|
|
EXECUTE FUNCTION update_updated_column();
|
|
|
|
-- Comments
|
|
COMMENT ON TABLE workflow_execution IS 'Runtime state tracking for workflow executions. execution column has no FK — execution is a hypertable.';
|
|
COMMENT ON COLUMN workflow_execution.variables IS 'Workflow-scoped variables, updated via publish directives';
|
|
COMMENT ON COLUMN workflow_execution.task_graph IS 'Execution graph with dependencies and transitions';
|
|
COMMENT ON COLUMN workflow_execution.current_tasks IS 'Array of task names currently executing';
|
|
COMMENT ON COLUMN workflow_execution.paused IS 'True if workflow execution is paused (can be resumed)';
|
|
|
|
-- ============================================================================
|
|
-- MODIFY ACTION TABLE - Add Workflow Support
|
|
-- ============================================================================
|
|
|
|
ALTER TABLE action
|
|
ADD COLUMN workflow_def BIGINT REFERENCES workflow_definition(id) ON DELETE CASCADE;
|
|
|
|
CREATE INDEX idx_action_workflow_def ON action(workflow_def);
|
|
|
|
COMMENT ON COLUMN action.workflow_def IS 'Reference to workflow definition (non-null means this action is a workflow)';
|
|
|
|
-- NOTE: execution.workflow_def has no FK constraint because execution is a
|
|
-- TimescaleDB hypertable (converted in migration 000009). The column was
|
|
-- created as a plain BIGINT in migration 000005.
|
|
|
|
-- ============================================================================
|
|
-- WORKFLOW VIEWS
|
|
-- ============================================================================
|
|
|
|
CREATE VIEW workflow_execution_summary AS
|
|
SELECT
|
|
we.id,
|
|
we.execution,
|
|
wd.ref as workflow_ref,
|
|
wd.label as workflow_label,
|
|
wd.version as workflow_version,
|
|
we.status,
|
|
we.paused,
|
|
array_length(we.current_tasks, 1) as current_task_count,
|
|
array_length(we.completed_tasks, 1) as completed_task_count,
|
|
array_length(we.failed_tasks, 1) as failed_task_count,
|
|
array_length(we.skipped_tasks, 1) as skipped_task_count,
|
|
we.error_message,
|
|
we.created,
|
|
we.updated
|
|
FROM workflow_execution we
|
|
JOIN workflow_definition wd ON we.workflow_def = wd.id;
|
|
|
|
COMMENT ON VIEW workflow_execution_summary IS 'Summary view of workflow executions with task counts';
|
|
|
|
CREATE VIEW workflow_action_link AS
|
|
SELECT
|
|
wd.id as workflow_def_id,
|
|
wd.ref as workflow_ref,
|
|
wd.label,
|
|
wd.version,
|
|
a.id as action_id,
|
|
a.ref as action_ref,
|
|
a.pack as pack_id,
|
|
a.pack_ref
|
|
FROM workflow_definition wd
|
|
LEFT JOIN action a ON a.workflow_def = wd.id;
|
|
|
|
COMMENT ON VIEW workflow_action_link IS 'Links workflow definitions to their corresponding action records';
|