1 -- Fix up after population of the database...
3 -- First of all readd the constraints (takes ~1:30 on auric)
5 ALTER TABLE files ADD CONSTRAINT files_location FOREIGN KEY (location) REFERENCES location(id) MATCH FULL;
7 ALTER TABLE source ADD CONSTRAINT source_maintainer FOREIGN KEY (maintainer) REFERENCES maintainer(id) MATCH FULL;
8 ALTER TABLE source ADD CONSTRAINT source_changedby FOREIGN KEY (changedby) REFERENCES maintainer(id) MATCH FULL;
9 ALTER TABLE source ADD CONSTRAINT source_file FOREIGN KEY (file) REFERENCES files(id) MATCH FULL;
10 ALTER TABLE source ADD CONSTRAINT source_sig_fpr FOREIGN KEY (sig_fpr) REFERENCES fingerprint(id) MATCH FULL;
12 ALTER TABLE dsc_files ADD CONSTRAINT dsc_files_source FOREIGN KEY (source) REFERENCES source(id) MATCH FULL;
13 ALTER TABLE dsc_files ADD CONSTRAINT dsc_files_file FOREIGN KEY (file) REFERENCES files(id) MATCH FULL;
15 ALTER TABLE binaries ADD CONSTRAINT binaries_maintainer FOREIGN KEY (maintainer) REFERENCES maintainer(id) MATCH FULL;
16 ALTER TABLE binaries ADD CONSTRAINT binaries_source FOREIGN KEY (source) REFERENCES source(id) MATCH FULL;
17 ALTER TABLE binaries ADD CONSTRAINT binaries_architecture FOREIGN KEY (architecture) REFERENCES architecture(id) MATCH FULL;
18 ALTER TABLE binaries ADD CONSTRAINT binaries_file FOREIGN KEY (file) REFERENCES files(id) MATCH FULL;
19 ALTER TABLE binaries ADD CONSTRAINT binaries_sig_fpr FOREIGN KEY (sig_fpr) REFERENCES fingerprint(id) MATCH FULL;
21 ALTER TABLE suite_architectures ADD CONSTRAINT suite_architectures_suite FOREIGN KEY (suite) REFERENCES suite(id) MATCH FULL;
22 ALTER TABLE suite_architectures ADD CONSTRAINT suite_architectures_architecture FOREIGN KEY (architecture) REFERENCES architecture(id) MATCH FULL;
24 ALTER TABLE bin_associations ADD CONSTRAINT bin_associations_suite FOREIGN KEY (suite) REFERENCES suite(id) MATCH FULL;
25 ALTER TABLE bin_associations ADD CONSTRAINT bin_associations_bin FOREIGN KEY (bin) REFERENCES binaries(id) MATCH FULL;
27 ALTER TABLE src_associations ADD CONSTRAINT src_associations_suite FOREIGN KEY (suite) REFERENCES suite(id) MATCH FULL;
28 ALTER TABLE src_associations ADD CONSTRAINT src_associations_source FOREIGN KEY (source) REFERENCES source(id) MATCH FULL;
30 ALTER TABLE override ADD CONSTRAINT override_suite FOREIGN KEY (suite) REFERENCES suite(id) MATCH FULL;
31 ALTER TABLE override ADD CONSTRAINT override_component FOREIGN KEY (component) REFERENCES component(id) MATCH FULL;
32 ALTER TABLE override ADD CONSTRAINT override_priority FOREIGN KEY (priority) REFERENCES priority(id) MATCH FULL;
33 ALTER TABLE override ADD CONSTRAINT override_section FOREIGN KEY (section) REFERENCES section(id) MATCH FULL;
34 ALTER TABLE override ADD CONSTRAINT override_type FOREIGN KEY (type) REFERENCES override_type(id) MATCH FULL;
36 ALTER TABLE queue_build ADD CONSTRAINT queue_build_suite FOREIGN KEY (suite) REFERENCES suite(id) MATCH FULL;
37 ALTER TABLE queue_build ADD CONSTRAINT queue_build_queue FOREIGN KEY (queue) REFERENCES queue(id) MATCH FULL;
39 -- Then correct all the id SERIAL PRIMARY KEY columns...
41 CREATE FUNCTION files_id_max() RETURNS INT4
42 AS 'SELECT max(id) FROM files'
44 CREATE FUNCTION source_id_max() RETURNS INT4
45 AS 'SELECT max(id) FROM source'
47 CREATE FUNCTION src_associations_id_max() RETURNS INT4
48 AS 'SELECT max(id) FROM src_associations'
50 CREATE FUNCTION dsc_files_id_max() RETURNS INT4
51 AS 'SELECT max(id) FROM dsc_files'
53 CREATE FUNCTION binaries_id_max() RETURNS INT4
54 AS 'SELECT max(id) FROM binaries'
56 CREATE FUNCTION bin_associations_id_max() RETURNS INT4
57 AS 'SELECT max(id) FROM bin_associations'
59 CREATE FUNCTION section_id_max() RETURNS INT4
60 AS 'SELECT max(id) FROM section'
62 CREATE FUNCTION priority_id_max() RETURNS INT4
63 AS 'SELECT max(id) FROM priority'
65 CREATE FUNCTION override_type_id_max() RETURNS INT4
66 AS 'SELECT max(id) FROM override_type'
68 CREATE FUNCTION maintainer_id_max() RETURNS INT4
69 AS 'SELECT max(id) FROM maintainer'
72 SELECT setval('files_id_seq', files_id_max());
73 SELECT setval('source_id_seq', source_id_max());
74 SELECT setval('src_associations_id_seq', src_associations_id_max());
75 SELECT setval('dsc_files_id_seq', dsc_files_id_max());
76 SELECT setval('binaries_id_seq', binaries_id_max());
77 SELECT setval('bin_associations_id_seq', bin_associations_id_max());
78 SELECT setval('section_id_seq', section_id_max());
79 SELECT setval('priority_id_seq', priority_id_max());
80 SELECT setval('override_type_id_seq', override_type_id_max());
81 SELECT setval('maintainer_id_seq', maintainer_id_max());
83 -- Vacuum the tables for efficency
95 VACUUM suite_architectures;
96 VACUUM bin_associations;
97 VACUUM src_associations;
100 VACUUM override_type;
103 -- FIXME: has to be a better way to do this
104 GRANT ALL ON architecture, architecture_id_seq, archive,
105 archive_id_seq, bin_associations, bin_associations_id_seq, binaries,
106 binaries_id_seq, component, component_id_seq, dsc_files,
107 dsc_files_id_seq, files, files_id_seq, fingerprint,
108 fingerprint_id_seq, keyrings, keyrings_id_seq,
109 location, location_id_seq, maintainer,
110 maintainer_id_seq, override, override_type, override_type_id_seq,
111 priority, priority_id_seq, section, section_id_seq, source,
112 source_id_seq, src_uploaders, src_uploaders_id_seq,
113 src_associations, src_associations_id_seq, suite,
114 suite_architectures, suite_id_seq, queue_build, uid,
115 uid_id_seq TO GROUP ftpmaster;
117 -- Read only access to user 'nobody'
118 GRANT SELECT ON architecture, architecture_id_seq, archive,
119 archive_id_seq, bin_associations, bin_associations_id_seq, binaries,
120 binaries_id_seq, component, component_id_seq, dsc_files,
121 dsc_files_id_seq, files, files_id_seq, fingerprint,
122 fingerprint_id_seq, keyrings, keyrings_id_seq,
123 location, location_id_seq, maintainer,
124 maintainer_id_seq, override, override_type, override_type_id_seq,
125 priority, priority_id_seq, section, section_id_seq, source,
126 source_id_seq, src_uploaders, src_uploaders_id_seq,
127 src_associations, src_associations_id_seq, suite,
128 suite_architectures, suite_id_seq, queue_build, uid,
129 uid_id_seq TO PUBLIC;