From 4e0530a64d7e7029ad2df0a367ff1c51f042632e Mon Sep 17 00:00:00 2001 From: Jenny V Medina Date: Fri, 20 Dec 2024 15:01:10 -0500 Subject: [PATCH] [SNOW-60,162,165] Add new columns to `userprofilesnapshots` (#95) --- ...r_auth_enabled_to_userprofilesnapshots.sql | 7 +++ ...28.1__update_userprofilesnapshots_task.sql | 45 +++++++++++++++++++ .../V2.28.2__refresh_userprofilesnapshots.sql | 38 ++++++++++++++++ 3 files changed, 90 insertions(+) create mode 100644 synapse_data_warehouse/synapse_raw/tables/V2.28.0__add_is_two_factor_auth_enabled_to_userprofilesnapshots.sql create mode 100644 synapse_data_warehouse/synapse_raw/tables/V2.28.1__update_userprofilesnapshots_task.sql create mode 100644 synapse_data_warehouse/synapse_raw/tables/V2.28.2__refresh_userprofilesnapshots.sql diff --git a/synapse_data_warehouse/synapse_raw/tables/V2.28.0__add_is_two_factor_auth_enabled_to_userprofilesnapshots.sql b/synapse_data_warehouse/synapse_raw/tables/V2.28.0__add_is_two_factor_auth_enabled_to_userprofilesnapshots.sql new file mode 100644 index 00000000..5223bae6 --- /dev/null +++ b/synapse_data_warehouse/synapse_raw/tables/V2.28.0__add_is_two_factor_auth_enabled_to_userprofilesnapshots.sql @@ -0,0 +1,7 @@ +-- Configure environment +USE SCHEMA {{database_name}}.synapse_raw; --noqa: JJ01,PRS,TMP,CP02 + +-- Add new column +ALTER TABLE userprofilesnapshot ADD COLUMN is_two_factor_auth_enabled BOOLEAN COMMENT 'Indicates if the user had two factor authentication enabled when the snapshot was captured.'; +ALTER TABLE userprofilesnapshot ADD COLUMN industry STRING COMMENT 'The industry/discipline that this person is associated with.'; +ALTER TABLE userprofilesnapshot ADD COLUMN tos_agreements VARIANT COMMENT 'Contains the list of all the term of service that the user agreed to, with their agreed on date and version.'; diff --git a/synapse_data_warehouse/synapse_raw/tables/V2.28.1__update_userprofilesnapshots_task.sql b/synapse_data_warehouse/synapse_raw/tables/V2.28.1__update_userprofilesnapshots_task.sql new file mode 100644 index 00000000..87ab00a6 --- /dev/null +++ b/synapse_data_warehouse/synapse_raw/tables/V2.28.1__update_userprofilesnapshots_task.sql @@ -0,0 +1,45 @@ +-- Configure environment +USE SCHEMA {{database_name}}.synapse_raw; --noqa: JJ01,PRS,TMP,CP02 + +-- Suspend the root task +ALTER TASK refresh_synapse_warehouse_s3_stage_task SUSPEND; + +-- Suspend the child task in question +ALTER TASK userprofilesnapshot_task SUSPEND; + +-- Add the new column to the child task +ALTER TASK userprofilesnapshot_task MODIFY AS + COPY INTO + userprofilesnapshot + FROM ( + SELECT + $1:change_type as change_type, + $1:change_timestamp as change_timestamp, + $1:change_user_id as change_user_id, + $1:snapshot_timestamp as snapshot_timestamp, + $1:id as id, + $1:user_name as user_name, + $1:first_name as first_name, + $1:last_name as last_name, + $1:email as email, + $1:location as location, + $1:company as company, + $1:position as position, + NULLIF( + REGEXP_REPLACE( + metadata$filename, + '.*userprofilesnapshots\/snapshot_date\=(.*)\/.*', '\\1' + ), + '__HIVE_DEFAULT_PARTITION__' + ) as snapshot_date, + $1:created_on as created_on, + $1:is_two_factor_auth_enabled as is_two_factor_auth_enabled, + $1:industry as industry, + $1:tos_agreements as tos_agreements + from + @synapse_prod_warehouse_s3_stage/userprofilesnapshots --noqa: TMP + ) + pattern = '.*userprofilesnapshots/snapshot_date=.*/.*'; + +-- Resume the ROOT task and its child task +SELECT SYSTEM$TASK_DEPENDENTS_ENABLE( 'refresh_synapse_warehouse_s3_stage_task' ); diff --git a/synapse_data_warehouse/synapse_raw/tables/V2.28.2__refresh_userprofilesnapshots.sql b/synapse_data_warehouse/synapse_raw/tables/V2.28.2__refresh_userprofilesnapshots.sql new file mode 100644 index 00000000..7e6008ef --- /dev/null +++ b/synapse_data_warehouse/synapse_raw/tables/V2.28.2__refresh_userprofilesnapshots.sql @@ -0,0 +1,38 @@ +-- Configure environment +USE SCHEMA {{database_name}}.synapse_raw; --noqa: JJ01,PRS,TMP,CP02 + +-- Drop all records from this table but keep structure and permissions intact +TRUNCATE TABLE userprofilesnapshot; + +-- +COPY INTO + userprofilesnapshot +FROM ( + SELECT + $1:change_type as change_type, + $1:change_timestamp as change_timestamp, + $1:change_user_id as change_user_id, + $1:snapshot_timestamp as snapshot_timestamp, + $1:id as id, + $1:user_name as user_name, + $1:first_name as first_name, + $1:last_name as last_name, + $1:email as email, + $1:location as location, + $1:company as company, + $1:position as position, + NULLIF( + REGEXP_REPLACE( + metadata$filename, + '.*userprofilesnapshots\/snapshot_date\=(.*)\/.*', '\\1' + ), + '__HIVE_DEFAULT_PARTITION__' + ) as snapshot_date, + $1:created_on as created_on, + $1:is_two_factor_auth_enabled as is_two_factor_auth_enabled, + $1:industry as industry, + $1:tos_agreements as tos_agreements + from + @synapse_prod_warehouse_s3_stage/userprofilesnapshots --noqa: TMP +) +pattern = '.*userprofilesnapshots/snapshot_date=.*/.*';