feat: event ids, outbox identity migration

This commit is contained in:
2026-10-25 23:57:24 +01:00
parent c31aa033cc
commit 32dfc84697
14 changed files with 287 additions and 39 deletions

View File

@@ -0,0 +1,23 @@
-- Outbox identity: every queued event carries a stable id; handlers record
-- (event_id, handler) pairs so redeliveries are skipped.
ALTER TABLE event_queue ADD COLUMN event_id TEXT;
-- Legacy rows get a random v4-shaped uuid. The subquery references the row id
-- so it is re-evaluated per row rather than cached.
UPDATE event_queue SET event_id = (
SELECT lower(
substr(h, 1, 8) || '-' || substr(h, 9, 4) || '-4' || substr(h, 14, 3) || '-'
|| substr('89ab', (abs(random()) % 4) + 1, 1) || substr(h, 18, 3) || '-' || substr(h, 21, 12)
)
FROM (SELECT hex(randomblob(16)) AS h, event_queue.id AS row_id)
);
CREATE UNIQUE INDEX idx_event_queue_event_id
ON event_queue (event_id) WHERE event_id IS NOT NULL;
CREATE TABLE processed_events (
event_id TEXT NOT NULL,
handler TEXT NOT NULL,
processed_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%SZ', 'now')),
PRIMARY KEY (event_id, handler)
);