~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to database/schema/pending/stub-distroreleasequeue.sql

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-12-22 04:55:30 UTC
  • mfrom: (14577.1.1 testfix)
  • Revision ID: launchpad@pqm.canonical.com-20111222045530-wki9iu6c0ysqqwkx
[r=wgrant][no-qa] Fix test_publisherconfig lpstorm import. Probably a
        silent conflict between megalint and apocalypse.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
-- Copyright 2009 Canonical Ltd.  This software is licensed under the
 
2
-- GNU Affero General Public License version 3 (see the file LICENSE).
 
3
 
 
4
SET client_min_messages=ERROR;
 
5
 
 
6
/*
 
7
    Collapse DistreoReleaseQueue* into a single table, and add a date_created
 
8
    column while we are at it
 
9
*/
 
10
 
 
11
ALTER TABLE DistroReleaseQueue
 
12
    ADD COLUMN date_created timestamp WITHOUT TIME ZONE
 
13
    DEFAULT (CURRENT_TIMESTAMP AT TIME ZONE 'UTC');
 
14
 
 
15
-- Columns from DistroReleaseQueueSource
 
16
ALTER TABLE DistroReleaseQueue
 
17
    ADD COLUMN sourcepackagerelease integer REFERENCES SourcePackageRelease;
 
18
 
 
19
-- Columns from DistroReleaseQueueBuild
 
20
ALTER TABLE DistroReleaseQueue
 
21
    ADD COLUMN build integer REFERENCES Build;
 
22
 
 
23
-- Columns from DistroReleaseQueueCustom
 
24
ALTER TABLE DistroReleaseQueue
 
25
    ADD COLUMN customformat integer;
 
26
-- XXX: What should this column be called? libraryfilealias is not descriptive
 
27
ALTER TABLE DistroReleaseQueue
 
28
    ADD COLUMN upload integer REFERENCES LibraryFileAlias;
 
29
 
 
30
-- Migrate and set data
 
31
-- XXX: This is currently being calculated programmatically. We either
 
32
-- need to duplicate this in the database patch, or we need a post rollout
 
33
-- migration script that sets date_created corretly.
 
34
UPDATE DistroReleaseQueue SET date_created = DEFAULT;
 
35
UPDATE DistroReleaseQueue
 
36
    SET sourcepackagerelease=DistroReleaseQueueSource.sourcepackagerelease
 
37
    FROM DistroReleaseQueueSource
 
38
    WHERE DistroReleaseQueue.id = DistroReleaseQueueSource.distroreleasequeue;
 
39
UPDATE DistroReleaseQueue
 
40
    SET build=DistroReleaseQueueBuild.build
 
41
    FROM DistroReleaseQueueBuild
 
42
    WHERE DistroReleaseQueue.id = DistroReleaseQueueBuild.distroreleasequeue;
 
43
UPDATE DistroReleaseQueue
 
44
    SET customformat=custom.customformat, upload=custom.libraryfilealias
 
45
    FROM DistroReleaseQueueCustom AS custom
 
46
    WHERE DistroReleaseQueue.id = custom.distroreleasequeue;
 
47
 
 
48
-- Set NOT NULL flags and other constraints now data has been migrated
 
49
ALTER TABLE DistroReleaseQueue ALTER COLUMN date_created SET NOT NULL;
 
50
ALTER TABLE DistroReleaseQueue ADD CONSTRAINT valid_custom_upload
 
51
    CHECK (customformat IS NULL = upload IS NULL);
 
52
-- XXX: Is this constraint valid? It says that only one of
 
53
-- (sourcepackagerelease,build,upload) may be set.
 
54
ALTER TABLE DistroReleaseQueue ADD CONSTRAINT valid_source_upload CHECK (
 
55
    (sourcepackagerelease IS NOT NULL AND build IS NULL AND upload IS NULL) OR
 
56
    (sourcepackagerelease IS NULL AND build IS NOT NULL AND upload IS NULL) OR
 
57
    (sourcepackagerelease IS NULL AND build IS NULL AND upload IS NOT NULL)
 
58
    );
 
59
 
 
60
-- Add some indexes
 
61
CREATE INDEX distroreleasequeue__upload__idx ON DistroReleaseQueue(upload)
 
62
    WHERE upload IS NOT NULL;
 
63
-- XXX: How is DistroRelaseQueue accessed? We need to know this to
 
64
-- setup indexes correctly.
 
65
CREATE INDEX distroreleasequeue__status__idx ON DistroReleaseQueue(status);
 
66
 
 
67
INSERT INTO LaunchpadDatabaseRevision VALUES (40, 44, 0);