Created
May 11, 2026 22:30
-
-
Save philerooski/4f8372c996648822b172c59651cd0271 to your computer and use it in GitHub Desktop.
Snowflake test script: reset default secondary roles for all users
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| USE ROLE USERADMIN; | |
| -- Rollback script for test_set_default_secondary_roles_by_analyst_rules.sql. | |
| -- Resets DEFAULT_SECONDARY_ROLES to empty for all users except SNOWFLAKE. | |
| EXECUTE IMMEDIATE $$ | |
| DECLARE | |
| updated_users ARRAY DEFAULT ARRAY_CONSTRUCT(); | |
| username STRING; | |
| dsr_value STRING; | |
| user_cursor CURSOR FOR | |
| SELECT "name", "default_secondary_roles" | |
| FROM TABLE(RESULT_SCAN(LAST_QUERY_ID())) | |
| WHERE "name" <> 'SNOWFLAKE' | |
| AND UPPER("name") NOT IN ( | |
| 'JOE.SMITH@SAGEBASE.ORG', | |
| 'JONI.HARKER@SAGEBASE.ORG' | |
| ); -- Jumpcloud-managed users | |
| BEGIN | |
| SHOW USERS; | |
| OPEN user_cursor; | |
| LOOP | |
| FETCH user_cursor INTO username, dsr_value; | |
| IF (username IS NULL) THEN | |
| BREAK; | |
| END IF; | |
| IF (COALESCE(dsr_value, '') != '[]') THEN | |
| LET quoted_username STRING := '"' || :username || '"'; | |
| ALTER USER IDENTIFIER(:quoted_username) SET DEFAULT_SECONDARY_ROLES=(); | |
| updated_users := ARRAY_APPEND(updated_users, username); | |
| END IF; | |
| END LOOP; | |
| CLOSE user_cursor; | |
| RETURN updated_users; | |
| END; | |
| $$; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment