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_file FOREIGN KEY (file) REFERENCES files(id) MATCH FULL;
10 ALTER TABLE dsc_files ADD CONSTRAINT dsc_files_source FOREIGN KEY (source) REFERENCES source(id) MATCH FULL;
11 ALTER TABLE dsc_files ADD CONSTRAINT dsc_files_file FOREIGN KEY (file) REFERENCES files(id) MATCH FULL;
13 ALTER TABLE binaries ADD CONSTRAINT binaries_maintainer FOREIGN KEY (maintainer) REFERENCES maintainer(id) MATCH FULL;
14 ALTER TABLE binaries ADD CONSTRAINT binaries_source FOREIGN KEY (source) REFERENCES source(id) MATCH FULL;
15 ALTER TABLE binaries ADD CONSTRAINT binaries_architecture FOREIGN KEY (architecture) REFERENCES architecture(id) MATCH FULL;
16 ALTER TABLE binaries ADD CONSTRAINT binaries_file FOREIGN KEY (file) REFERENCES files(id) MATCH FULL;
18 ALTER TABLE suite_architectures ADD CONSTRAINT suite_architectures_suite FOREIGN KEY (suite) REFERENCES suite(id) MATCH FULL;
19 ALTER TABLE suite_architectures ADD CONSTRAINT suite_architectures_architecture FOREIGN KEY (architecture) REFERENCES architecture(id) MATCH FULL;
21 ALTER TABLE bin_associations ADD CONSTRAINT bin_associations_suite FOREIGN KEY (suite) REFERENCES suite(id) MATCH FULL;
22 ALTER TABLE bin_associations ADD CONSTRAINT bin_associations_bin FOREIGN KEY (bin) REFERENCES binaries(id) MATCH FULL;
24 ALTER TABLE src_associations ADD CONSTRAINT src_associations_suite FOREIGN KEY (suite) REFERENCES suite(id) MATCH FULL;
25 ALTER TABLE src_associations ADD CONSTRAINT src_associations_source FOREIGN KEY (source) REFERENCES source(id) MATCH FULL;
27 ALTER TABLE override ADD CONSTRAINT override_suite FOREIGN KEY (suite) REFERENCES suite(id) MATCH FULL;
28 ALTER TABLE override ADD CONSTRAINT override_component FOREIGN KEY (component) REFERENCES component(id) MATCH FULL;
29 ALTER TABLE override ADD CONSTRAINT override_priority FOREIGN KEY (priority) REFERENCES priority(id) MATCH FULL;
30 ALTER TABLE override ADD CONSTRAINT override_section FOREIGN KEY (section) REFERENCES section(id) MATCH FULL;
31 ALTER TABLE override ADD CONSTRAINT override_type FOREIGN KEY (type) REFERENCES override_type(id) MATCH FULL;
33 -- Then correct all the id SERIAL PRIMARY KEY columns...
35 CREATE FUNCTION files_id_max() RETURNS INT4
36 AS 'SELECT max(id) FROM files'
38 CREATE FUNCTION source_id_max() RETURNS INT4
39 AS 'SELECT max(id) FROM source'
41 CREATE FUNCTION src_associations_id_max() RETURNS INT4
42 AS 'SELECT max(id) FROM src_associations'
44 CREATE FUNCTION dsc_files_id_max() RETURNS INT4
45 AS 'SELECT max(id) FROM dsc_files'
47 CREATE FUNCTION binaries_id_max() RETURNS INT4
48 AS 'SELECT max(id) FROM binaries'
50 CREATE FUNCTION bin_associations_id_max() RETURNS INT4
51 AS 'SELECT max(id) FROM bin_associations'
53 CREATE FUNCTION section_id_max() RETURNS INT4
54 AS 'SELECT max(id) FROM section'
56 CREATE FUNCTION priority_id_max() RETURNS INT4
57 AS 'SELECT max(id) FROM priority'
59 CREATE FUNCTION override_type_id_max() RETURNS INT4
60 AS 'SELECT max(id) FROM override_type'
63 SELECT setval('files_id_seq', files_id_max());
64 SELECT setval('source_id_seq', source_id_max());
65 SELECT setval('src_associations_id_seq', src_associations_id_max());
66 SELECT setval('dsc_files_id_seq', dsc_files_id_max());
67 SELECT setval('binaries_id_seq', binaries_id_max());
68 SELECT setval('bin_associations_id_seq', bin_associations_id_max());
69 SELECT setval('section_id_seq', section_id_max());
70 SELECT setval('priority_id_seq', priority_id_max());
71 SELECT setval('override_type_id_seq', override_type_id_max());
73 -- Vacuum the tables for efficency
85 VACUUM suite_architectures;
86 VACUUM bin_associations;
87 VACUUM src_associations;
93 -- FIXME: has to be a better way to do this
95 architecture, architecture_id_seq, archive, archive_id_seq,
96 bin_associations, bin_associations_id_seq, binaries,
97 binaries_id_seq, component, component_id_seq, dsc_files,
98 dsc_files_id_seq, files, files_id_seq, location, location_id_seq,
99 maintainer, maintainer_id_seq, override, override_type,
100 override_type_id_seq, priority, priority_id_seq, section,
101 section_id_seq, source, source_id_seq, src_associations,
102 src_associations_id_seq, suite, suite_architectures, suite_id_seq
105 -- Read only access to user 'nobody'
107 architecture, architecture_id_seq, archive, archive_id_seq,
108 bin_associations, bin_associations_id_seq, binaries,
109 binaries_id_seq, component, component_id_seq, dsc_files,
110 dsc_files_id_seq, files, files_id_seq, location, location_id_seq,
111 maintainer, maintainer_id_seq, override, override_type,
112 override_type_id_seq, priority, priority_id_seq, section,
113 section_id_seq, source, source_id_seq, src_associations,
114 src_associations_id_seq, suite, suite_architectures, suite_id_seq