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

Feature/historical schedules #55

Merged
merged 19 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from 12 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
2 changes: 1 addition & 1 deletion .buildkite/scripts/run_models.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ dbt deps
dbt seed --target "$db" --full-refresh
dbt run --target "$db" --full-refresh
dbt test --target "$db"
dbt run --vars '{using_schedules: false, using_domain_names: false, using_user_tags: false, using_ticket_form_history: false, using_organization_tags: false}' --target "$db" --full-refresh
dbt run --vars '{using_schedules: false, using_schedule_histories: false, using_holidays:false, using_domain_names: false, using_user_tags: false, using_ticket_form_history: false, using_organization_tags: false}' --target "$db" --full-refresh
dbt test --target "$db"
dbt run-operation fivetran_utils.drop_schemas_automation --target "$db"
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# dbt_zendesk_source v0.13.0
[PR #55](https://github.com/fivetran/dbt_zendesk_source/pull/55) includes the following updates:
- Update this

# dbt_zendesk_source v0.12.0
[PR #53](https://github.com/fivetran/dbt_zendesk_source/pull/53) includes the following updates:
## Breaking changes
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Include the following zendesk_source package version in your `packages.yml` file
```yaml
packages:
- package: fivetran/zendesk_source
version: [">=0.12.0", "<0.13.0"]
version: [">=0.13.0", "<0.14.0"]
```
### Step 3: Define database and schema variables
By default, this package runs using your target database and the `zendesk` schema. If this is not where your Zendesk Support data is (for example, if your zendesk schema is named `zendesk_fivetran`), add the following configuration to your root `dbt_project.yml` file:
Expand Down
3 changes: 2 additions & 1 deletion dbt_project.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
config-version: 2
name: 'zendesk_source'
version: '0.12.0'
version: '0.13.0'
require-dbt-version: [">=1.3.0", "<2.0.0"]
models:
zendesk_source:
Expand Down 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
3 changes: 2 additions & 1 deletion integration_tests/dbt_project.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
config-version: 2

name: 'zendesk_source_integration_tests'
version: '0.12.0'
version: '0.13.0'

profile: 'integration_tests'

Expand All @@ -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
8 changes: 8 additions & 0 deletions integration_tests/seeds/audit_log_data.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
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=&amp;gt;{""01:45""=&amp;gt;""02:45""}, :mon=&amp;gt;{""09:00""=&amp;gt;""20:00""}, :tue=&amp;gt;{""09:00""=&amp;gt;""20:00""}, :wed=&amp;gt;{""08:00""=&amp;gt;""20:00""}, :thu=&amp;gt;{""08:00""=&amp;gt;""20:00""}, :fri=&amp;gt;{""08:00""=&amp;gt;""20:00""}} to {:sun=&amp;gt;{""03:00""=&amp;gt;""04:00""}, :mon=&amp;gt;{""08:00""=&amp;gt;""20:00""}, :tue=&amp;gt;{""08:00""=&amp;gt;""20:00""}, :wed=&amp;gt;{""07:15""=&amp;gt;""20:00""}, :thu=&amp;gt;{""07:15""=&amp;gt;""20:00""}, :fri=&amp;gt;{""07:15""=&amp;gt;""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=&amp;gt;{""09:00""=&amp;gt;""17:00""}, :fri=&amp;gt;{""09:00""=&amp;gt;""17:00""}, :mon=&amp;gt;{""09:00""=&amp;gt;""17:00""}, :tue=&amp;gt;{""09:00""=&amp;gt;""17:00""}, :wed=&amp;gt;{""09:00""=&amp;gt;""17:00""}} to {:mon=&amp;gt;{""09:00""=&amp;gt;""17:00""}, :tue=&amp;gt;{""09:00""=&amp;gt;""17:00""}, :wed=&amp;gt;{""09:00""=&amp;gt;""17:00""}, :thu=&amp;gt;{""09:00""=&amp;gt;""17:00""}, :fri=&amp;gt;{""09:00""=&amp;gt;""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=&amp;gt;{""09:00""=&amp;gt;""17:00""}, :tue=&amp;gt;{""09:00""=&amp;gt;""17:00""}, :wed=&amp;gt;{""09:00""=&amp;gt;""17:00""}, :thu=&amp;gt;{""09:00""=&amp;gt;""17:00""}, :fri=&amp;gt;{""09:00""=&amp;gt;""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=&amp;gt;{""09:00""=&amp;gt;""17:00""}, :thu=&amp;gt;{""09:00""=&amp;gt;""17:00""}, :mon=&amp;gt;{""09:00""=&amp;gt;""17:00""}, :tue=&amp;gt;{""09:00""=&amp;gt;""17:00""}, :fri=&amp;gt;{""09:00""=&amp;gt;""17:00""}} to {:mon=&amp;gt;{""09:00""=&amp;gt;""17:00""}, :tue=&amp;gt;{""09:00""=&amp;gt;""17:00""}, :wed=&amp;gt;{""09:00""=&amp;gt;""17:00""}, :thu=&amp;gt;{""09:00""=&amp;gt;""17:00""}, :fri=&amp;gt;{""09:00""=&amp;gt;""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=&amp;gt;{""09:00""=&amp;gt;""17:00""}, :tue=&amp;gt;{""09:00""=&amp;gt;""17:00""}, :wed=&amp;gt;{""09:00""=&amp;gt;""17:00""}, :thu=&amp;gt;{""09:00""=&amp;gt;""17:00""}, :fri=&amp;gt;{""09:00""=&amp;gt;""17:00""}}",2024-05-21 11:20:09.000000,267996,Workweek: New schedule 2,zendesk/business_hours/workweek
70901,2024-05-28 16:18:58.471000,update,37253,"Workweek changed from {&quot;mon&quot;:{&quot;10:00&quot;:&quot;20:00&quot;},&quot;tue&quot;:{&quot;10:00&quot;:&quot;20:00&quot;},&quot;wed&quot;:{&quot;10:00&quot;:&quot;20:00&quot;},&quot;thu&quot;:{&quot;10:00&quot;:&quot;20:00&quot;},&quot;fri&quot;:{&quot;10:00&quot;:&quot;20:00&quot;}} to {&quot;mon&quot;:{&quot;10:00&quot;:&quot;22:00&quot;},&quot;tue&quot;:{&quot;10:00&quot;:&quot;22:00&quot;},&quot;wed&quot;:{&quot;10:00&quot;:&quot;22:00&quot;},&quot;thu&quot;:{&quot;10:00&quot;:&quot;22:00&quot;},&quot;fri&quot;:{&quot;10:00&quot;:&quot;22:00&quot;}}",2024-05-21 11:20:09.000000,267996,Workweek: New schedule 2,zendesk/business_hours/workweek
70902,2024-05-28 16:18:58.471000,update,37253,"Workweek changed from {:mon=&amp;gt;{""09:00""=&amp;gt;""10:45"", ""11:45""=&amp;gt;""12:45"", ""13:45""=&amp;gt;""14:45"", ""15:15""=&amp;gt;""16:15"", ""19:00""=&amp;gt;""20:00"", ""17:30""=&amp;gt;""18:30""}, :tue=&amp;gt;{""00:15""=&amp;gt;""13:15"", ""13:30""=&amp;gt;""18:30"", ""18:45""=&amp;gt;""21:45"", ""22:00""=&amp;gt;""24:00""}, :wed=&amp;gt;{""09:00""=&amp;gt;""21:00""}, :thu=&amp;gt;{""17:00""=&amp;gt;""18:00"", ""19:45""=&amp;gt;""20:45"", ""09:00""=&amp;gt;""10:45"", ""12:15""=&amp;gt;""13:15"", ""14:30""=&amp;gt;""15:30""}, :fri=&amp;gt;{""09:00""=&amp;gt;""12:45"", ""19:15""=&amp;gt;""22:30"", ""14:45""=&amp;gt;""15:45"", ""17:30""=&amp;gt;""18:30""}} to {:mon=&amp;gt;{""09:00""=&amp;gt;""10:45"", ""11:45""=&amp;gt;""12:45"", ""13:45""=&amp;gt;""14:45"", ""15:15""=&amp;gt;""16:15"", ""17:30""=&amp;gt;""18:30"", ""19:00""=&amp;gt;""20:00""}, :tue=&amp;gt;{""00:15""=&amp;gt;""13:15"", ""13:30""=&amp;gt;""18:30"", ""18:45""=&amp;gt;""21:45"", ""22:00""=&amp;gt;""24:00""}, :wed=&amp;gt;{""02:30""=&amp;gt;""21:45""}, :thu=&amp;gt;{""09:00""=&amp;gt;""10:45"", ""12:15""=&amp;gt;""13:15"", ""14:30""=&amp;gt;""15:30"", ""17:00""=&amp;gt;""18:00"", ""19:45""=&amp;gt;""20:45""}, :fri=&amp;gt;{""09:00""=&amp;gt;""12:45"", ""14:45""=&amp;gt;""15:45"", ""17:30""=&amp;gt;""18:30"", ""19:15""=&amp;gt;""22:30""}}",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 %}
32 changes: 31 additions & 1 deletion models/src_zendesk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,36 @@ sources:


tables:
- name: audit_log
identifier: "{{ var('zendesk_audit_log_identifier', 'audit_log')}}"
config:
enabled: "{{ var('using_schedules', true) and var('using_schedule_histories', true) }}"
freshness: null
description: >
The `audit_log` table captures historical changes and actions within Zendesk. It provides a record of modifications
made to tickets, schedules, and other objects, allowing for a detailed audit trail. Each row represents an action
performed by an actor, including the time of the action, the affected entity, and a description of the changes. This
table is especially useful for tracking schedule modifications and maintaining a history of schedule changes.
columns:
- name: id
description: The unique identifier for each audit log entry, representing a distinct action or change.
- name: action
description: Describes the specific action performed within Zendesk, such as ticket updates or schedule modifications.
- name: actor_id
description: The unique identifier of the user or system responsible for performing the action.
- name: change_description
description: A detailed description of the changes made during the action, capturing what was altered.
- name: created_at
description: The timestamp indicating when the action was performed and recorded in the audit log.
- name: source_id
description: The unique identifier of the entity affected by the action, such as a ticket or schedule.
- name: source_label
description: A label that provides additional context about the affected entity, typically related to its type or name.
- name: source_type
description: Specifies the type of entity impacted by the action, such as a ticket, schedule, or user.
- name: _fivetran_synced
description: The timestamp when the record was last synchronized by Fivetran, used to track data freshness.

- name: ticket
identifier: "{{ var('zendesk_ticket_identifier', 'ticket')}}"
description: >
Expand Down Expand Up @@ -355,7 +385,7 @@ sources:
description: Information about holidays for each specified schedule.
freshness: null
config:
enabled: "{{ var('using_schedules', true) }}"
enabled: "{{ var('using_schedules', true) and var('using_holidays', true) }}"
fivetran-joemarkiewicz marked this conversation as resolved.
Show resolved Hide resolved
columns:
- name: end_date
description: ISO 8601 representation of the holiday end date.
Expand Down
26 changes: 26 additions & 0 deletions models/stg_zendesk.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,32 @@
version: 2

models:
- name: stg_zendesk__audit_log
description: >
The `audit_log` table captures historical changes and actions within Zendesk. It provides a record of modifications
made to tickets, schedules, and other objects, allowing for a detailed audit trail. Each row represents an action
performed by an actor, including the time of the action, the affected entity, and a description of the changes. This
table is especially useful for tracking schedule modifications and maintaining a history of schedule changes.
columns:
- name: audit_log_id
description: The unique identifier for each audit log entry, representing a distinct action or change.
- name: action
description: Describes the specific action performed within Zendesk, such as ticket updates or schedule modifications.
- name: actor_id
description: The unique identifier of the user or system responsible for performing the action.
- name: change_description
description: A detailed description of the changes made during the action, capturing what was altered.
- name: created_at
description: The timestamp indicating when the action was performed and recorded in the audit log.
- name: source_id
description: The unique identifier of the entity affected by the action, such as a ticket or schedule.
- name: source_label
description: A label that provides additional context about the affected entity, typically related to its type or name.
- name: source_type
description: Specifies the type of entity impacted by the action, such as a ticket, schedule, or user.
- name: _fivetran_synced
description: The timestamp when the record was last synchronized by Fivetran, used to track data freshness.

- name: stg_zendesk__ticket
description: >
Tickets are the means through which your end users (customers) communicate with agents in Zendesk Support. Tickets can
Expand Down
45 changes: 45 additions & 0 deletions models/stg_zendesk__audit_log.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{{ config(enabled=fivetran_utils.enabled_vars(['using_schedules','using_schedule_histories'])) }}

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).
*/
Comment on lines +13 to +18
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't imagine this comment is entirely necessary. We can probably remove it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was copied over since all the stg models in Zendesk have this language. Should I remove it from all of them?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's unnecessary for the scope of this task. We can leave this as is.

{{
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
cast(id as {{ dbt.type_string() }}) 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
4 changes: 2 additions & 2 deletions models/stg_zendesk__schedule_holiday.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--To disable this model, set the using_schedules variable within your dbt_project.yml file to False.
{{ config(enabled=var('using_schedules', True)) }}
--To disable this model, set the using_schedules or using_holidays variable within your dbt_project.yml file to False.
{{ config(enabled=fivetran_utils.enabled_vars(['using_schedules','using_holidays'])) }}
fivetran-joemarkiewicz marked this conversation as resolved.
Show resolved Hide resolved

with base as (

Expand Down
4 changes: 4 additions & 0 deletions models/tmp/stg_zendesk__audit_log_tmp.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{{ config(enabled=fivetran_utils.enabled_vars(['using_schedules','using_schedule_histories'])) }}

select {{ dbt_utils.star(source('zendesk','audit_log')) }}
from {{ source('zendesk','audit_log') }} as audit_log_table
4 changes: 2 additions & 2 deletions models/tmp/stg_zendesk__schedule_holiday_tmp.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--To disable this model, set the using_schedules variable within your dbt_project.yml file to False.
{{ config(enabled=var('using_schedules', True)) }}
--To disable this model, set the using_schedules or using_holidays variable within your dbt_project.yml file to False.
{{ config(enabled=fivetran_utils.enabled_vars(['using_schedules','using_holidays'])) }}

select {{ dbt_utils.star(source('zendesk', 'schedule_holiday')) }}
from {{ source('zendesk', 'schedule_holiday') }} as schedule_holiday_table