]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
DRYD-835: Update UOC migration script: Add checks for userGroup update
authorLam Voong <lkv@berkeley.edu>
Tue, 19 May 2020 16:44:56 +0000 (09:44 -0700)
committerGitHub <noreply@github.com>
Tue, 19 May 2020 16:44:56 +0000 (09:44 -0700)
-- Check to make sure both userType and userInstitutionRole columns exist in userGroup table.
-- Only update when userInstitutionRole IS NULL.

src/main/resources/db/postgresql/upgrade/6.0.0/post-init/05_uoc.sql

index 07fdaa6e93925832b6041cf8088d851595a819ac..435f97838b05c2638b623c07291d6e0f5177d06c 100644 (file)
@@ -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