Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spike for adding schedule history using audit_log #50

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dbt_project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ vars:
user: "{{ source('zendesk', 'user') }}"
time_zone: "{{ source('zendesk', 'time_zone') }}"
daylight_time: "{{ source('zendesk', 'daylight_time') }}"
audit_log: "{{ source('zendesk', 'audit_log') }}"

zendesk__ticket_passthrough_columns: []
zendesk__user_passthrough_columns: []
Expand Down
1 change: 1 addition & 0 deletions integration_tests/dbt_project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ vars:
zendesk_organization_tag_identifier: "organization_tag_data"
zendesk_user_identifier: "user_data"
zendesk_user_tag_identifier: "user_tag_data"
zendesk_audit_log_identifier: "audit_log_data"


using_schedules: True
Expand Down
6 changes: 6 additions & 0 deletions integration_tests/seeds/audit_log_data.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
id,_fivetran_synced,action,actor_id,change_description,created_at,source_id,source_label,source_type
579796,2024-05-28 21:53:06.793000,update,37253,"Workweek changed from {:sun=>{""01:45""=>""02:45""}, :mon=>{""09:00""=>""20:00""}, :tue=>{""09:00""=>""20:00""}, :wed=>{""08:00""=>""20:00""}, :thu=>{""08:00""=>""20:00""}, :fri=>{""08:00""=>""20:00""}} to {:sun=>{""03:00""=>""04:00""}, :mon=>{""08:00""=>""20:00""}, :tue=>{""08:00""=>""20:00""}, :wed=>{""07:15""=>""20:00""}, :thu=>{""07:15""=>""20:00""}, :fri=>{""07:15""=>""20:00""}}",2024-05-28 21:51:37.000000,18542,Workweek: Central US Schedule,zendesk/business_hours/workweek
2679952,2024-05-28 16:18:58.471000,update,37253,"Workweek changed from {:thu=>{""09:00""=>""17:00""}, :fri=>{""09:00""=>""17:00""}, :mon=>{""09:00""=>""17:00""}, :tue=>{""09:00""=>""17:00""}, :wed=>{""09:00""=>""17:00""}} to {:mon=>{""09:00""=>""17:00""}, :tue=>{""09:00""=>""17:00""}, :wed=>{""09:00""=>""17:00""}, :thu=>{""09:00""=>""17:00""}, :fri=>{""09:00""=>""17:00""}}",2024-05-21 11:20:29.000000,267996,Workweek: New schedule here,zendesk/business_hours/workweek
293556,2024-05-28 16:18:58.471000,update,37253,"Workweek changed from {} to {:mon=>{""09:00""=>""17:00""}, :tue=>{""09:00""=>""17:00""}, :wed=>{""09:00""=>""17:00""}, :thu=>{""09:00""=>""17:00""}, :fri=>{""09:00""=>""17:00""}}",2024-05-21 11:20:28.000000,267996,Workweek: New schedule here,zendesk/business_hours/workweek
4441364,2024-05-28 16:18:58.471000,update,37253,"Workweek changed from {:wed=>{""09:00""=>""17:00""}, :thu=>{""09:00""=>""17:00""}, :mon=>{""09:00""=>""17:00""}, :tue=>{""09:00""=>""17:00""}, :fri=>{""09:00""=>""17:00""}} to {:mon=>{""09:00""=>""17:00""}, :tue=>{""09:00""=>""17:00""}, :wed=>{""09:00""=>""17:00""}, :thu=>{""09:00""=>""17:00""}, :fri=>{""09:00""=>""17:00""}}",2024-05-21 11:20:10.000000,267996,Workweek: New schedule 2,zendesk/business_hours/workweek
70900,2024-05-28 16:18:58.471000,update,37253,"Workweek changed from {} to {:mon=>{""09:00""=>""17:00""}, :tue=>{""09:00""=>""17:00""}, :wed=>{""09:00""=>""17:00""}, :thu=>{""09:00""=>""17:00""}, :fri=>{""09:00""=>""17:00""}}",2024-05-21 11:20:09.000000,267996,Workweek: New schedule 2,zendesk/business_hours/workweek
17 changes: 17 additions & 0 deletions macros/get_audit_log_columns.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{% macro get_audit_log_columns() %}

{% set columns = [
{"name": "_fivetran_synced", "datatype": dbt.type_timestamp()},
{"name": "id", "datatype": dbt.type_int()},
{"name": "action", "datatype": dbt.type_string()},
{"name": "actor_id", "datatype": dbt.type_int()},
{"name": "change_description", "datatype": dbt.type_string()},
{"name": "created_at", "datatype": dbt.type_timestamp()},
{"name": "source_id", "datatype": dbt.type_int()},
{"name": "source_label", "datatype": dbt.type_string()},
{"name": "source_type", "datatype": dbt.type_string()}
] %}

{{ return(columns) }}

{% endmacro %}
4 changes: 4 additions & 0 deletions models/src_zendesk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ sources:


tables:
- name: audit_log
identifier: "{{ var('zendesk_audit_log_identifier', 'audit_log')}}"
freshness: null

- name: ticket
identifier: "{{ var('zendesk_ticket_identifier', 'ticket')}}"
description: >
Expand Down
46 changes: 46 additions & 0 deletions models/stg_zendesk__audit_log.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

with base as (

select *
from {{ ref('stg_zendesk__audit_log_tmp') }}

),

fields as (

select
/*
The below macro is used to generate the correct SQL for package staging models. It takes a list of columns
that are expected/needed (staging_columns from dbt_zendesk_source/models/tmp/) and compares it with columns
in the source (source_columns from dbt_zendesk_source/macros/).
For more information refer to our dbt_fivetran_utils documentation (https://github.com/fivetran/dbt_fivetran_utils.git).
*/
{{
fivetran_utils.fill_staging_columns(
source_columns=adapter.get_columns_in_relation(ref('stg_zendesk__audit_log_tmp')),
staging_columns=get_audit_log_columns()
)
}}

from base
),

final as (

select

id as audit_log_id,
action,
actor_id,
change_description,
cast(created_at as {{ dbt.type_timestamp() }}) as created_at,
source_id,
source_label,
source_type,
_fivetran_synced

from fields
)

select *
from final
2 changes: 2 additions & 0 deletions models/tmp/stg_zendesk__audit_log_tmp.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
select {{ dbt_utils.star(source('zendesk','audit_log')) }}
from {{ source('zendesk','audit_log') }} as audit_log_table