Reviewed-on: #26
This commit was merged in pull request #26.
This commit is contained in:
13
crates/adapters/sqlite/migrations/0100_event_queue.sql
Normal file
13
crates/adapters/sqlite/migrations/0100_event_queue.sql
Normal file
@@ -0,0 +1,13 @@
|
||||
CREATE TABLE IF NOT EXISTS event_queue (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
event_type TEXT NOT NULL,
|
||||
payload TEXT NOT NULL,
|
||||
status TEXT NOT NULL DEFAULT 'pending',
|
||||
attempts INTEGER NOT NULL DEFAULT 0,
|
||||
created_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%SZ', 'now')),
|
||||
next_attempt_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%SZ', 'now')),
|
||||
last_error TEXT
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_event_queue_poll
|
||||
ON event_queue (status, next_attempt_at);
|
||||
29
crates/adapters/sqlite/migrations/0101_outbox_identity.sql
Normal file
29
crates/adapters/sqlite/migrations/0101_outbox_identity.sql
Normal file
@@ -0,0 +1,29 @@
|
||||
-- Outbox identity: every queued event carries a stable id; handlers claim
|
||||
-- (event_id, handler) pairs so redeliveries are skipped and concurrent
|
||||
-- deliveries never run the same handler twice.
|
||||
ALTER TABLE event_queue ADD COLUMN event_id TEXT;
|
||||
|
||||
-- When the current claim started; a claim older than the lease is reclaimable.
|
||||
ALTER TABLE event_queue ADD COLUMN claimed_at 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,
|
||||
status TEXT NOT NULL CHECK (status IN ('in_progress', 'done')),
|
||||
started_at TEXT,
|
||||
processed_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%SZ', 'now')),
|
||||
PRIMARY KEY (event_id, handler)
|
||||
);
|
||||
@@ -0,0 +1,9 @@
|
||||
ALTER TABLE users ADD COLUMN deleted_at TEXT;
|
||||
-- Set once the account's data is purged; the stripped row (and the signing
|
||||
-- keypair) stays until the tombstone cleanup removes it.
|
||||
ALTER TABLE users ADD COLUMN purged_at TEXT;
|
||||
|
||||
CREATE TABLE retired_usernames (
|
||||
username TEXT PRIMARY KEY COLLATE NOCASE,
|
||||
retired_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%SZ', 'now'))
|
||||
);
|
||||
Reference in New Issue
Block a user