Merge lp://staging/~gary/launchpad/bug753000 into lp://staging/launchpad/db-devel
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 | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Graham Binns (community) | code | Approve | |
Stuart Bishop (community) | db | Approve | |
Review via email:
|
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
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 structuralsubsc ription_ _product_ _subscriber_ _key ription( product, subscriber) WHERE product IS NOT NULL;
ON StructuralSubsc
CREATE UNIQUE INDEX structuralsubsc ription_ _project_ _subscriber_ _key ription( project, subscriber) WHERE project IS NOT NULL;
ON StructuralSubsc
-- We want to do this. ription ription_ _distribution_ _sourcepackagen ame__subscriber __unique ription ription_ _distribution_ _subscriber_ _unique
-- ALTER TABLE ONLY StructuralSubsc
-- ADD CONSTRAINT structuralsubsc
-- UNIQUE (distribution, sourcepackagename, subscriber);
-- However, we also want to do this, *if* the sourcepackagename is NULL.
-- ALTER TABLE ONLY StructuralSubsc
-- ADD CONSTRAINT structuralsubsc
-- 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 ubscription_ _distribution_ _sourcepackagen ame__subscriber __key ription( distribution, sourcepackagename, subscriber)
structurals
ON StructuralSubsc
WHERE distribution IS NOT NULL AND sourcepackagename IS NOT NULL;
CREATE UNIQUE INDEX structuralsubsc ription_ _distribution_ _subscriber_ _key ription( distribution, subscriber)
ON StructuralSubsc
WHERE distribution IS NOT NULL AND sourcepackagename IS NULL;
CREATE UNIQUE INDEX structuralsubsc ription_ _distroseries_ _subscriber_ _key ription( distroseries, subscriber)
ON StructuralSubsc
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 structuralsubsc ription_ _milestone_ _subscriber_ _key ription( milestone, subscriber)
ON StructuralSubsc
WHERE milestone IS NOT NULL;
CREATE UNIQUE INDEX structuralsubsc ription_ _productseries_ _subscriber_ _key ription( productseries, subscriber)
ON StructuralSubsc
WHERE productseries IS NOT NULL;
-- Drop obsolete indexes - the above constraints make them redundant. ription_ _distribution_ _sourcepackagen ame__idx; ription_ _distroseries_ _idx; ription_ _milestone_ _idx; ription_ _product_ _idx; ription_ _productseries_ _idx; ription_ _project_ _idx;
DROP INDEX structuralsubsc
DROP INDEX structuralsubsc
DROP INDEX structuralsubsc
DROP INDEX structuralsubsc
DROP INDEX structuralsubsc
DROP INDEX structuralsubsc
INSERT INTO LaunchpadDataba seRevision VALUES (2208, 65, 0);