Merge lp://staging/~gary/launchpad/bug753000 into lp://staging/launchpad/db-devel

Proposed by Gary Poster
Status: Merged
Approved by: Stuart Bishop
Approved revision: no longer in the source branch.
Merged at revision: 10481
Proposed branch: lp://staging/~gary/launchpad/bug753000
Merge into: lp://staging/launchpad/db-devel
Diff against target: 573 lines (+521/-1)
4 files modified
database/schema/patch-2208-65-0.sql (+360/-0)
database/schema/security.cfg (+2/-1)
lib/lp/registry/model/person.py (+57/-0)
lib/lp/registry/tests/test_person.py (+102/-0)
To merge this branch: bzr merge lp://staging/~gary/launchpad/bug753000
Reviewer Review Type Date Requested Status
Graham Binns (community) code Approve
Stuart Bishop (community) db Approve
Review via email: mp+59139@code.staging.launchpad.net

Commit message

[r=gmb,stub][bug=753000] Remove duplicate structural subscriptions and set up constraints in the database so they do not appear again.

Description of the change

This branch removes duplicate structural subscriptions and creates constraints as described in bug 753000. The patch file is copiously commented, so I'm hoping that it is sufficient for change notes.

Some lines are over our line limit, but I felt what I did was a reasonable compromise.

This does not change Python code because we don't know what code caused the inconsistencies to happen. The database constraints will hopefully expose the problem in the future so that we know what, if anything, to fix in the application itself.

Thank you!

Gary

To post a comment you must log in.
Revision history for this message
Stuart Bishop (stub) wrote :

The data migration looks fine, and should be fast enough with production data to run as part of the patch.

I've reworked the indexes below to minimize index size, and dropped redundant indexes. patch-2208-65-0.sql

-- CREATE CONSTRAINTS ----------------------------------------------------

CREATE UNIQUE INDEX structuralsubscription__product__subscriber__key
ON StructuralSubscription(product, subscriber) WHERE product IS NOT NULL;

CREATE UNIQUE INDEX structuralsubscription__project__subscriber__key
ON StructuralSubscription(project, subscriber) WHERE project IS NOT NULL;

-- We want to do this.
-- ALTER TABLE ONLY StructuralSubscription
-- ADD CONSTRAINT structuralsubscription__distribution__sourcepackagename__subscriber__unique
-- UNIQUE (distribution, sourcepackagename, subscriber);
-- However, we also want to do this, *if* the sourcepackagename is NULL.
-- ALTER TABLE ONLY StructuralSubscription
-- ADD CONSTRAINT structuralsubscription__distribution__subscriber__unique
-- UNIQUE (distribution, subscriber);
-- The second constraint will disallow sourcepackagename flexibility in the
-- first. Therefore, we use a unique index instead, as seen below.

CREATE UNIQUE INDEX
    structuralsubscription__distribution__sourcepackagename__subscriber__key
ON StructuralSubscription(distribution, sourcepackagename, subscriber)
WHERE distribution IS NOT NULL AND sourcepackagename IS NOT NULL;

CREATE UNIQUE INDEX structuralsubscription__distribution__subscriber__key
ON StructuralSubscription(distribution, subscriber)
WHERE distribution IS NOT NULL AND sourcepackagename IS NULL;

CREATE UNIQUE INDEX structuralsubscription__distroseries__subscriber__key
ON StructuralSubscription(distroseries, subscriber)
WHERE distroseries IS NOT NULL;

-- NB. Currently we can't subscribe to a (distroseries, sourcepackagename)
-- so no need for the second partial distroseries index like the two
-- distribution indexes.

CREATE UNIQUE INDEX structuralsubscription__milestone__subscriber__key
ON StructuralSubscription(milestone, subscriber)
WHERE milestone IS NOT NULL;

CREATE UNIQUE INDEX structuralsubscription__productseries__subscriber__key
ON StructuralSubscription(productseries, subscriber)
WHERE productseries IS NOT NULL;

-- Drop obsolete indexes - the above constraints make them redundant.
DROP INDEX structuralsubscription__distribution__sourcepackagename__idx;
DROP INDEX structuralsubscription__distroseries__idx;
DROP INDEX structuralsubscription__milestone__idx;
DROP INDEX structuralsubscription__product__idx;
DROP INDEX structuralsubscription__productseries__idx;
DROP INDEX structuralsubscription__project__idx;

INSERT INTO LaunchpadDatabaseRevision VALUES (2208, 65, 0);

review: Approve (db)
Revision history for this message
Graham Binns (gmb) wrote :

Hi Gary,

The tests - or at least the assert*()s you've added need some explanatory comments, but other than that this is good to go.

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
The diff is not available at this time. You can reload the page or download it.

Subscribers

People subscribed via source and target branches

to status/vote changes: