*/
-- 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