]> git.decadent.org.uk Git - dak.git/blob - init_pool.sql
two bug fixes in source_exists changes
[dak.git] / init_pool.sql
1 DROP DATABASE projectb;
2 CREATE DATABASE projectb WITH ENCODING = 'SQL_ASCII';
3
4 \c projectb
5
6 CREATE TABLE archive (
7        id SERIAL PRIMARY KEY,
8        name TEXT UNIQUE NOT NULL,
9        origin_server TEXT,
10        description TEXT
11 );
12
13 CREATE TABLE component (
14        id SERIAL PRIMARY KEY,
15        name TEXT UNIQUE NOT NULL,
16        description TEXT,
17        meets_dfsg BOOLEAN
18 );
19
20 CREATE TABLE architecture (
21        id SERIAL PRIMARY KEY,
22        arch_string TEXT UNIQUE NOT NULL,
23        description TEXT
24 );
25
26 CREATE TABLE maintainer (
27        id SERIAL PRIMARY KEY,
28        name TEXT UNIQUE NOT NULL
29 );
30
31 CREATE TABLE uid (
32        id SERIAL PRIMARY KEY,
33        uid TEXT UNIQUE NOT NULL
34 );
35
36 CREATE TABLE fingerprint (
37        id SERIAL PRIMARY KEY,
38        fingerprint TEXT UNIQUE NOT NULL,
39        uid INT4 REFERENCES uid
40 );
41
42 CREATE TABLE location (
43        id SERIAL PRIMARY KEY,
44        path TEXT NOT NULL,
45        component INT4 REFERENCES component,
46        archive INT4 REFERENCES archive,
47        type TEXT NOT NULL
48 );
49
50 -- No references below here to allow sane population; added post-population
51
52 CREATE TABLE files (
53        id SERIAL PRIMARY KEY,
54        filename TEXT NOT NULL,
55        size INT8 NOT NULL,
56        md5sum TEXT NOT NULL,
57        location INT4 NOT NULL, -- REFERENCES location
58        last_used TIMESTAMP,
59        unique (filename, location)
60 );
61
62 CREATE TABLE source (
63         id SERIAL PRIMARY KEY,
64         source TEXT NOT NULL,
65         version TEXT NOT NULL,
66         maintainer INT4 NOT NULL, -- REFERENCES maintainer
67         file INT4 UNIQUE NOT NULL, -- REFERENCES files
68         install_date TIMESTAMP NOT NULL,
69         sig_fpr INT4 NOT NULL, -- REFERENCES fingerprint
70         unique (source, version)
71 );
72
73 CREATE TABLE dsc_files (
74        id SERIAL PRIMARY KEY,
75        source INT4 NOT NULL, -- REFERENCES source,
76        file INT4 NOT NULL, -- RERENCES files
77        unique (source, file)
78 );
79
80 CREATE TABLE binaries (
81        id SERIAL PRIMARY KEY,
82        package TEXT NOT NULL,
83        version TEXT NOT NULL,
84        maintainer INT4 NOT NULL, -- REFERENCES maintainer
85        source INT4, -- REFERENCES source,
86        architecture INT4 NOT NULL, -- REFERENCES architecture
87        file INT4 UNIQUE NOT NULL, -- REFERENCES files,
88        type TEXT NOT NULL,
89 -- joeyh@ doesn't want .udebs and .debs with the same name, which is why the unique () doesn't mention type
90        sig_fpr INT4 NOT NULL, -- REFERENCES fingerprint
91        unique (package, version, architecture)
92 );
93
94 CREATE TABLE suite (
95        id SERIAL PRIMARY KEY,
96        suite_name TEXT NOT NULL,
97        version TEXT,
98        origin TEXT,
99        label TEXT,
100        policy_engine TEXT,
101        description TEXT
102 );
103
104 CREATE TABLE suite_architectures (
105        suite INT4 NOT NULL, -- REFERENCES suite
106        architecture INT4 NOT NULL, -- REFERENCES architecture
107        unique (suite, architecture)
108 );
109
110 CREATE TABLE bin_associations (
111        id SERIAL PRIMARY KEY,
112        suite INT4 NOT NULL, -- REFERENCES suite
113        bin INT4 NOT NULL, -- REFERENCES binaries
114        unique (suite, bin)
115 );
116
117 CREATE TABLE src_associations (
118        id SERIAL PRIMARY KEY,
119        suite INT4 NOT NULL, -- REFERENCES suite
120        source INT4 NOT NULL, -- REFERENCES source
121        unique (suite, source)
122 );
123
124 CREATE TABLE section (
125        id SERIAL PRIMARY KEY,
126        section TEXT UNIQUE NOT NULL
127 );
128
129 CREATE TABLE priority (
130        id SERIAL PRIMARY KEY,
131        priority TEXT UNIQUE NOT NULL,
132        level INT4 UNIQUE NOT NULL
133 );
134
135 CREATE TABLE override_type (
136        id SERIAL PRIMARY KEY,
137        type TEXT UNIQUE NOT NULL
138 );
139
140 CREATE TABLE override (
141        package TEXT NOT NULL,
142        suite INT4 NOT NULL, -- references suite
143        component INT4 NOT NULL, -- references component
144        priority INT4, -- references priority
145        section INT4 NOT NULL, -- references section
146        type INT4 NOT NULL, -- references override_type
147        maintainer TEXT,
148        unique (suite, component, package, type)
149 );
150
151 CREATE TABLE accepted_autobuild (
152        suite INT4 NOT NULL, -- references suite
153        filename TEXT NOT NULL,
154        in_accepted BOOLEAN NOT NULL,
155        last_used TIMESTAMP
156 );
157
158 -- Critical indexes
159
160 CREATE INDEX bin_associations_bin ON bin_associations (bin);
161 CREATE INDEX src_associations_source ON src_associations (source);
162 CREATE INDEX source_maintainer ON source (maintainer);
163 CREATE INDEX binaries_maintainer ON binaries (maintainer);
164 CREATE INDEX binaries_fingerprint on binaries (sig_fpr);
165 CREATE INDEX source_fingerprint on source (sig_fpr);
166 CREATE INDEX dsc_files_file ON dsc_files (file);