Merge lp:~wgrant/launchpad/xref-db into lp:launchpad/db-devel

Proposed by William Grant
Status: Merged
Merged at revision: 13235
Proposed branch: lp:~wgrant/launchpad/xref-db
Merge into: lp:launchpad/db-devel
Diff against target: 55 lines (+33/-0)
2 files modified
database/schema/patch-2209-70-0.sql (+31/-0)
database/schema/security.cfg (+2/-0)
To merge this branch: bzr merge lp:~wgrant/launchpad/xref-db
Reviewer Review Type Date Requested Status
Colin Watson (community) db Approve
Review via email: mp+272587@code.launchpad.net

Commit message

Add an XRef table for generic cross-references between artifacts.

Description of the change

Add an XRef table for generic cross-references between artifacts.

Model code is at <https://code.launchpad.net/~wgrant/launchpad/xref-model/+merge/272588>.

An artifact is identified as a tuple of two Unicode strings: ('type', 'id'). Examples from the initial series include ('bug', '1'), ('specification', '10'), ('question', '100') and ('cve', '2015-0001').

To optimise SQL joins against tables with integral PKs, *_id_int columns are available and populated automatically if the ID looks like a decimal number.

Model code automatically creates links in both directions. This won't always be the case when the table can also refer to remote objects, but it makes queries faster and easier today.

To post a comment you must log in.
Revision history for this message
Colin Watson (cjwatson) :
review: Approve (db)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added file 'database/schema/patch-2209-70-0.sql'
--- database/schema/patch-2209-70-0.sql 1970-01-01 00:00:00 +0000
+++ database/schema/patch-2209-70-0.sql 2015-09-28 12:40:41 +0000
@@ -0,0 +1,31 @@
1-- Copyright 2015 Canonical Ltd. This software is licensed under the
2-- GNU Affero General Public License version 3 (see the file LICENSE).
3
4SET client_min_messages=ERROR;
5
6CREATE TABLE XRef (
7 from_type text NOT NULL,
8 from_id text NOT NULL,
9 from_id_int integer,
10 to_type text NOT NULL,
11 to_id text NOT NULL,
12 to_id_int integer,
13 creator integer REFERENCES Person,
14 date_created timestamp without time zone
15 DEFAULT (CURRENT_TIMESTAMP AT TIME ZONE 'UTC') NOT NULL,
16 metadata text,
17 PRIMARY KEY (from_type, from_id, to_type, to_id)
18);
19
20CREATE UNIQUE INDEX xref__inverse__key
21 ON XRef(to_type, to_id, from_type, from_id);
22CREATE UNIQUE INDEX xref__int__key
23 ON XRef(from_type, from_id_int, to_type, to_id_int);
24CREATE UNIQUE INDEX xref__int_inverse__key
25 ON XRef(to_type, to_id_int, from_type, from_id_int);
26CREATE INDEX xref__from_type__to_type__idx ON XRef(from_type, to_type);
27CREATE INDEX xref__to_type__from_type__idx ON XRef(to_type, from_type);
28
29CREATE INDEX xref__creator__idx ON XRef(creator);
30
31INSERT INTO LaunchpadDatabaseRevision VALUES (2209, 70, 0);
032
=== modified file 'database/schema/security.cfg'
--- database/schema/security.cfg 2015-09-09 16:48:14 +0000
+++ database/schema/security.cfg 2015-09-28 12:40:41 +0000
@@ -328,6 +328,7 @@
328public.webhook = SELECT, INSERT, UPDATE, DELETE328public.webhook = SELECT, INSERT, UPDATE, DELETE
329public.webhookjob = SELECT, INSERT, UPDATE, DELETE329public.webhookjob = SELECT, INSERT, UPDATE, DELETE
330public.wikiname = SELECT, INSERT, UPDATE, DELETE330public.wikiname = SELECT, INSERT, UPDATE, DELETE
331public.xref = SELECT, INSERT, UPDATE, DELETE
331type=user332type=user
332333
333[launchpad]334[launchpad]
@@ -2268,6 +2269,7 @@
2268public.votecast = SELECT, UPDATE2269public.votecast = SELECT, UPDATE
2269public.webhook = SELECT, UPDATE2270public.webhook = SELECT, UPDATE
2270public.wikiname = SELECT, UPDATE2271public.wikiname = SELECT, UPDATE
2272public.xref = SELECT, UPDATE
2271type=user2273type=user
22722274
2273[garbo]2275[garbo]

Subscribers

People subscribed via source and target branches

to status/vote changes: