Skip to content

Instantly share code, notes, and snippets.

View philerooski's full-sized avatar

Phil Snyder philerooski

  • San Francisco, CA
View GitHub Profile
@philerooski
philerooski / test_reset_default_secondary_roles_all_users.sql
Created May 11, 2026 22:30
Snowflake test script: reset default secondary roles for all users
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
@philerooski
philerooski / test_verify_default_secondary_roles_summary.sql
Created May 11, 2026 22:30
Snowflake test script: verify default secondary roles summary
USE ROLE USERADMIN;
-- Verification script for DEFAULT_SECONDARY_ROLES test runs.
-- Run this before and after test scripts to compare distribution changes.
-- ============================================================================
-- SECTION 1: SUMMARY COUNT BY DEFAULT_SECONDARY_ROLES BUCKET
-- Captures counts of users in ALL_ENABLED, EMPTY ([]), NULL, and OTHER buckets.
-- ============================================================================
SELECT 'SECTION 1: SUMMARY COUNT BY DSR BUCKET' AS report_section;
@philerooski
philerooski / verify_pr317_grants.py
Created May 21, 2026 21:06
Verify PR #317 (SNOW-460) grants in Snowflake
"""
Verify that all grants introduced in PR #317 (SNOW-460) are applied.
Checks:
1. Roles exist (new roles added in roles.sql)
2. Schemas exist (schema init migrations)
3. Schema ownership (ownership_grants migrations)
4. Database-level privileges (USAGE, MONITOR on SAGE)
5. Schema-level privileges (USAGE, MONITOR on SAGE.<schema>)
6. Role-to-role grants (analyst roles → DATA_ENGINEER, admin roles → SAGE_ADMIN, etc.)
@philerooski
philerooski / load_snapshot_data.py
Created June 15, 2026 13:14
Load RDS snapshot data from S3 into Snowflake with column-level masking for raw_table_read_censored
"""
Load RDS snapshot data from S3 via Snowflake external stage into tables.
This script supports two modes:
1. Bootstrap mode (--bootstrap-stack): Creates a new schema, external stage,
file format, and grants privileges before loading data.
2. Manual mode: Loads data into an existing schema with pre-configured stage.
The script dynamically discovers all data types from the S3 stage URL,
creates tables using INFER_SCHEMA from Parquet files, loads the data,
"""Incrementally backfills COPY_FILES_TASK / COPY_CHANGES_TASK / COPY_SENT_MESSAGES_TASK's
RDS_SNAPSHOTS_STAGE backlog one snapshot_date at a time (SNOW-580).
These tasks time out trying to COPY INTO their entire backlog (150K+ files,
1TB+) in a single statement, even on COMPUTE_MEDIUM. This script drains the
backlog day by day instead: each COPY INTO is scoped to one snapshot_date via
the PATTERN clause, which keeps each run's file count/volume small enough to
finish well inside the warehouse statement timeout. It's safe to re-run --
COPY INTO skips files it has already loaded -- so a partial or interrupted run
can just be re-invoked to pick up where it left off.