From: Ray Lee Date: Sat, 16 Mar 2024 01:41:19 +0000 (-0400) Subject: DRYD-1372: Add numberofobjects to objectcountgroup upgrade script. (#403) X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=5526bddc2a78598bc3b55987e076f35c3560628c;p=tmp%2Fjakarta-migration.git DRYD-1372: Add numberofobjects to objectcountgroup upgrade script. (#403) --- diff --git a/src/main/resources/db/postgresql/upgrade/8.0.0/post-init/01_collectionobject.sql b/src/main/resources/db/postgresql/upgrade/8.0.0/post-init/01_collectionobject_fieldcollectionplace.sql similarity index 100% rename from src/main/resources/db/postgresql/upgrade/8.0.0/post-init/01_collectionobject.sql rename to src/main/resources/db/postgresql/upgrade/8.0.0/post-init/01_collectionobject_fieldcollectionplace.sql diff --git a/src/main/resources/db/postgresql/upgrade/8.0.0/post-init/02_collectionobject_numberofobjects.sql b/src/main/resources/db/postgresql/upgrade/8.0.0/post-init/02_collectionobject_numberofobjects.sql new file mode 100644 index 000000000..8240957bc --- /dev/null +++ b/src/main/resources/db/postgresql/upgrade/8.0.0/post-init/02_collectionobject_numberofobjects.sql @@ -0,0 +1,76 @@ +-- Upgrade collectionobject. Move number of objects into the new repeating object count group (DRYD-1372). + +DO $$ +DECLARE + trow record; + maxpos int; + uuid varchar(36); +BEGIN + + -- For new install, if collectionobjects_common.numberofobjects does not exist, there is nothing to migrate. + + IF EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name='collectionobjects_common' AND column_name='numberofobjects') THEN + FOR trow IN + -- Get record in collectionobjects_common that does not have an existing/matching record in objectcountgroup: + + SELECT id AS parentid, numberofobjects + FROM public.collectionobjects_common + WHERE id NOT IN ( + SELECT cc.id + FROM public.collectionobjects_common cc + JOIN public.hierarchy h ON (cc.id = h.parentid) + JOIN public.objectcountgroup ocg ON ( + h.id = ocg.id + AND cc.numberofobjects IS NOT DISTINCT FROM ocg.objectcount + ) + ) + AND (numberofobjects IS NOT NULL) + + LOOP + -- Get max pos value for the collectionobject record's object count group, and generate a new uuid: + + SELECT + coalesce(max(pos), -1), + uuid_generate_v4()::varchar + INTO + maxpos, + uuid + FROM public.hierarchy + WHERE parentid = trow.parentid + AND name = 'collectionobjects_common:objectCountGroupList' + AND primarytype = 'objectCountGroup'; + + -- Insert new record into hierarchy table first, due to foreign key on objectcountgroup table: + + INSERT INTO public.hierarchy ( + id, + parentid, + pos, + name, + isproperty, + primarytype) + VALUES ( + uuid, + trow.parentid, + maxpos + 1, + 'collectionobjects_common:objectCountGroupList', + TRUE, + 'objectCountGroup'); + + -- Migrate collectionobject number of objects data into objectcountgroup table: + + INSERT INTO public.objectcountgroup ( + id, + objectcount) + VALUES ( + uuid, + trow.numberofobjects); + + END LOOP; + + ELSE + RAISE NOTICE 'No v7.2 collectionobject number of objects data to migrate: collectionobjects_common.numberofobjects does not exist'; + + END IF; +END +$$; \ No newline at end of file