feat(webhooks): add per-verb subscriptions and bulk-create debounce
Subscriptions now declare a `verb` (create | delete | bulk-create). POST /:did/webhooks defaults to inserting both create and delete rows when no verb is given, preserving existing all-events behavior. Update events fold into the create verb. The new bulk-create verb debounces creates per DID over 400 ms and delivers a `records` array. Migration adds the verb column with default 'create' and clones every existing row for the delete verb so legacy subscriptions keep firing on both events.
This commit is contained in:
@@ -61,4 +61,23 @@ try {
|
||||
// Column already exists — no-op
|
||||
}
|
||||
|
||||
try {
|
||||
db.exec(
|
||||
`ALTER TABLE webhook_subscription ADD COLUMN verb TEXT NOT NULL DEFAULT 'create';`,
|
||||
);
|
||||
db.exec(`
|
||||
INSERT INTO webhook_subscription (did, method, url, token, verb)
|
||||
SELECT did, method, url, token, 'delete'
|
||||
FROM webhook_subscription
|
||||
WHERE verb = 'create';
|
||||
`);
|
||||
} catch {
|
||||
// Column already exists — backfill already happened on a previous run.
|
||||
}
|
||||
|
||||
db.exec(`
|
||||
CREATE INDEX IF NOT EXISTS idx_webhook_subscription_did_verb
|
||||
ON webhook_subscription(did, verb);
|
||||
`);
|
||||
|
||||
db.close();
|
||||
|
||||
Reference in New Issue
Block a user