Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions internal/database/migrations/000002_webhooks.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
DROP TABLE IF EXISTS webhook_deliveries;
DROP TABLE IF EXISTS webhook_registrations;
24 changes: 24 additions & 0 deletions internal/database/migrations/000002_webhooks.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
CREATE TABLE IF NOT EXISTS webhook_registrations (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
url TEXT NOT NULL,
secret TEXT NOT NULL, -- encrypted at rest (ENCRYPTION_KEY)
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
);

CREATE TABLE IF NOT EXISTS webhook_deliveries (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
registration_id UUID NOT NULL REFERENCES webhook_registrations (id) ON DELETE CASCADE,
event TEXT NOT NULL, -- 'job.done' | 'job.failed'
asset_id UUID NOT NULL,
job_id BIGINT NOT NULL,
payload JSONB NOT NULL,
status TEXT NOT NULL DEFAULT 'pending', -- pending | delivered | failed
attempts INT NOT NULL DEFAULT 0,
next_attempt_at TIMESTAMPTZ NOT NULL DEFAULT now(),
delivered_at TIMESTAMPTZ,
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
);

CREATE INDEX IF NOT EXISTS webhook_deliveries_pending_idx
ON webhook_deliveries (next_attempt_at)
WHERE status = 'pending';