further work on schema upgrade script

This commit is contained in:
Mike McLean 2012-08-21 15:48:12 -04:00
parent 9456dcd9b9
commit 390a8fb699

View file

@ -4,21 +4,39 @@
BEGIN;
ALTER TABLE imageinfo_listing RENAME TO old_imageinfo_listing;
-- we need to keep this data temporarily (as well as the obsolete imageinfo
-- table) so that the supplemental migration script can do its job
-- The following tables are now obsolete:
-- imageinfo
-- imageinfo_listing
-- However, we cannot drop them until after we migrate the data
-- create new image tables
CREATE TABLE image_builds (
build_id INTEGER NOT NULL PRIMARY KEY REFERENCES build(id)
) WITHOUT OIDS;
CREATE TABLE image_listing (
image_id INTEGER NOT NULL REFERENCES archiveinfo(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);
CREATE TABLE image_archives (
archive_id INTEGER NOT NULL PRIMARY KEY REFERENCES archiveinfo(id),
arch VARCHAR(16) NOT NULL
) WITHOUT OIDS;
-- alter archiveinfo
ALTER TABLE archiveinfo ALTER COLUMN size TYPE BIGINT;
ALTER TABLE archiveinfo RENAME COLUMN md5sum TO checksum;
ALTER TABLE archiveinfo ADD COLUMN checksum_type INTEGER NOT NULL;
ALTER TABLE archiveinfo ADD COLUMN checksum_type INTEGER NOT NULL DEFAULT 0;
ALTER TABLE archiveinfo ALTER COLUMN checksum_type DROP DEFAULT;
-- the main schema has no default for checksum_type
-- this is just an easy way to populate the fields for the old entries
-- new archive types
insert into archivetypes (name, description, extensions) values ('iso', 'CD/DVD Image', 'iso');
@ -27,3 +45,4 @@ insert into archivetypes (name, description, extensions) values ('qcow', 'QCOW i
insert into archivetypes (name, description, extensions) values ('qcow2', 'QCOW2 image', 'qcow2');
insert into archivetypes (name, description, extensions) values ('vmx', 'VMX image', 'vmx');
COMMIT;