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