]> git.decadent.org.uk Git - dak.git/blob - setup/init_pool.sql
Stop using silly names, and migrate to a saner directory structure.
[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 );
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 queue (
105        id SERIAL PRIMARY KEY,
106        queue_name TEXT NOT NULL
107 );
108
109 CREATE TABLE suite_architectures (
110        suite INT4 NOT NULL, -- REFERENCES suite
111        architecture INT4 NOT NULL, -- REFERENCES architecture
112        unique (suite, architecture)
113 );
114
115 CREATE TABLE bin_associations (
116        id SERIAL PRIMARY KEY,
117        suite INT4 NOT NULL, -- REFERENCES suite
118        bin INT4 NOT NULL, -- REFERENCES binaries
119        unique (suite, bin)
120 );
121
122 CREATE TABLE src_associations (
123        id SERIAL PRIMARY KEY,
124        suite INT4 NOT NULL, -- REFERENCES suite
125        source INT4 NOT NULL, -- REFERENCES source
126        unique (suite, source)
127 );
128
129 CREATE TABLE section (
130        id SERIAL PRIMARY KEY,
131        section TEXT UNIQUE NOT NULL
132 );
133
134 CREATE TABLE priority (
135        id SERIAL PRIMARY KEY,
136        priority TEXT UNIQUE NOT NULL,
137        level INT4 UNIQUE NOT NULL
138 );
139
140 CREATE TABLE override_type (
141        id SERIAL PRIMARY KEY,
142        type TEXT UNIQUE NOT NULL
143 );
144
145 CREATE TABLE override (
146        package TEXT NOT NULL,
147        suite INT4 NOT NULL, -- references suite
148        component INT4 NOT NULL, -- references component
149        priority INT4, -- references priority
150        section INT4 NOT NULL, -- references section
151        type INT4 NOT NULL, -- references override_type
152        maintainer TEXT,
153        unique (suite, component, package, type)
154 );
155
156 CREATE TABLE queue_build (
157        suite INT4 NOT NULL, -- references suite
158        queue INT4 NOT NULL, -- references queue
159        filename TEXT NOT NULL,
160        in_queue BOOLEAN NOT NULL,
161        last_used TIMESTAMP
162 );
163
164 -- Critical indexes
165
166 CREATE INDEX bin_associations_bin ON bin_associations (bin);
167 CREATE INDEX src_associations_source ON src_associations (source);
168 CREATE INDEX source_maintainer ON source (maintainer);
169 CREATE INDEX binaries_maintainer ON binaries (maintainer);
170 CREATE INDEX binaries_fingerprint on binaries (sig_fpr);
171 CREATE INDEX source_fingerprint on source (sig_fpr);
172 CREATE INDEX dsc_files_file ON dsc_files (file);