From c29f1b976e4381ad19697a819be5506e8376785f Mon Sep 17 00:00:00 2001 From: Lam Voong Date: Tue, 19 May 2020 09:44:56 -0700 Subject: [PATCH] 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. --- .../upgrade/6.0.0/post-init/05_uoc.sql | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) 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 -- 2.47.3