merge main into the workflow editor branch (#2061)

This commit is contained in:
sam committed 2026-11-22 11:48:30 +11:00
commit 07d14c8d50
39 files changed
+4372 -547

No files matched your search

@@ -0,0 +1,67 @@
-- +goose Up
-- A source keeps a display name and the header its sender repeats on every
-- retry of one delivery. A source that does no verification refuses deliveries
-- until a person approves it, and may stop keeping the raw payload.
ALTER TABLE events.sources
ADD COLUMN display_name text NOT NULL DEFAULT '',
ADD COLUMN delivery_header text NOT NULL DEFAULT '',
ADD COLUMN unsigned_approved boolean NOT NULL DEFAULT false,
ADD COLUMN capture boolean NOT NULL DEFAULT true;
UPDATE events.sources SET unsigned_approved = true WHERE verification = 'none';
-- A person names a kind of event on a source by the headers and payload paths
-- that identify it. Its schema is the JSON paths of the example it came from.
CREATE TABLE events.event_types (
id uuid PRIMARY KEY,
org_id text NOT NULL,
source text NOT NULL,
name text NOT NULL,
rule jsonb NOT NULL,
schema jsonb NOT NULL DEFAULT '{}',
created_at timestamptz NOT NULL DEFAULT now(),
updated_at timestamptz NOT NULL DEFAULT now(),
UNIQUE (org_id, source, name)
);
-- A mapping names the payload paths a workflow reads from one event type.
CREATE TABLE events.mappings (
id uuid PRIMARY KEY,
org_id text NOT NULL,
name text NOT NULL,
source_hint text NOT NULL DEFAULT '',
event_type_id uuid NOT NULL REFERENCES events.event_types (id) ON DELETE RESTRICT,
fields jsonb NOT NULL,
match_count bigint NOT NULL DEFAULT 0,
last_matched_at timestamptz,
created_at timestamptz NOT NULL DEFAULT now(),
updated_at timestamptz NOT NULL DEFAULT now()
);
-- Each event records how its delivery was verified and the headers and sender
-- address it arrived with. The headers and body are null when the source does
-- not keep payloads. event_type_id is the type its headers and payload matched
-- on arrival.
ALTER TABLE events.events
ADD COLUMN verification text NOT NULL DEFAULT ''
CHECK (verification IN ('', 'signed', 'token', 'unsigned')),
ADD COLUMN headers jsonb,
ADD COLUMN remote_addr text NOT NULL DEFAULT '',
ADD COLUMN event_type_id uuid REFERENCES events.event_types (id) ON DELETE SET NULL;
-- A trigger bound to an event type fires only for events identified as it; a
-- bound mapping reads the event's payload for the run. Triggers
-- saved before approval existed are approved.
ALTER TABLE events.triggers
ADD COLUMN approved boolean NOT NULL DEFAULT true,
ADD COLUMN event_type_id uuid REFERENCES events.event_types (id) ON DELETE RESTRICT,
ADD COLUMN mapping_id uuid REFERENCES events.mappings (id) ON DELETE RESTRICT;
-- +goose Down
ALTER TABLE events.triggers
DROP COLUMN mapping_id, DROP COLUMN event_type_id, DROP COLUMN approved;
ALTER TABLE events.events
DROP COLUMN event_type_id, DROP COLUMN remote_addr, DROP COLUMN headers, DROP COLUMN verification;
DROP TABLE events.mappings;
DROP TABLE events.event_types;
ALTER TABLE events.sources
DROP COLUMN capture, DROP COLUMN unsigned_approved, DROP COLUMN delivery_header, DROP COLUMN display_name;