| 1 | -- ─── domain_events_processed ────────────────────────────────────── |
| 2 | |
| 3 | -- name: GetEventCursor :one |
| 4 | SELECT consumer, last_event_id, updated_at |
| 5 | FROM domain_events_processed |
| 6 | WHERE consumer = $1; |
| 7 | |
| 8 | -- name: SetEventCursor :exec |
| 9 | -- Always-write upsert so the worker doesn't have to special-case |
| 10 | -- the missing-row branch (the migration seeds 'notify_fanout' at |
| 11 | -- 0; future consumers like 'webhook_deliver' do the same on first |
| 12 | -- run via this same call). |
| 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 | -- The fan-out worker's read cursor. Bounded so a single tick |
| 21 | -- doesn't try to drain a million-row backlog. |
| 22 | SELECT id, actor_user_id, kind, repo_id, source_kind, source_id, |
| 23 | public, payload, created_at |
| 24 | FROM domain_events |
| 25 | WHERE id > $1 |
| 26 | ORDER BY id |
| 27 | LIMIT $2; |
| 28 |