diff --git a/scripts/migration/1.11-1.16.3/1 b/scripts/migration/1.11-1.16.3/1 new file mode 100644 index 0000000..d76b1e5 --- /dev/null +++ b/scripts/migration/1.11-1.16.3/1 @@ -0,0 +1,4 @@ +CHANGES from original schema: +- We created the 'image' role in 1.11 -> removed +- A user nobody need to exist with id=1 -> insert into users (id,name,password,status,usertype,krb_principal) VALUES (1, 'nobody', '',0,0,''); was executed on production database. +- A deleted constrain in 1.15 -> 1.16, didn't exist -> commented out. diff --git a/scripts/migration/1.11-1.16.3/README b/scripts/migration/1.11-1.16.3/README new file mode 100644 index 0000000..1b6d52a --- /dev/null +++ b/scripts/migration/1.11-1.16.3/README @@ -0,0 +1,5 @@ +CHANGES from original schema upgrad files: +- We created the 'image' role in 1.11 -> removed +- A user nobody need to exist with id=1 -> insert into users (id,name,password,status,usertype,krb_principal) VALUES (1, 'nobody', '',0,0,''); was executed on production database. +- A deleted constrain in 1.15 -> 1.16, didn't exist -> commented out. (-- ALTER TABLE host_channels DROP CONSTRAINT host_channels_host_id_channel_id_key; +) diff --git a/scripts/migration/1.11-1.16.3/schema-upgrade-1.11-1.12.sql b/scripts/migration/1.11-1.16.3/schema-upgrade-1.11-1.12.sql new file mode 100644 index 0000000..758a645 --- /dev/null +++ b/scripts/migration/1.11-1.16.3/schema-upgrade-1.11-1.12.sql @@ -0,0 +1,11 @@ +BEGIN; + +-- from schema-update-dist-repos.sql + +-- INSERT INTO permissions (name) VALUES ('image'); + +ALTER TABLE repo ADD COLUMN dist BOOLEAN; +ALTER TABLE repo ALTER COLUMN dist SET DEFAULT 'false'; +UPDATE repo SET dist = 'false'; + +COMMIT; diff --git a/scripts/migration/1.11-1.16.3/schema-upgrade-1.12-1.13.sql b/scripts/migration/1.11-1.16.3/schema-upgrade-1.12-1.13.sql new file mode 100644 index 0000000..5a87ec3 --- /dev/null +++ b/scripts/migration/1.11-1.16.3/schema-upgrade-1.12-1.13.sql @@ -0,0 +1,9 @@ +-- upgrade script to migrate the Koji database schema +-- from version 1.12 to 1.13 + +BEGIN; + +-- Change VARCHAR field for tag names to TEXT to allow longer tag names +ALTER TABLE tag ALTER COLUMN name TYPE TEXT; + +COMMIT; diff --git a/scripts/migration/1.11-1.16.3/schema-upgrade-1.13-1.14.sql b/scripts/migration/1.11-1.16.3/schema-upgrade-1.13-1.14.sql new file mode 100644 index 0000000..16b4227 --- /dev/null +++ b/scripts/migration/1.11-1.16.3/schema-upgrade-1.13-1.14.sql @@ -0,0 +1,13 @@ +-- upgrade script to migrate the Koji database schema +-- from version 1.13 to 1.14 + +BEGIN; + +-- drop unused log_messages table +DROP TABLE log_messages; + +-- add yaml and xjb file type in archivetypes +insert into archivetypes (name, description, extensions) values ('yaml', 'YAML Ain''t Markup Language', 'yaml yml'); +insert into archivetypes (name, description, extensions) values ('xjb', 'JAXB(Java Architecture for XML Binding) Binding Customization File', 'xjb'); + +COMMIT; diff --git a/scripts/migration/1.11-1.16.3/schema-upgrade-1.14-1.15.sql b/scripts/migration/1.11-1.16.3/schema-upgrade-1.14-1.15.sql new file mode 100644 index 0000000..dd4e026 --- /dev/null +++ b/scripts/migration/1.11-1.16.3/schema-upgrade-1.14-1.15.sql @@ -0,0 +1,3 @@ +-- Nothing to do +-- +-- There were no schema changes between 1.14 and 1.15 diff --git a/scripts/migration/1.11-1.16.3/schema-upgrade-1.15-1.16.sql b/scripts/migration/1.11-1.16.3/schema-upgrade-1.15-1.16.sql new file mode 100644 index 0000000..37d2078 --- /dev/null +++ b/scripts/migration/1.11-1.16.3/schema-upgrade-1.15-1.16.sql @@ -0,0 +1,64 @@ +-- upgrade script to migrate the Koji database schema +-- from version 1.14 to 1.16 + + +BEGIN; + +-- create host_config table +SELECT 'Creating table host_config'; +CREATE TABLE host_config ( + host_id INTEGER NOT NULL REFERENCES host(id), + arches TEXT, + capacity FLOAT CHECK (capacity > 1) NOT NULL DEFAULT 2.0, + description TEXT, + comment TEXT, + enabled BOOLEAN NOT NULL DEFAULT 'true', +-- versioned - see desc above + create_event INTEGER NOT NULL REFERENCES events(id) DEFAULT get_event(), + revoke_event INTEGER REFERENCES events(id), + creator_id INTEGER NOT NULL REFERENCES users(id), + revoker_id INTEGER REFERENCES users(id), + active BOOLEAN DEFAULT 'true' CHECK (active), + CONSTRAINT active_revoke_sane CHECK ( + (active IS NULL AND revoke_event IS NOT NULL AND revoker_id IS NOT NULL) + OR (active IS NOT NULL AND revoke_event IS NULL AND revoker_id IS NULL)), + PRIMARY KEY (create_event, host_id), + UNIQUE (host_id, active) +) WITHOUT OIDS; +CREATE INDEX host_config_by_active_and_enabled ON host_config(active, enabled); + +-- copy starting data +-- CREATE FUNCTION pg_temp.user() returns INTEGER as $$ select id from users where name='nobody' $$ language SQL; +CREATE FUNCTION pg_temp.user() returns INTEGER as $$ select 1 $$ language SQL; +-- If you would like to use an existing user instead, then: +-- 1. edit the temporary function to look for the alternate user name + +SELECT 'Copying data from host to host_config'; +INSERT INTO host_config (host_id, arches, capacity, description, comment, enabled, creator_id) + SELECT id, arches, capacity, description, comment, enabled, pg_temp.user() FROM host; + +-- alter original table +SELECT 'Dropping moved columns'; +ALTER TABLE host DROP COLUMN arches; +ALTER TABLE host DROP COLUMN capacity; +ALTER TABLE host DROP COLUMN description; +ALTER TABLE host DROP COLUMN comment; +ALTER TABLE host DROP COLUMN enabled; + +-- history for host_channels +SELECT 'Adding versions to host_channels'; +ALTER TABLE host_channels ADD COLUMN create_event INTEGER NOT NULL REFERENCES events(id) DEFAULT get_event(); +ALTER TABLE host_channels ADD COLUMN revoke_event INTEGER REFERENCES events(id); +-- we need some default for alter table, but drop it after +ALTER TABLE host_channels ADD COLUMN creator_id INTEGER NOT NULL REFERENCES users(id) DEFAULT pg_temp.user(); +ALTER TABLE host_channels ALTER COLUMN creator_id DROP DEFAULT; +ALTER TABLE host_channels ADD COLUMN revoker_id INTEGER REFERENCES users(id); +ALTER TABLE host_channels ADD COLUMN active BOOLEAN DEFAULT 'true' CHECK (active); +ALTER TABLE host_channels ADD CONSTRAINT active_revoke_sane CHECK ( + (active IS NULL AND revoke_event IS NOT NULL AND revoker_id IS NOT NULL) + OR (active IS NOT NULL AND revoke_event IS NULL AND revoker_id IS NULL)); +ALTER TABLE host_channels ADD PRIMARY KEY (create_event, host_id, channel_id); +ALTER TABLE host_channels ADD UNIQUE (host_id, channel_id, active); +-- ALTER TABLE host_channels DROP CONSTRAINT host_channels_host_id_channel_id_key; + +COMMIT;