]> git.decadent.org.uk Git - dak.git/blob - setup/init_pool.sql
Merged from ftpmaster
[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        unique (filename, location)
74 );
75
76 CREATE TABLE source (
77         id SERIAL PRIMARY KEY,
78         source TEXT NOT NULL,
79         version TEXT NOT NULL,
80         maintainer INT4 NOT NULL, -- REFERENCES maintainer
81         changedby INT4 NOT NULL, -- REFERENCES maintainer
82         file INT4 UNIQUE NOT NULL, -- REFERENCES files
83         install_date TIMESTAMP NOT NULL,
84         sig_fpr INT4 NOT NULL, -- REFERENCES fingerprint
85         unique (source, version)
86 );
87
88 CREATE TABLE src_uploaders (
89        id SERIAL PRIMARY KEY,
90        source INT4 NOT NULL REFERENCES source,
91        maintainer INT4 NOT NULL REFERENCES maintainer
92 );
93
94 CREATE TABLE dsc_files (
95        id SERIAL PRIMARY KEY,
96        source INT4 NOT NULL, -- REFERENCES source,
97        file INT4 NOT NULL, -- RERENCES files
98        unique (source, file)
99 );
100
101 CREATE TABLE binaries (
102        id SERIAL PRIMARY KEY,
103        package TEXT NOT NULL,
104        version TEXT NOT NULL,
105        maintainer INT4 NOT NULL, -- REFERENCES maintainer
106        source INT4, -- REFERENCES source,
107        architecture INT4 NOT NULL, -- REFERENCES architecture
108        file INT4 UNIQUE NOT NULL, -- REFERENCES files,
109        type TEXT NOT NULL,
110 -- joeyh@ doesn't want .udebs and .debs with the same name, which is why the unique () doesn't mention type
111        sig_fpr INT4 NOT NULL, -- REFERENCES fingerprint
112        unique (package, version, architecture)
113 );
114
115 CREATE TABLE suite (
116        id SERIAL PRIMARY KEY,
117        suite_name TEXT NOT NULL,
118        version TEXT,
119        origin TEXT,
120        label TEXT,
121        policy_engine TEXT,
122        description TEXT
123 );
124
125 CREATE TABLE queue (
126        id SERIAL PRIMARY KEY,
127        queue_name TEXT NOT NULL
128 );
129
130 CREATE TABLE suite_architectures (
131        suite INT4 NOT NULL, -- REFERENCES suite
132        architecture INT4 NOT NULL, -- REFERENCES architecture
133        unique (suite, architecture)
134 );
135
136 CREATE TABLE bin_associations (
137        id SERIAL PRIMARY KEY,
138        suite INT4 NOT NULL, -- REFERENCES suite
139        bin INT4 NOT NULL, -- REFERENCES binaries
140        unique (suite, bin)
141 );
142
143 CREATE TABLE src_associations (
144        id SERIAL PRIMARY KEY,
145        suite INT4 NOT NULL, -- REFERENCES suite
146        source INT4 NOT NULL, -- REFERENCES source
147        unique (suite, source)
148 );
149
150 CREATE TABLE section (
151        id SERIAL PRIMARY KEY,
152        section TEXT UNIQUE NOT NULL
153 );
154
155 CREATE TABLE priority (
156        id SERIAL PRIMARY KEY,
157        priority TEXT UNIQUE NOT NULL,
158        level INT4 UNIQUE NOT NULL
159 );
160
161 CREATE TABLE override_type (
162        id SERIAL PRIMARY KEY,
163        type TEXT UNIQUE NOT NULL
164 );
165
166 CREATE TABLE override (
167        package TEXT NOT NULL,
168        suite INT4 NOT NULL, -- references suite
169        component INT4 NOT NULL, -- references component
170        priority INT4, -- references priority
171        section INT4 NOT NULL, -- references section
172        type INT4 NOT NULL, -- references override_type
173        maintainer TEXT,
174        unique (suite, component, package, type)
175 );
176
177 CREATE TABLE queue_build (
178        suite INT4 NOT NULL, -- references suite
179        queue INT4 NOT NULL, -- references queue
180        filename TEXT NOT NULL,
181        in_queue BOOLEAN NOT NULL,
182        last_used TIMESTAMP
183 );
184
185 -- Critical indexes
186
187 CREATE INDEX bin_associations_bin ON bin_associations (bin);
188 CREATE INDEX src_associations_source ON src_associations (source);
189 CREATE INDEX source_maintainer ON source (maintainer);
190 CREATE INDEX binaries_maintainer ON binaries (maintainer);
191 CREATE INDEX binaries_fingerprint on binaries (sig_fpr);
192 CREATE INDEX source_fingerprint on source (sig_fpr);
193 CREATE INDEX dsc_files_file ON dsc_files (file);
194
195 -- Own function
196 CREATE FUNCTION space_concat(text, text) RETURNS text
197     AS $_$select case
198 WHEN $2 is null or $2 = '' THEN $1
199 WHEN $1 is null or $1 = '' THEN $2
200 ELSE $1 || ' ' || $2
201 END$_$
202     LANGUAGE sql;
203
204 CREATE AGGREGATE space_separated_list (
205     BASETYPE = text,
206     SFUNC = space_concat,
207     STYPE = text,
208     INITCOND = ''
209 );