| 1 | -- SPDX-License-Identifier: AGPL-3.0-or-later |
| 2 | -- |
| 3 | -- Webhook fanout reads the same domain_events / cursor surface that |
| 4 | -- notifications do — but with its own consumer row so progress |
| 5 | -- doesn't collide with notify_fanout. |
| 6 | |
| 7 | -- name: GetWebhookCursor :one |
| 8 | SELECT consumer, last_event_id, updated_at |
| 9 | FROM domain_events_processed |
| 10 | WHERE consumer = $1; |
| 11 | |
| 12 | -- name: SetWebhookCursor :exec |
| 13 | INSERT INTO domain_events_processed (consumer, last_event_id) |
| 14 | VALUES ($1, $2) |
| 15 | ON CONFLICT (consumer) |
| 16 | DO UPDATE SET last_event_id = EXCLUDED.last_event_id, |
| 17 | updated_at = now(); |
| 18 | |
| 19 | -- name: ListUnprocessedDomainEvents :many |
| 20 | SELECT id, actor_user_id, kind, repo_id, source_kind, source_id, |
| 21 | public, payload, created_at |
| 22 | FROM domain_events |
| 23 | WHERE id > $1 |
| 24 | ORDER BY id |
| 25 | LIMIT $2; |
| 26 | |
| 27 | -- name: GetRepoOwnerKindForFanout :one |
| 28 | -- Resolve a repo's owner so the fanout knows which webhooks to fire. |
| 29 | -- Returns owner_kind 'user' or 'org' so the matcher knows what bucket |
| 30 | -- to look in. (We use 'user' as a literal string here; the webhook |
| 31 | -- machinery itself only stores 'repo'/'org' as owners — repo-owned |
| 32 | -- webhooks attach to the repo regardless of who owns the repo.) |
| 33 | SELECT owner_user_id, owner_org_id |
| 34 | FROM repos |
| 35 | WHERE id = $1; |
| 36 |