]> git.decadent.org.uk Git - dak.git/blob - setup/init_pool.sql
Merge commit 'mhy/checksums'
[dak.git] / setup / 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 src_uploaders (
32        id SERIAL PRIMARY KEY,
33        source INT4 NOT NULL REFERENCES source,
34        maintainer INT4 NOT NULL REFERENCES maintainer
35 );
36
37 CREATE TABLE uid (
38        id SERIAL PRIMARY KEY,
39        uid TEXT UNIQUE NOT NULL,
40        name TEXT
41 );
42
43 CREATE TABLE keyrings (
44        id SERIAL PRIMARY KEY,
45        name TEXT
46 );
47
48
49 CREATE TABLE fingerprint (
50        id SERIAL PRIMARY KEY,
51        fingerprint TEXT UNIQUE NOT NULL,
52        uid INT4 REFERENCES uid,
53        keyring INT4 REFERENCES keyrings
54 );
55
56 CREATE TABLE location (
57        id SERIAL PRIMARY KEY,
58        path TEXT NOT NULL,
59        component INT4 REFERENCES component,
60        archive INT4 REFERENCES archive,
61        type TEXT NOT NULL
62 );
63
64 -- No references below here to allow sane population; added post-population
65
66 CREATE TABLE files (
67        id SERIAL PRIMARY KEY,
68        filename TEXT NOT NULL,
69        size INT8 NOT NULL,
70        md5sum TEXT NOT NULL,
71        location INT4 NOT NULL, -- REFERENCES location
72        last_used TIMESTAMP,
73        sha1sum TEXT NOT NULL,
74        sha256sum TEXT NOT NULL,
75        unique (filename, location)
76 );
77
78 CREATE TABLE source (
79         id SERIAL PRIMARY KEY,
80         source TEXT NOT NULL,
81         version TEXT NOT NULL,
82         maintainer INT4 NOT NULL, -- REFERENCES maintainer
83         changedby INT4 NOT NULL, -- REFERENCES maintainer
84         file INT4 UNIQUE NOT NULL, -- REFERENCES files
85         install_date TIMESTAMP NOT NULL,
86         sig_fpr INT4 NOT NULL, -- REFERENCES fingerprint
87         unique (source, version)
88 );
89
90 CREATE TABLE src_uploaders (
91        id SERIAL PRIMARY KEY,
92        source INT4 NOT NULL REFERENCES source,
93        maintainer INT4 NOT NULL REFERENCES maintainer
94 );
95
96 CREATE TABLE dsc_files (
97        id SERIAL PRIMARY KEY,
98        source INT4 NOT NULL, -- REFERENCES source,
99        file INT4 NOT NULL, -- RERENCES files
100        unique (source, file)
101 );
102
103 CREATE TABLE binaries (
104        id SERIAL PRIMARY KEY,
105        package TEXT NOT NULL,
106        version TEXT NOT NULL,
107        maintainer INT4 NOT NULL, -- REFERENCES maintainer
108        source INT4, -- REFERENCES source,
109        architecture INT4 NOT NULL, -- REFERENCES architecture
110        file INT4 UNIQUE NOT NULL, -- REFERENCES files,
111        type TEXT NOT NULL,
112 -- joeyh@ doesn't want .udebs and .debs with the same name, which is why the unique () doesn't mention type
113        sig_fpr INT4 NOT NULL, -- REFERENCES fingerprint
114        unique (package, version, architecture)
115 );
116
117 CREATE TABLE suite (
118        id SERIAL PRIMARY KEY,
119        suite_name TEXT NOT NULL,
120        version TEXT,
121        origin TEXT,
122        label TEXT,
123        policy_engine TEXT,
124        description TEXT
125 );
126
127 CREATE TABLE queue (
128        id SERIAL PRIMARY KEY,
129        queue_name TEXT NOT NULL
130 );
131
132 CREATE TABLE suite_architectures (
133        suite INT4 NOT NULL, -- REFERENCES suite
134        architecture INT4 NOT NULL, -- REFERENCES architecture
135        unique (suite, architecture)
136 );
137
138 CREATE TABLE bin_associations (
139        id SERIAL PRIMARY KEY,
140        suite INT4 NOT NULL, -- REFERENCES suite
141        bin INT4 NOT NULL, -- REFERENCES binaries
142        unique (suite, bin)
143 );
144
145 CREATE TABLE src_associations (
146        id SERIAL PRIMARY KEY,
147        suite INT4 NOT NULL, -- REFERENCES suite
148        source INT4 NOT NULL, -- REFERENCES source
149        unique (suite, source)
150 );
151
152 CREATE TABLE section (
153        id SERIAL PRIMARY KEY,
154        section TEXT UNIQUE NOT NULL
155 );
156
157 CREATE TABLE priority (
158        id SERIAL PRIMARY KEY,
159        priority TEXT UNIQUE NOT NULL,
160        level INT4 UNIQUE NOT NULL
161 );
162
163 CREATE TABLE override_type (
164        id SERIAL PRIMARY KEY,
165        type TEXT UNIQUE NOT NULL
166 );
167
168 CREATE TABLE override (
169        package TEXT NOT NULL,
170        suite INT4 NOT NULL, -- references suite
171        component INT4 NOT NULL, -- references component
172        priority INT4, -- references priority
173        section INT4 NOT NULL, -- references section
174        type INT4 NOT NULL, -- references override_type
175        maintainer TEXT,
176        unique (suite, component, package, type)
177 );
178
179 CREATE TABLE queue_build (
180        suite INT4 NOT NULL, -- references suite
181        queue INT4 NOT NULL, -- references queue
182        filename TEXT NOT NULL,
183        in_queue BOOLEAN NOT NULL,
184        last_used TIMESTAMP
185 );
186
187 -- Critical indexes
188
189 CREATE INDEX bin_associations_bin ON bin_associations (bin);
190 CREATE INDEX src_associations_source ON src_associations (source);
191 CREATE INDEX source_maintainer ON source (maintainer);
192 CREATE INDEX binaries_maintainer ON binaries (maintainer);
193 CREATE INDEX binaries_fingerprint on binaries (sig_fpr);
194 CREATE INDEX source_fingerprint on source (sig_fpr);
195 CREATE INDEX dsc_files_file ON dsc_files (file);
196
197 -- Own function
198 CREATE FUNCTION space_concat(text, text) RETURNS text
199     AS $_$select case
200 WHEN $2 is null or $2 = '' THEN $1
201 WHEN $1 is null or $1 = '' THEN $2
202 ELSE $1 || ' ' || $2
203 END$_$
204     LANGUAGE sql;
205
206 CREATE AGGREGATE space_separated_list (
207     BASETYPE = text,
208     SFUNC = space_concat,
209     STYPE = text,
210     INITCOND = ''
211 );