A source is the capture endpoint: a UUIDv7 path by default or a unique URL-safe custom path, signed by default with an Archie-generated secret (encrypted via the bindings cipher), or unsigned after an approval. Intake verifies X-Hub-Signature-256/X-Signature-256 against the source secret before redaction; an unauthenticated event on a signed source is captured but never dispatched, an event on an approved unsigned source dispatches and is marked unsigned. The binding secret is retired; migration 0006 derives sources from existing binding and capture source strings, moving each binding's secret onto its source. SourceStore crosses the State Store gRPC contract. The dashboard gains a sources panel and flags unsigned in the capture inspector, binding list and task timeline.
117 lines
3.9 KiB
SQL
117 lines
3.9 KiB
SQL
-- EDA queries: captures, mappings, bindings, dispatch ledgers, tool_calls.
|
|
|
|
-- name: InsertCapture :exec
|
|
INSERT INTO captures (id, source, remote_addr, content_type, headers, body, authenticated, received_at, unsigned)
|
|
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9);
|
|
|
|
-- name: ListCaptures :many
|
|
SELECT id, source, remote_addr, content_type, headers, body, authenticated, received_at, unsigned
|
|
FROM captures
|
|
ORDER BY received_at DESC
|
|
LIMIT $1;
|
|
|
|
-- name: ListUndispatchedCaptures :many
|
|
SELECT id, source, remote_addr, content_type, headers, body, authenticated, received_at, unsigned
|
|
FROM captures
|
|
WHERE source = ANY(@sources::text[])
|
|
AND id NOT IN (SELECT capture FROM binding_dispatches)
|
|
ORDER BY received_at DESC
|
|
LIMIT @entry_limit;
|
|
|
|
-- name: DeleteCapturesOlderThan :exec
|
|
DELETE FROM captures WHERE received_at < $1;
|
|
|
|
-- name: DeleteCapturesBeyondCount :exec
|
|
DELETE FROM captures WHERE id NOT IN (
|
|
SELECT id FROM captures ORDER BY received_at DESC LIMIT $1
|
|
);
|
|
|
|
-- name: InsertMapping :exec
|
|
INSERT INTO mappings (id, name, source_hint, fields)
|
|
VALUES ($1, $2, $3, $4);
|
|
|
|
-- name: GetMapping :one
|
|
SELECT id, name, source_hint, fields, created_at, updated_at
|
|
FROM mappings WHERE id = $1;
|
|
|
|
-- name: ListMappings :many
|
|
SELECT id, name, source_hint, fields, created_at, updated_at
|
|
FROM mappings ORDER BY created_at DESC;
|
|
|
|
-- name: UpdateMapping :execrows
|
|
UPDATE mappings
|
|
SET name = $2, source_hint = $3, fields = $4, updated_at = now()
|
|
WHERE id = $1;
|
|
|
|
-- name: DeleteMapping :execrows
|
|
DELETE FROM mappings WHERE id = $1;
|
|
|
|
-- name: InsertBinding :exec
|
|
INSERT INTO bindings (id, name, source, mapping, workflow, owner, repo, version, status)
|
|
VALUES ($1, $2, $3, $4, $5, $6, $7, 1, $8);
|
|
|
|
-- name: GetBinding :one
|
|
SELECT id, name, source, mapping, workflow, owner, repo, version, status, created_at, updated_at
|
|
FROM bindings WHERE id = $1;
|
|
|
|
-- name: ListBindings :many
|
|
SELECT id, name, source, mapping, workflow, owner, repo, version, status, created_at, updated_at
|
|
FROM bindings ORDER BY created_at DESC;
|
|
|
|
-- name: ArmedBindingsForSource :many
|
|
SELECT id, name, source, mapping, workflow, owner, repo, version, status, created_at, updated_at
|
|
FROM bindings WHERE source = $1 AND status = 'armed' ORDER BY created_at DESC;
|
|
|
|
-- name: UpdateBinding :execrows
|
|
UPDATE bindings
|
|
SET name = $2, source = $3, mapping = $4, workflow = $5, owner = $6, repo = $7,
|
|
version = version + 1, status = $8, updated_at = now()
|
|
WHERE id = $1;
|
|
|
|
-- name: SetBindingArmed :execrows
|
|
UPDATE bindings SET status = 'armed', updated_at = now() WHERE id = $1;
|
|
|
|
-- name: DeleteBinding :execrows
|
|
DELETE FROM bindings WHERE id = $1;
|
|
|
|
-- name: InsertBindingDispatch :exec
|
|
INSERT INTO binding_dispatches (binding, binding_version, capture, task_id)
|
|
VALUES ($1, $2, $3, $4);
|
|
|
|
-- name: InsertPlaybookDispatch :exec
|
|
INSERT INTO playbook_dispatches (playbook_id, playbook_version, event_id, action_id)
|
|
VALUES ($1, $2, $3, $4);
|
|
|
|
-- name: DeletePlaybookDispatches :exec
|
|
DELETE FROM playbook_dispatches WHERE playbook_id = $1;
|
|
|
|
-- name: InsertToolCall :exec
|
|
INSERT INTO tool_calls (id, task_id, attempt, tool, result, error, called_at)
|
|
VALUES ($1, $2, $3, $4, $5, $6, $7);
|
|
|
|
-- name: TaskToolCalls :many
|
|
SELECT id, task_id, attempt, tool, result, error, called_at
|
|
FROM tool_calls WHERE task_id = $1 ORDER BY called_at ASC;
|
|
|
|
-- name: InsertSource :exec
|
|
INSERT INTO sources (path, signing, secret) VALUES ($1, $2, $3);
|
|
|
|
-- name: GetSource :one
|
|
SELECT path, signing, secret, created_at, updated_at FROM sources WHERE path = $1;
|
|
|
|
-- name: ListSources :many
|
|
SELECT path, signing, secret, created_at, updated_at FROM sources ORDER BY created_at DESC, path;
|
|
|
|
-- name: SetSourceSigning :execrows
|
|
UPDATE sources SET signing = sqlc.arg(to_signing), updated_at = now()
|
|
WHERE path = sqlc.arg(path) AND signing = sqlc.arg(from_signing);
|
|
|
|
-- name: SetSourceSecret :execrows
|
|
UPDATE sources SET secret = $2, updated_at = now() WHERE path = $1;
|
|
|
|
-- name: SourceExists :one
|
|
SELECT EXISTS (SELECT 1 FROM sources WHERE path = $1);
|
|
|
|
-- name: DeriveSources :exec
|
|
SELECT derive_sources();
|