mirror of
https://github.com/Dvorinka/Primora.git
synced 2026-10-28 15:51:23 +00:00
Migration 00016: function_id on scheduled_jobs/inbound_hooks, event_pattern on functions, 'event' in the run-trigger enum. - Jobs deliver to a function instead of HTTP when function_id is set; the run's status_code mirrors the process exit code. Clearing the field returns the job to URL delivery. - Inbound hooks gain mode "function" — received body becomes stdin payload, acked immediately, run recorded async. - event_pattern (document.*, *, exact type) fires the function detached on matching publishEvent — never blocks realtime/webhook fan-out. - One executeFunction path serves manual/schedule/hook/event; run rows record the trigger source. - Backend image now ships bun 1.3.14 so Functions work under compose. Dashboard: job target picker, hook function mode, event-pattern field. Verified live: job run → success (status_code 0), hook POST → run, document.created → event run with correct payload. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
46 lines
1.3 KiB
SQL
46 lines
1.3 KiB
SQL
-- name: CreateFunction :one
|
|
INSERT INTO core.functions (project_id, name, code, runtime, event_pattern)
|
|
VALUES ($1, $2, $3, $4, $5)
|
|
RETURNING *;
|
|
|
|
-- name: GetFunction :one
|
|
SELECT * FROM core.functions WHERE id = $1;
|
|
|
|
-- name: GetFunctionByName :one
|
|
SELECT * FROM core.functions WHERE project_id = $1 AND name = $2;
|
|
|
|
-- name: ListFunctions :many
|
|
SELECT * FROM core.functions
|
|
WHERE project_id = $1
|
|
ORDER BY name;
|
|
|
|
-- name: UpdateFunction :one
|
|
UPDATE core.functions
|
|
SET code = COALESCE(sqlc.narg('code'), code),
|
|
enabled = COALESCE(sqlc.narg('enabled'), enabled),
|
|
event_pattern = COALESCE(sqlc.narg('event_pattern'), event_pattern),
|
|
updated_at = NOW()
|
|
WHERE id = $1 AND project_id = $2
|
|
RETURNING *;
|
|
|
|
-- name: DeleteFunction :exec
|
|
DELETE FROM core.functions WHERE id = $1 AND project_id = $2;
|
|
|
|
-- name: InsertFunctionRun :one
|
|
INSERT INTO core.function_runs (function_id, trigger, status, exit_code, stdout, stderr, duration_ms)
|
|
VALUES ($1, $2, $3, $4, $5, $6, $7)
|
|
RETURNING *;
|
|
|
|
-- name: ListFunctionRuns :many
|
|
SELECT * FROM core.function_runs
|
|
WHERE function_id = $1
|
|
ORDER BY created_at DESC
|
|
LIMIT $2;
|
|
|
|
-- name: ListFunctionsForEvent :many
|
|
SELECT * FROM core.functions
|
|
WHERE project_id = $1
|
|
AND enabled = TRUE
|
|
AND event_pattern <> ''
|
|
AND ($2 LIKE REPLACE(event_pattern, '*', '%') OR event_pattern = '*');
|