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