From: Lam Voong Date: Tue, 19 May 2020 16:44:56 +0000 (-0700) Subject: DRYD-835: Update UOC migration script: Add checks for userGroup update X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=c29f1b976e4381ad19697a819be5506e8376785f;p=tmp%2Fjakarta-migration.git DRYD-835: Update UOC migration script: Add checks for userGroup update -- Check to make sure both userType and userInstitutionRole columns exist in userGroup table. -- Only update when userInstitutionRole IS NULL. --- diff --git a/src/main/resources/db/postgresql/upgrade/6.0.0/post-init/05_uoc.sql b/src/main/resources/db/postgresql/upgrade/6.0.0/post-init/05_uoc.sql index 07fdaa6e9..435f97838 100644 --- a/src/main/resources/db/postgresql/upgrade/6.0.0/post-init/05_uoc.sql +++ b/src/main/resources/db/postgresql/upgrade/6.0.0/post-init/05_uoc.sql @@ -432,8 +432,23 @@ $$; */ -- Migrate v5.2 UOC User Type data from userType to userInstitutionRole in the userGroup table: +-- Check to make sure both columns exist in userGroup table. +-- Only update when userInstitutionRole is NULL. + +DO $$ +BEGIN + IF 2 = (SELECT count(*) c + FROM information_schema.columns + WHERE table_name = 'usergroup' + AND (column_name = 'usertype' OR column_name = 'userinstitutionrole')) + THEN + UPDATE usergroup + SET userinstitutionrole = usertype + WHERE userinstitutionrole IS NULL; + ELSE + RAISE NOTICE 'Unable to update userGroup: userType and/or userInstitutionRole columns missing.'; + END IF; +END $$; -update usergroup -set userinstitutionrole = usertype; -- END OF MIGRATION