more schema updates

This commit is contained in:
Mike McLean 2016-08-29 16:25:30 -04:00
parent e5ac6cf286
commit 275aa83b0f
2 changed files with 41 additions and 13 deletions

View file

@ -29,5 +29,33 @@ SELECT statement_timestamp(), 'Altering archiveinfo table' as msg;
ALTER TABLE archiveinfo ADD COLUMN btype_id INTEGER REFERENCES btype(id);
-- new component tables
SELECT statement_timestamp(), 'Creating new component tables' as msg;
CREATE TABLE archive_rpm_components AS SELECT image_id, rpm_id from image_listing;
CREATE TABLE archive_components AS SELECT image_id, archive_id from image_archive_listing;
-- doing it this way and fixing up after is *much* faster than creating the empty table
-- and using insert..select to populate
SELECT statement_timestamp(), 'Fixing up component tables, rename columns' as msg;
ALTER TABLE archive_rpm_components RENAME image_id TO archive_id;
ALTER TABLE archive_components RENAME archive_id TO component_id;
ALTER TABLE archive_components RENAME image_id TO archive_id;
SELECT statement_timestamp(), 'Fixing up component tables, adding constraints' as msg;
ALTER TABLE archive_rpm_components ADD CONSTRAINT archive_fk FOREIGN KEY (archive_id) REFERENCES archiveinfo(id);
ALTER TABLE archive_rpm_components ADD CONSTRAINT rpm_fk FOREIGN KEY (rpm_id) REFERENCES rpminfo(id);
ALTER TABLE archive_rpm_components ADD CONSTRAINT arcomp_unique UNIQUE (archive_id, rpm_id);
ALTER TABLE archive_components ADD CONSTRAINT archive_fk FOREIGN KEY (archive_id) REFERENCES archiveinfo(id);
ALTER TABLE archive_components ADD CONSTRAINT rpm_fk FOREIGN KEY (component_id) REFERENCES archiveinfo(id);
ALTER TABLE archive_components ADD CONSTRAINT arcomp_unique UNIQUE (archive_id, component_id);
SELECT statement_timestamp(), 'Adding component table indexes' as msg;
CREATE INDEX rpm_components_idx on archive_rpm_components(rpm_id);
CREATE INDEX archive_components_idx on archive_components(component_id);
-- image_listing and image_archive_listing are no longer used
COMMIT;

View file

@ -829,21 +829,21 @@ CREATE TABLE image_archives (
arch VARCHAR(16) NOT NULL
) WITHOUT OIDS;
-- tracks the contents of an image
CREATE TABLE image_listing (
image_id INTEGER NOT NULL REFERENCES image_archives(archive_id),
rpm_id INTEGER NOT NULL REFERENCES rpminfo(id),
UNIQUE (image_id, rpm_id)
) WITHOUT OIDS;
CREATE INDEX image_listing_rpms on image_listing(rpm_id);
-- track the archive contents of an image
CREATE TABLE image_archive_listing (
image_id INTEGER NOT NULL REFERENCES image_archives(archive_id),
-- tracks the rpm contents of an image or other archive
CREATE TABLE archive_rpm_components (
archive_id INTEGER NOT NULL REFERENCES archiveinfo(id),
UNIQUE (image_id, archive_id)
rpm_id INTEGER NOT NULL REFERENCES rpminfo(id),
UNIQUE (archive_id, rpm_id)
) WITHOUT OIDS;
CREATE INDEX image_listing_archives on image_archive_listing(archive_id);
CREATE INDEX rpm_components_idx on archive_rpm_components(rpm_id);
-- track the archive contents of an image or other archive
CREATE TABLE archive_components (
archive_id INTEGER NOT NULL REFERENCES archiveinfo(id),
component_id INTEGER NOT NULL REFERENCES archiveinfo(id),
UNIQUE (archive_id, component_id)
) WITHOUT OIDS;
CREATE INDEX archive_components_idx on archive_components(component_id);
CREATE TABLE buildroot_archives (