Merge ~pappacena/launchpad:snap-pillar-db-indexes into launchpad:db-devel

Proposed by Thiago F. Pappacena
Status: Superseded
Proposed branch: ~pappacena/launchpad:snap-pillar-db-indexes
Merge into: launchpad:db-devel
Prerequisite: ~pappacena/launchpad:snap-pillar-db
Diff against target: 122 lines (+32/-13)
4 files modified
database/schema/patch-2210-26-1.sql (+11/-13)
database/schema/patch-2210-26-2.sql (+14/-0)
database/schema/security.cfg (+3/-0)
lib/lp/registry/personmerge.py (+4/-0)
Reviewer Review Type Date Requested Status
Launchpad code reviewers Pending
Review via email: mp+398359@code.launchpad.net

Commit message

Snap privacy indexes and CHECK constraint validation

To post a comment you must log in.

Unmerged commits

c8875c6... by Thiago F. Pappacena

Snap privacy indexes and CHECK constraint validation

a44145f... by Thiago F. Pappacena

Skipping personmerge sanity checks on SnapSubscription (while we dont have this entity in place)

bcdb89b... by Thiago F. Pappacena

Minor adjustments, and moving large index/constraint creation to another patch

0510967... by Thiago F. Pappacena

Fixing ambiguity in snap_denorm_access

08fb5e5... by Thiago F. Pappacena

Adding Snap.information_type column

9c49e1b... by Thiago F. Pappacena

Adding SnapSubscription model

f2abd3c... by Thiago F. Pappacena

Adding access_policy and access_grants caches to Snap table

ea33cf9... by Thiago F. Pappacena

