]> git.donarmstrong.com Git - debbugs.git/blobdiff - sql/debbugs_schema.sql
remove useless primary keys in mapping tables
[debbugs.git] / sql / debbugs_schema.sql
index af98307b7d85959dba2131c894a941175c53a0cd..ea8446453cf4e861b4a30c4e9c99d79144679772 100644 (file)
@@ -4,6 +4,8 @@ DROP VIEW bug_package CASCADE;
 DROP VIEW binary_versions CASCADE;
 DROP TABLE bug_tag CASCADE;
 DROP TABLE tag CASCADE;
+DROP TABLE bug_user_tag CASCADE;
+DROP TABLE user_tag CASCADE;
 DROP TABLE severity CASCADE;
 DROP TABLE bug CASCADE;
 DROP TABLE src_pkg CASCADE;
@@ -169,16 +171,19 @@ INSERT INTO column_comments VALUES ('bug_merged','merged','Bug number which is m
 CREATE TABLE src_pkg (
        id SERIAL PRIMARY KEY,
        pkg TEXT NOT NULL,
-       pseduopkg BOOLEAN DEFAULT FALSE,
+       pseduopkg BOOLEAN NOT NULL DEFAULT FALSE,
        alias_of INT REFERENCES src_pkg ON UPDATE CASCADE ON DELETE CASCADE,
-       creation TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
-       disabled TIMESTAMP WITH TIME ZONE DEFAULT NULL,
-       last_modified TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
-       obsolete BOOLEAN DEFAULT FALSE,
+       creation TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
+       disabled TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT 'infinity'::timestamp with time zone,
+       last_modified TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
+       obsolete BOOLEAN NOT NULL DEFAULT FALSE,
        CONSTRAINT src_pkg_doesnt_alias_itself CHECK (id <> alias_of),
-       CONSTRAINT src_pkg_is_obsolete_if_disabled CHECK ((obsolete IS FALSE AND disabled IS NULL) OR (obsolete IS TRUE AND disabled IS NOT NULL))
+       CONSTRAINT src_pkg_is_obsolete_if_disabled CHECK (
+          (obsolete IS FALSE AND disabled='infinity'::timestamp with time zone) OR
+          (obsolete IS TRUE AND disabled < 'infinity'::timestamp with time zone))
 );
 CREATE INDEX src_pkg_pkg ON src_pkg(pkg);
+CREATE UNIQUE INDEX src_pkg_pkg_null ON src_pkg(pkg) WHERE disabled='infinity'::timestamp with time zone;
 CREATE UNIQUE INDEX src_pkg_pkg_disabled ON src_pkg(pkg,disabled);
 INSERT INTO table_comments VALUES ('src_pkg','Source packages');
 INSERT INTO column_comments VALUES ('src_pkg','id','Source package id');
@@ -270,7 +275,7 @@ CREATE TABLE bin_ver(
 );
 CREATE INDEX bin_ver_ver_idx ON bin_ver(ver);
 CREATE UNIQUE INDEX bin_ver_bin_pkg_id_arch_idx ON bin_ver(bin_pkg,arch,ver);
-CREATE UNIQUE INDEX bin_ver_src_ver_id_arch_idx ON bin_ver(src_ver,arch);
+CREATE INDEX bin_ver_src_ver_id_arch_idx ON bin_ver(src_ver,arch);
 CREATE INDEX bin_ver_bin_pkg_id_idx ON bin_ver(bin_pkg);
 CREATE INDEX bin_ver_src_ver_id_idx ON bin_ver(src_ver);
 INSERT INTO table_comments VALUES ('bin_ver','Binary versions');
@@ -291,7 +296,6 @@ INSERT INTO column_comments VALUES ('tag','tag','Tag name');
 INSERT INTO column_comments VALUES ('tag','obsolete','Whether a tag is obsolete (should not be set on new bugs)');
 
 CREATE TABLE bug_tag (
-       id SERIAL PRIMARY KEY,
        bug INT NOT NULL REFERENCES bug,
        tag INT NOT NULL REFERENCES tag
 );
@@ -303,10 +307,32 @@ CREATE UNIQUE INDEX bug_tag_bug_tag ON bug_tag (bug,tag);
 CREATE INDEX bug_tag_tag ON bug_tag (tag);
 CREATE INDEX bug_tag_bug ON bug_tag (bug);
 
+CREATE TABLE user_tag (
+       id SERIAL PRIMARY KEY,
+       tag TEXT NOT NULL,
+       correspondent INT NOT NULL REFERENCES correspondent(id)
+);
+INSERT INTO table_comments VALUES ('user_tag','User bug tags');
+INSERT INTO column_comments VALUES ('user_tag','id','User bug tag id');
+INSERT INTO column_comments VALUES ('user_tag','tag','User bug tag name');
+INSERT INTO column_comments VALUES ('user_tag','correspondent','User bug tag correspondent');
+
+CREATE UNIQUE INDEX user_tag_tag_correspondent ON user_tag(tag,correspondent);
+CREATE INDEX user_tag_correspondent ON user_tag(correspondent);
+
+CREATE TABLE bug_user_tag (
+       bug INT NOT NULL REFERENCES bug,
+       user_tag INT NOT NULL REFERENCES user_tag
+);
+INSERT INTO table_comments VALUES ('bug_user_tag','Bug <-> user tag mapping');
+INSERT INTO column_comments VALUES ('bug_user_tag','bug','Bug id (matches bug)');
+INSERT INTO column_comments VALUES ('bug_user_tag','tag','User tag id (matches user_tag)');
 
+CREATE UNIQUE INDEX bug_user_tag_bug_tag ON bug_user_tag (bug,user_tag);
+CREATE INDEX bug_user_tag_tag ON bug_user_tag (user_tag);
+CREATE INDEX bug_user_tag_bug ON bug_user_tag (bug);
 
 CREATE TABLE bug_binpackage (
-       id SERIAL PRIMARY KEY,
        bug INT NOT NULL REFERENCES bug,
        bin_pkg INT NOT NULL REFERENCES bin_pkg ON UPDATE CASCADE ON DELETE CASCADE
 );
@@ -316,7 +342,6 @@ INSERT INTO column_comments VALUES ('bug_binpackage','bug','Bug id (matches bug)
 INSERT INTO column_comments VALUES ('bug_binpackage','bin_pkg','Binary package id (matches bin_pkg)');
 
 CREATE TABLE bug_srcpackage (
-       id SERIAL PRIMARY KEY,
        bug INT NOT NULL REFERENCES bug,
        src_pkg INT NOT NULL REFERENCES src_pkg ON UPDATE CASCADE ON DELETE CASCADE
 );
@@ -333,7 +358,6 @@ CREATE VIEW bug_package (bug,pkg_id,pkg_type,package) AS
               SELECT s.bug,s.src_pkg,'source',sp.pkg FROM bug_srcpackage s JOIN src_pkg sp ON sp.id=s.src_pkg;
 
 CREATE TABLE bug_affects_binpackage (
-       id SERIAL PRIMARY KEY,
        bug INT NOT NULL REFERENCES bug,
        bin_pkg INT NOT NULL REFERENCES bin_pkg ON UPDATE CASCADE ON DELETE CASCADE
 );
@@ -343,7 +367,6 @@ INSERT INTO column_comments VALUES ('bug_affects_binpackage','bug','Bug id (matc
 INSERT INTO column_comments VALUES ('bug_affects_binpackage','bin_pkg','Binary package id (matches bin_pkg)');
 
 CREATE TABLE bug_affects_srcpackage (
-       id SERIAL PRIMARY KEY,
        bug INT NOT NULL REFERENCES bug,
        src_pkg INT NOT NULL REFERENCES src_pkg ON UPDATE CASCADE ON DELETE CASCADE
 );
@@ -364,18 +387,18 @@ CREATE VIEW binary_versions (src_pkg, src_ver, bin_pkg, arch, bin_ver) AS
 
 CREATE TABLE suite (
        id SERIAL PRIMARY KEY,
-       suite_name TEXT NOT NULL,
+       codename TEXT NOT NULL,
+       suite_name TEXT,
        version TEXT,
-       codename TEXT,
        active BOOLEAN DEFAULT TRUE);
+CREATE UNIQUE INDEX suite_idx_codename ON suite(codename);
 CREATE UNIQUE INDEX suite_suite_name_key ON suite(suite_name);
-CREATE INDEX suite_idx_codename ON suite(codename);
-CREATE INDEX suite_idx_version ON suite(version);
+CREATE UNIQUE INDEX suite_idx_version ON suite(version);
 INSERT INTO table_comments VALUES ('suite','Debian Release Suite (stable, testing, etc.)');
 INSERT INTO column_comments VALUES ('suite','id','Suite id');
-INSERT INTO column_comments VALUES ('suite','suite_name','Suite name');
+INSERT INTO column_comments VALUES ('suite','suite_name','Suite name (testing, stable, etc.)');
 INSERT INTO column_comments VALUES ('suite','version','Suite version; NULL if there is no appropriate version');
-INSERT INTO column_comments VALUES ('suite','codename','Suite codename');
+INSERT INTO column_comments VALUES ('suite','codename','Suite codename (sid, squeeze, etc.)');
 INSERT INTO column_comments VALUES ('suite','active','TRUE if the suite is still accepting uploads');
 
 CREATE TABLE bin_associations (
@@ -391,6 +414,7 @@ INSERT INTO column_comments VALUES ('bin_associations','suite','Suite id (matche
 INSERT INTO column_comments VALUES ('bin_associations','bin','Binary version id (matches bin_ver)');
 INSERT INTO column_comments VALUES ('bin_associations','created','Time this binary package entered this suite');
 INSERT INTO column_comments VALUES ('bin_associations','modified','Time this entry was modified');
+CREATE UNIQUE INDEX bin_associations_bin_suite ON bin_associations(bin,suite);
 
 CREATE TABLE src_associations (
        id SERIAL PRIMARY KEY,
@@ -405,12 +429,11 @@ INSERT INTO column_comments VALUES ('src_associations','suite','Suite id (matche
 INSERT INTO column_comments VALUES ('src_associations','source','Source version id (matches src_ver)');
 INSERT INTO column_comments VALUES ('src_associations','created','Time this source package entered this suite');
 INSERT INTO column_comments VALUES ('src_associations','modified','Time this entry was modified');
-
+CREATE UNIQUE INDEX src_associations_source_suite ON src_associations(source,suite);
 
 
 CREATE TYPE bug_status_type AS ENUM ('pending','forwarded','pending-fixed','fixed','absent','done');
 CREATE TABLE bug_status_cache (
-       id SERIAL PRIMARY KEY,
        bug INT NOT NULL REFERENCES bug ON DELETE CASCADE ON UPDATE CASCADE,
        suite INT REFERENCES suite ON DELETE CASCADE ON UPDATE CASCADE,
        arch INT REFERENCES arch ON DELETE CASCADE ON UPDATE CASCADE,
@@ -423,14 +446,14 @@ CREATE INDEX bug_status_cache_idx_bug ON bug_status_cache(bug);
 CREATE INDEX bug_status_cache_idx_status ON bug_status_cache(status);
 CREATE INDEX bug_status_cache_idx_arch ON bug_status_cache(arch);
 CREATE INDEX bug_status_cache_idx_suite ON bug_status_cache(suite);
-INSERT INTO table_comments  VALUES ('bug_status_cache','Source <-> suite associations');
-INSERT INTO column_comments VALUES ('bug_status_cache','id','Source <-> suite association id');
-INSERT INTO column_comments VALUES ('bug_status_cache','bug','Source <-> suite association id');
-INSERT INTO column_comments VALUES ('bug_status_cache','suite','Source <-> suite association id');
-INSERT INTO column_comments VALUES ('bug_status_cache','arch','Source <-> suite association id');
-INSERT INTO column_comments VALUES ('bug_status_cache','status','Source <-> suite association id');
-INSERT INTO column_comments VALUES ('bug_status_cache','modified','Source <-> suite association id');
-INSERT INTO column_comments VALUES ('bug_status_cache','asof','Source <-> suite association id');
+INSERT INTO table_comments  VALUES ('bug_status_cache','Bug Status Cache');
+INSERT INTO column_comments VALUES ('bug_status_cache','id','Bug status cache entry id');
+INSERT INTO column_comments VALUES ('bug_status_cache','bug','Bug number (matches bug)');
+INSERT INTO column_comments VALUES ('bug_status_cache','suite','Suite id (matches suite)');
+INSERT INTO column_comments VALUES ('bug_status_cache','arch','Architecture id (matches arch)');
+INSERT INTO column_comments VALUES ('bug_status_cache','status','Status (bug status)');
+INSERT INTO column_comments VALUES ('bug_status_cache','modified','Time that this status was last modified');
+INSERT INTO column_comments VALUES ('bug_status_cache','asof','Time that this status was last calculated');
 
 
 
@@ -465,7 +488,6 @@ CREATE UNIQUE INDEX message_msgid_from_complete_to_complete_subject_idx
 CREATE INDEX message_subject_idx ON message(subject);
 
 CREATE TABLE message_refs (
-       id SERIAL PRIMARY KEY,
        message INT NOT NULL REFERENCES message ON DELETE CASCADE ON UPDATE CASCADE,
        refs INT NOT NULL REFERENCES message ON DELETE CASCADE ON UPDATE CASCADE,
        inferred BOOLEAN DEFAULT FALSE,
@@ -501,7 +523,6 @@ INSERT INTO column_comments VALUES ('correspondent_full_name','full_name','Corre
 CREATE TYPE message_correspondent_type AS ENUM ('to','from','envfrom','cc');
 
 CREATE TABLE message_correspondent (
-       id SERIAL PRIMARY KEY,
        message INT NOT NULL REFERENCES message ON DELETE CASCADE ON UPDATE CASCADE,
        correspondent INT NOT NULL REFERENCES correspondent ON DELETE CASCADE ON UPDATE CASCADE,
        correspondent_type message_correspondent_type NOT NULL DEFAULT 'to'
@@ -517,7 +538,6 @@ CREATE INDEX message_correspondent_idx_correspondent ON message_correspondent(co
 CREATE INDEX message_correspondent_idx_message ON message_correspondent(message);
 
 CREATE TABLE bug_message (
-       id SERIAL PRIMARY KEY,
        bug INT NOT NULL REFERENCES bug ON DELETE CASCADE ON UPDATE CASCADE,
        message INT NOT NULL REFERENCES message ON DELETE CASCADE ON UPDATE CASCADE,
        message_number INT NOT NULL,