diff --git a/connectors/source_recurly/models/fivetran_converter/account_history.sql b/connectors/source_recurly/models/fivetran_converter/account_history.sql index 74526773..54242f3a 100644 --- a/connectors/source_recurly/models/fivetran_converter/account_history.sql +++ b/connectors/source_recurly/models/fivetran_converter/account_history.sql @@ -2,100 +2,90 @@ WITH tmp AS ( SELECT - t.id AS user_id, - NULL AS external_id, - NULL AS _fivetran_synced, - NULL AS last_login_at, - cast(t.created_at as {{ dbt.type_timestamp() }}) AS created_at, - cast(t.updated_at as {{ dbt.type_timestamp() }}) AS updated_at, - t.email AS email, - t.name AS name, - t.organization_id AS organization_id, - t.phone AS phone, - {% if var('internal_user_criteria', false) -%} - CASE - WHEN t.role IN ('admin', 'agent') THEN t.role - WHEN {{ var('internal_user_criteria', false) }} THEN 'agent' - ELSE t.role END AS role, - {% else -%} - t.role AS role, - {% endif -%} - t.ticket_restriction AS ticket_restriction, - t.time_zone AS time_zone, - t.locale AS locale, - t.active AS is_active, - t.suspended AS is_suspended + id AS account_id, + cast(updated_at AS {{ dbt.type_timestamp() }}) AS updated_at, + NULL AS account_city, + NULL AS account_country, + NULL AS account_postal_code, + NULL AS account_region, + bill_to, + cc_emails, + code, + company, + cast(created_at AS {{ dbt.type_timestamp() }}) AS created_at, + cast(deleted_at AS {{ dbt.type_timestamp() }}) AS deleted_at, + email, + first_name, + ROW_NUMBER() OVER (PARTITION BY id ORDER BY updated_at DESC) = 1 AS is_most_recent_record, + tax_exempt AS is_tax_exempt, + last_name, + state, + username, + vat_number FROM - {{ source('source_recurly', 'accounts') }} t + {{ source('source_recurly', 'accounts') }} ) SELECT * FROM tmp - WHERE user_id IS NOT NULL - + WHERE account_id IS NOT NULL {% elif target.type == "snowflake" %} WITH tmp AS ( SELECT - t.id AS user_id, - NULL AS external_id, - NULL AS _fivetran_synced, - NULL AS last_login_at, - cast(t.created_at as {{ dbt.type_timestamp() }}) AS created_at, - cast(t.updated_at as {{ dbt.type_timestamp() }}) AS updated_at, - t.email AS email, - t.name AS name, - t.organization_id AS organization_id, - t.phone AS phone, - {% if var('internal_user_criteria', false) -%} - CASE - WHEN t.role IN ('admin', 'agent') THEN t.role - WHEN {{ var('internal_user_criteria', false) }} THEN 'agent' - ELSE t.role END AS role, - {% else -%} - t.role AS role, - {% endif -%} - t.ticket_restriction AS ticket_restriction, - t.time_zone AS time_zone, - t.locale AS locale, - t.active AS is_active, - t.suspended AS is_suspended + id AS account_id, + cast(updated_at AS {{ dbt.type_timestamp() }}) AS updated_at, + NULL AS account_city, + NULL AS account_country, + NULL AS account_postal_code, + NULL AS account_region, + bill_to, + cc_emails, + code, + company, + cast(created_at AS {{ dbt.type_timestamp() }}) AS created_at, + cast(deleted_at AS {{ dbt.type_timestamp() }}) AS deleted_at, + email, + first_name, + ROW_NUMBER() OVER (PARTITION BY id ORDER BY updated_at DESC) = 1 AS is_most_recent_record, + tax_exempt AS is_tax_exempt, + last_name, + state, + username, + vat_number FROM - {{ source('source_recurly', 'accounts') }} t + {{ source('source_recurly', 'accounts') }} ) SELECT * FROM tmp - WHERE user_id IS NOT NULL + WHERE account_id IS NOT NULL {% elif target.type == "bigquery" %} WITH tmp AS ( SELECT - t.id AS user_id, - NULL AS external_id, - NULL AS _fivetran_synced, - NULL AS last_login_at, - cast(t.created_at as {{ dbt.type_timestamp() }}) AS created_at, - cast(t.updated_at as {{ dbt.type_timestamp() }}) AS updated_at, - t.email AS email, - t.name AS name, - t.organization_id AS organization_id, - t.phone AS phone, - {% if var('internal_user_criteria', false) -%} - CASE - WHEN t.role IN ('admin', 'agent') THEN t.role - WHEN {{ var('internal_user_criteria', false) }} THEN 'agent' - ELSE t.role END AS role, - {% else -%} - t.role AS role, - {% endif -%} - t.ticket_restriction AS ticket_restriction, - t.time_zone AS time_zone, - t.locale AS locale, - t.active AS is_active, - t.suspended AS is_suspended + id AS account_id, + cast(updated_at AS {{ dbt.type_timestamp() }}) AS updated_at, + NULL AS account_city, + NULL AS account_country, + NULL AS account_postal_code, + NULL AS account_region, + bill_to, + cc_emails, + code, + company, + cast(created_at AS {{ dbt.type_timestamp() }}) AS created_at, + cast(deleted_at AS {{ dbt.type_timestamp() }}) AS deleted_at, + email, + first_name, + ROW_NUMBER() OVER (PARTITION BY id ORDER BY updated_at DESC) = 1 AS is_most_recent_record, + tax_exempt AS is_tax_exempt, + last_name, + state, + username, + vat_number FROM - {{ source('source_recurly', 'accounts') }} t + {{ source('source_recurly', 'accounts') }} ) SELECT * FROM tmp - WHERE user_id IS NOT NULL + WHERE account_id IS NOT NULL -{% endif %} +{% endif %} \ No newline at end of file diff --git a/connectors/source_recurly/models/fivetran_converter/account_history.yml b/connectors/source_recurly/models/fivetran_converter/account_history.yml index 896f40f5..108ec279 100644 --- a/connectors/source_recurly/models/fivetran_converter/account_history.yml +++ b/connectors/source_recurly/models/fivetran_converter/account_history.yml @@ -9,35 +9,43 @@ models: config: +enabled: "{{ var('using_fivetran_model', False) }}" columns: - - name: user_id - description: Unique identifier of the user account - - name: external_id - description: External identifier associated with the user account - - name: _fivetran_synced - description: Timestamp indicating when the data was synced by Fivetran - - name: last_login_at - description: Date and time when the user last logged in - - name: created_at - description: Date and time when the user account was created + - name: account_id + description: Unique identifier of the account - name: updated_at - description: Date and time when the user account was last updated + description: Date and time when the account was last updated + - name: account_city + description: City of the account (Note- This field may be NULL as it's not present in the original schema) + - name: account_country + description: Country of the account (Note- This field may be NULL as it's not present in the original schema) + - name: account_postal_code + description: Postal code of the account (Note- This field may be NULL as it's not present in the original schema) + - name: account_region + description: Region of the account (Note- This field may be NULL as it's not present in the original schema) + - name: bill_to + description: The billing details + - name: cc_emails + description: Email addresses for carbon copy (CC) + - name: code + description: Unique code assigned to the account + - name: company + description: Company associated with the account + - name: created_at + description: Date and time when the account was created + - name: deleted_at + description: Date and time when the account was deleted - name: email - description: Email address of the user - - name: name - description: Name of the user - - name: organization_id - description: Identifier of the organization associated with the user - - name: phone - description: Phone number of the user - - name: role - description: Role of the user within the system - - name: ticket_restriction - description: Restrictions applied to user tickets - - name: time_zone - description: Time zone of the user - - name: locale - description: Locale setting of the user - - name: is_active - description: Indicates if the user account is active - - name: is_suspended - description: Indicates if the user account is suspended + description: Email address of the account holder + - name: first_name + description: First name of the account holder + - name: is_most_recent_record + description: Flag indicating if this is the most recent record for the account + - name: is_tax_exempt + description: Flag indicating if the account is tax exempt + - name: last_name + description: Last name of the account holder + - name: state + description: State/province of the account address + - name: username + description: Username of the account holder + - name: vat_number + description: VAT (Value Added Tax) number of the account diff --git a/connectors/source_recurly/models/fivetran_converter/account_note_history.sql b/connectors/source_recurly/models/fivetran_converter/account_note_history.sql index e1a4cf91..5f8bbc38 100644 --- a/connectors/source_recurly/models/fivetran_converter/account_note_history.sql +++ b/connectors/source_recurly/models/fivetran_converter/account_note_history.sql @@ -28,7 +28,7 @@ message, object, created_by AS user_email, - NULL AS user_id, -- This field is not present in the original schema + NULL AS user_id, ROW_NUMBER() OVER (PARTITION BY id ORDER BY updated_at DESC) = 1 AS is_most_recent_record FROM {{ source('source_recurly', 'account_notes') }}