Adding Snap.project for private Snaps' optional pillars

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/database/schema/patch-2210-26-1.sql b/database/schema/patch-2210-26-1.sql
2index 5511d91..90fdbf3 100644
3--- a/database/schema/patch-2210-26-1.sql
4+++ b/database/schema/patch-2210-26-1.sql
5@@ -18,8 +18,8 @@ COMMENT ON COLUMN Snap.information_type IS
6
7 CREATE TABLE SnapSubscription (
8 id serial PRIMARY KEY,
9- person integer NOT NULL REFERENCES Person(id),
10 snap integer NOT NULL REFERENCES Snap(id),
11+ person integer NOT NULL REFERENCES Person(id),
12 date_created timestamp without time zone DEFAULT (CURRENT_TIMESTAMP AT TIME ZONE 'UTC') NOT NULL,
13 subscribed_by integer NOT NULL REFERENCES Person(id)
14 );
15@@ -41,17 +41,17 @@ CREATE UNIQUE INDEX snapsubscription__person_snap__key
16 CREATE INDEX snapsubscription__person__idx
17 ON SnapSubscription(person);
18
19+CREATE INDEX snapsubscription__subscribed_by__idx
20+ ON SnapSubscription(subscribed_by);
21+
22 ALTER TABLE AccessArtifact
23 ADD COLUMN snap integer REFERENCES snap;
24
25-CREATE UNIQUE INDEX accessartifact__snap__key
26- ON AccessArtifact(snap) WHERE snap IS NOT NULL;
27-
28
29 ALTER TABLE AccessArtifact DROP CONSTRAINT has_artifact;
30 ALTER TABLE AccessArtifact
31 ADD CONSTRAINT has_artifact CHECK (
32- (null_count(ARRAY[bug, branch, gitrepository, snap, specification]) = 4));
33+ (null_count(ARRAY[bug, branch, gitrepository, snap, specification]) = 4)) NOT VALID;
34
35
36 CREATE OR REPLACE FUNCTION snap_denorm_access(snap_id integer)
37@@ -60,17 +60,15 @@ $$
38 DECLARE
39 info_type integer;
40 BEGIN
41- -- XXX pappacena 2021-002-12: Once we finish filling "information_type" and
42+ -- XXX pappacena 2021-02-12: Once we finish filling "information_type" and
43 -- deprecate the usage of "public" column at code level, we will be able to
44 -- drop the "private" column usage here.
45 SELECT
46- CASE snap.information_type
47- WHEN NULL THEN
48- -- information type: 1 = public; 5 = proprietary
49- CASE WHEN snap.private THEN 5 ELSE 1 END
50- ELSE
51- snap.information_type
52- END
53+ COALESCE(
54+ snap.information_type,
55+ -- information type: 1 = public; 5 = proprietary
56+ CASE WHEN snap.private THEN 5 ELSE 1 END
57+ )
58 INTO info_type
59 FROM snap WHERE id = snap_id;
60
61diff --git a/database/schema/patch-2210-26-2.sql b/database/schema/patch-2210-26-2.sql
62new file mode 100644
63index 0000000..ab6e0a3
64--- /dev/null
65+++ b/database/schema/patch-2210-26-2.sql
66@@ -0,0 +1,14 @@
67+-- Copyright 2021 Canonical Ltd. This software is licensed under the
68+-- GNU Affero General Public License version 3 (see the file LICENSE).
69+
70+SET client_min_messages=ERROR;
71+
72+CREATE INDEX snap__project__idx ON Snap(project) WHERE project IS NOT NULL;
73+
74+CREATE UNIQUE INDEX accessartifact__snap__key
75+ ON AccessArtifact(snap) WHERE snap IS NOT NULL;
76+
77+ALTER TABLE AccessArtifact VALIDATE CONSTRAINT has_artifact;
78+
79+
80+INSERT INTO LaunchpadDatabaseRevision VALUES (2210, 26, 2);
81diff --git a/database/schema/security.cfg b/database/schema/security.cfg
82index bf4b81c..e343a5f 100644
83--- a/database/schema/security.cfg
84+++ b/database/schema/security.cfg
85@@ -302,6 +302,7 @@ public.snapbuild = SELECT, INSERT, UPDATE, DELETE
86 public.snapbuildjob = SELECT, INSERT, UPDATE, DELETE
87 public.snapfile = SELECT, INSERT, UPDATE, DELETE
88 public.snapjob = SELECT, INSERT, UPDATE, DELETE
89+public.snapsubscription = SELECT, INSERT, UPDATE, DELETE
90 public.snappydistroseries = SELECT, INSERT, UPDATE, DELETE
91 public.snappyseries = SELECT, INSERT, UPDATE, DELETE
92 public.sourcepackageformatselection = SELECT
93@@ -2246,6 +2247,7 @@ type=user
94
95 [person-merge-job]
96 groups=script
97+public.accesspolicyartifact = SELECT
98 public.accessartifactgrant = SELECT, UPDATE, DELETE
99 public.accesspolicy = SELECT, UPDATE, DELETE
100 public.accesspolicygrant = SELECT, UPDATE, DELETE
101@@ -2363,6 +2365,7 @@ public.signedcodeofconduct = SELECT, UPDATE
102 public.snap = SELECT, UPDATE
103 public.snapbase = SELECT, UPDATE
104 public.snapbuild = SELECT, UPDATE
105+public.snapsubscription = SELECT, UPDATE, DELETE
106 public.snappyseries = SELECT, UPDATE
107 public.sourcepackagename = SELECT
108 public.sourcepackagepublishinghistory = SELECT, UPDATE
109diff --git a/lib/lp/registry/personmerge.py b/lib/lp/registry/personmerge.py
110index 7873a61..50e0f91 100644
111--- a/lib/lp/registry/personmerge.py
112+++ b/lib/lp/registry/personmerge.py
113@@ -917,6 +917,10 @@ def merge_people(from_person, to_person, reviewer, delete=False):
114 _mergeSnap(cur, from_person, to_person)
115 skip.append(('snap', 'owner'))
116
117+ # XXX pappacena 2021-02-18: add tests for this once we have
118+ # SnapSubscription model in place.
119+ skip.append(('snapsubscription', 'person'))
120+
121 _mergeOCIRecipe(cur, from_person, to_person)
122 skip.append(('ocirecipe', 'owner'))
123