← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~wgrant/launchpad/webhook-db into lp:launchpad/db-devel

 

William Grant has proposed merging lp:~wgrant/launchpad/webhook-db into lp:launchpad/db-devel.

Commit message:
Add webhook schema (Webhook, WebhookJob).

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~wgrant/launchpad/webhook-db/+merge/264003

This branch adds the initial schema for webhooks.

The model is implemented in https://code.launchpad.net/~wgrant/launchpad/webhook-model/+merge/264004, but here's a summary. The owner of an IWebhookTarget (currently IGitRepository) can create IWebhooks to receive events related to that target. Each event creates an IWebhookDeliveryJob (a "delivery") which is stored as a WebhookJob. A delivery may be retried many times, automatically via the normal Job retry machinery, or triggered manually by the user.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~wgrant/launchpad/webhook-db into lp:launchpad/db-devel.
=== added file 'database/schema/patch-2209-66-0.sql'
--- database/schema/patch-2209-66-0.sql	1970-01-01 00:00:00 +0000
+++ database/schema/patch-2209-66-0.sql	2015-07-07 08:01:33 +0000
@@ -0,0 +1,34 @@
+-- Copyright 2015 Canonical Ltd.  This software is licensed under the
+-- GNU Affero General Public License version 3 (see the file LICENSE).
+
+SET client_min_messages=ERROR;
+
+CREATE TABLE WebHook (
+    id serial PRIMARY KEY,
+    git_repository integer REFERENCES GitRepository,
+    registrant integer REFERENCES Person,
+    date_created timestamp without time zone
+        DEFAULT (CURRENT_TIMESTAMP AT TIME ZONE 'UTC') NOT NULL,
+    date_last_modified timestamp without time zone
+        DEFAULT (CURRENT_TIMESTAMP AT TIME ZONE 'UTC') NOT NULL,
+    active boolean DEFAULT true NOT NULL,
+    delivery_url text NOT NULL,
+    secret text,
+    json_data text NOT NULL,
+    CHECK (git_repository IS NOT NULL) -- To be expanded to other targets.
+    );
+
+CREATE TABLE WebHookJob (
+    job integer PRIMARY KEY REFERENCES Job ON DELETE CASCADE NOT NULL,
+    webhook integer REFERENCES WebHook NOT NULL,
+    job_type integer NOT NULL,
+    json_data text NOT NULL
+    );
+
+CREATE INDEX webhook__git_repository__id__idx
+    ON webhook(git_repository, id) WHERE git_repository IS NOT NULL;
+
+CREATE INDEX webhookjob__webhook__job_type__job__idx
+    ON webhookjob(webhook, job_type, job);
+
+INSERT INTO LaunchpadDatabaseRevision VALUES (2209, 66, 0);