Skip to content

Commit

Permalink
Feature/order to orders (#12)
Browse files Browse the repository at this point in the history
* feature/order-to-orders

* update whitespace issues and changelog, readme.  add workflows

* update readme

* update changelog

* updates

* Update dbt_project.yml

* Apply suggestions from code review

Co-authored-by: Joe Markiewicz <[email protected]>

* add testing for both order and orders

* regen docs

---------

Co-authored-by: Joe Markiewicz <[email protected]>
  • Loading branch information
1 parent 2545b0a commit 806f31c
Show file tree
Hide file tree
Showing 15 changed files with 136 additions and 57 deletions.
4 changes: 2 additions & 2 deletions .buildkite/scripts/run_models.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ dbt seed --target "$db" --full-refresh
dbt compile --target "$db"
dbt run --target "$db" --full-refresh
dbt test --target "$db"
dbt run --vars '{recharge__one_time_product_enabled: false, recharge__address_passthrough_columns: [cart_attribute_id]}' --target "$db" --full-refresh
dbt test --vars '{recharge__one_time_product_enabled: false, recharge__address_passthrough_columns: [cart_attribute_id]}' --target "$db"
dbt run --vars '{recharge__using_orders: false, recharge__one_time_product_enabled: false, recharge__address_passthrough_columns: [cart_attribute_id]}' --target "$db" --full-refresh
dbt test --vars '{recharge__using_orders: false, recharge__one_time_product_enabled: false, recharge__address_passthrough_columns: [cart_attribute_id]}' --target "$db"

dbt run-operation fivetran_utils.drop_schemas_automation --target "$db"
42 changes: 10 additions & 32 deletions .github/PULL_REQUEST_TEMPLATE/maintainer_pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,48 +4,26 @@
**This PR will result in the following new package version:**
<!--- Please add details around your decision for breaking vs non-breaking version upgrade. If this is a breaking change, were backwards-compatible options explored? -->

**Please detail what change(s) this PR introduces and any additional information that should be known during the review of this PR:**
**Please provide the finalized CHANGELOG entry which details the relevant changes included in this PR:**
<!--- Copy/paste the CHANGELOG for this version below. -->

## PR Checklist
### Basic Validation
Please acknowledge that you have successfully performed the following commands locally:
- [ ] dbt compile
- [ ] dbt run –full-refresh
- [ ] dbt run
- [ ] dbt test
- [ ] dbt run –vars (if applicable)
- [ ] dbt run –full-refresh && dbt test
- [ ] dbt run (if incremental models are present) && dbt test

Before marking this PR as "ready for review" the following have been applied:
- [ ] The appropriate issue has been linked and tagged
- [ ] You are assigned to the corresponding issue and this PR
- [ ] The appropriate issue has been linked, tagged, and properly assigned
- [ ] All necessary documentation and version upgrades have been applied
- [ ] docs were regenerated (unless this PR does not include any code or yml updates)
- [ ] BuildKite integration tests are passing
- [ ] Detailed validation steps have been provided below

### Detailed Validation
Please acknowledge that the following validation checks have been performed prior to marking this PR as "ready for review":
- [ ] You have validated these changes and assure this PR will address the respective Issue/Feature.
- [ ] You are reasonably confident these changes will not impact any other components of this package or any dependent packages.
- [ ] You have provided details below around the validation steps performed to gain confidence in these changes.
Please share any and all of your validation steps:
<!--- Provide the steps you took to validate your changes below. -->

### Standard Updates
Please acknowledge that your PR contains the following standard updates:
- Package versioning has been appropriately indexed in the following locations:
- [ ] indexed within dbt_project.yml
- [ ] indexed within integration_tests/dbt_project.yml
- [ ] CHANGELOG has individual entries for each respective change in this PR
<!--- If there is a parallel upstream change, remember to reference the corresponding CHANGELOG as an individual entry. -->
- [ ] README updates have been applied (if applicable)
<!--- Remember to check the following README locations for common updates. →
<!--- Suggested install range (needed for breaking changes) →
<!--- Dependency matrix is appropriately updated (if applicable) →
<!--- New variable documentation (if applicable) -->
- [ ] DECISIONLOG updates have been updated (if applicable)
- [ ] Appropriate yml documentation has been added (if applicable)

### dbt Docs
Please acknowledge that after the above were all completed the below were applied to your branch:
- [ ] docs were regenerated (unless this PR does not include any code or yml updates)

### If you had to summarize this PR in an emoji, which would it be?
<!--- For a complete list of markdown compatible emojis check our this git repo (https://gist.github.com/rxaviers/7360908) -->
:dancer:
:dancer:
13 changes: 13 additions & 0 deletions .github/workflows/auto-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: 'auto release'
on:
pull_request:
types:
- closed
branches:
- main

jobs:
call-workflow-passing-data:
if: github.event.pull_request.merged
uses: fivetran/dbt_package_automations/.github/workflows/auto-release.yml@main
secrets: inherit
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
# dbt_recharge_source v0.2.0
[PR #12](https://github.com/fivetran/dbt_recharge_source/pull/12) includes the following updates:
## Features
- For Fivetran Recharge connectors created on or after June 18, 2024, the `ORDER` source table has been renamed to `ORDERS`. The package will now use the `ORDERS` table if it exists and then `ORDER` if not.
- If you have both versions but wish to use the `ORDER` table instead, you can set the variable `recharge__using_orders` to false in your `dbt_project.yml`.
- See the [June 2024 connector release notes](https://fivetran.com/docs/connectors/applications/recharge/changelog#june2024) and the related
[README section](https://github.com/fivetran/dbt_recharge_source/blob/main/README.md##leveraging-orders-vs-orders-source) for more details.

## Under the Hood:
- Updated the pull request templates.
- Included auto-releaser GitHub Actions workflow to automate future releases.

# dbt_recharge_source v0.1.1
[PR #10](https://github.com/fivetran/dbt_recharge_source/pull/10) includes the following updates:
## Bug fixes
Expand Down
17 changes: 13 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Include the following recharge_source package version in your `packages.yml` fil
```yml
packages:
- package: fivetran/recharge_source
version: [">=0.1.0", "<0.2.0"] # we recommend using ranges to capture non-breaking changes automatically
version: [">=0.2.0", "<0.3.0"] # we recommend using ranges to capture non-breaking changes automatically
```

## Step 3: Define database and schema variables
Expand All @@ -63,7 +63,16 @@ vars:
```

## (Optional) Step 5: Additional configurations
<details><summary>Expand for configurations</summary>
<details open><summary>Expand for configurations</summary>

### Leveraging `orders` vs `order` source
For Fivetran Recharge connectors created on or after June 18, 2024, the `ORDER` source table has been renamed to `ORDERS`. Refer to the [June 2024 connector release notes](https://fivetran.com/docs/connectors/applications/recharge/changelog#june2024) for more information.

The package will default to use the `ORDERS` table if it exists and then `ORDER` if not. If you have both versions but wish to use the `ORDER` table instead, you can set the variable `recharge__using_orders` to false in your `dbt_project.yml` file.
```yml
vars:
recharge__using_orders: false # default is true, which will use the `orders` version of the source.
```

### Passing Through Additional Columns
This package includes all source columns defined in the macros folder. If you would like to pass through additional columns to the staging models, add the following configurations to your `dbt_project.yml` file. These variables allow for the pass-through fields to be aliased (`alias`) and casted (`transform_sql`) if desired, but not required. Datatype casting is configured via a SQL snippet within the `transform_sql` key. You may add the desired SQL while omitting the `as field_name` at the end, and your custom pass-though fields will be casted accordingly. Use the below format for declaring the respective pass-through variables in your root `dbt_project.yml`.
Expand Down Expand Up @@ -105,13 +114,13 @@ vars:
#### 🚨 Snowflake Users 🚨
You may need to provide the case-sensitive spelling of your source tables that are also Snowflake reserved words.

In this package, this would apply to the `ORDER` source. If you are receiving errors for this source, include the following in your `dbt_project.yml` file:
In this package, this would apply to the `ORDER` source. If you are receiving errors for this source, include the following in your `dbt_project.yml` file. (**Note:** This should not be necessary for the `ORDERS` source table.)
```yml
vars:
recharge_order_identifier: '"Order"' # as an example, must include this quoting pattern and adjust for your exact casing
```

**Note!** if you have sources defined in your project's yml, the above will not work. Instead you will need to add the following where your order table is defined in your yml:
**Note!** If you have sources defined in your project's yml, the above will not work. Instead you will need to add the following where your order table is defined in your yml:
```yml
sources:
tables:
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 @@

name: 'recharge_source'
version: '0.1.1'
version: '0.2.0'
config-version: 2
require-dbt-version: [">=1.3.0", "<2.0.0"]

Expand All @@ -19,6 +19,7 @@ vars:
discount: "{{ source('recharge','discount') }}"
one_time_product: "{{ source('recharge','one_time_product') }}"
order: "{{ source('recharge','order') }}"
orders: "{{ source('recharge','orders') }}"
order_line_item: "{{ source('recharge','order_line_item') }}"
subscription: "{{ source('recharge','subscription') }}"
subscription_history: "{{ source('recharge','subscription_history') }}"
Expand Down
2 changes: 1 addition & 1 deletion docs/catalog.json

Large diffs are not rendered by default.

24 changes: 12 additions & 12 deletions docs/index.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/manifest.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/run_results.json

Large diffs are not rendered by default.

6 changes: 5 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: 'recharge_source_integration_tests'
version: '0.1.1'
version: '0.2.0'

profile: 'integration_tests'

Expand All @@ -22,6 +22,7 @@ vars:
recharge_one_time_product_identifier: "one_time_product_data"
order: "{{ ref('order_data') }}" # Comment out for generating docs -- Uncomment this before sending to buildkite.
# recharge_order_identifier: "order_data" # Uncomment for generating docs -- Comment this out before sending to buildkite.
recharge_orders_identifier: "orders_data"
recharge_order_line_item_identifier: "order_line_item_data"
recharge_subscription_identifier: "subscription_data"
recharge_subscription_history_identifier: "subscription_history_data"
Expand Down Expand Up @@ -69,3 +70,6 @@ seeds:
order_data:
+column_types:
SHIPPED_DATE: "timestamp"
orders_data:
+column_types:
SHIPPED_DATE: "timestamp"
3 changes: 3 additions & 0 deletions integration_tests/seeds/orders_data.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ID,CUSTOMER_ID,ADDRESS_ID,CHARGE_ID,IS_DELETED,EMAIL,TRANSACTION_ID,CHARGE_STATUS,IS_PREPAID,STATUS,TOTAL_PRICE,TYPE,EXTERNAL_ORDER_ID_ECOMMERCE,EXTERNAL_ORDER_NUMBER_ECOMMERCE,CREATED_AT,UPDATED_AT,PROCESSED_AT,SCHEDULED_AT,SHIPPED_DATE,_FIVETRAN_SYNCED
11000001,90000001,300000001,400000001,FALSE,[email protected],ch_3La00000000000000000001uS,SUCCESS,FALSE,SUCCESS,14.45,RECURRING,13000001,14000001,2022-08-24T05:27:25Z,2022-08-24T05:27:26Z,2022-08-24T05:27:27Z,2022-08-24T04:00:00Z,2022-08-24T05:27:27Z,2022-08-25T03:57:07.416Z
11000002,90000002,300000002,400000002,FALSE,[email protected],ch_3La00000000000000000002uS,SUCCESS,FALSE,SUCCESS,11.95,RECURRING,13000002,14000002,2022-08-24T05:07:12Z,2022-08-24T05:07:14Z,2022-08-24T05:07:15Z,2022-08-24T04:00:00Z,2022-08-24T05:07:15Z,2022-08-25T03:57:06.225Z
13 changes: 13 additions & 0 deletions macros/recharge_does_table_exist.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{%- macro recharge_does_table_exist(table_name) -%}

{%- if execute -%}
{%- set source_relation = adapter.get_relation(
database=source('recharge', table_name).database,
schema=source('recharge', table_name).schema,
identifier=source('recharge', table_name).name) -%}

{% set table_exists=source_relation is not none %}
{{ return(table_exists) }}
{%- endif -%}

{% endmacro %}
47 changes: 46 additions & 1 deletion models/src_recharge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ sources:
- name: _fivetran_synced
description: "{{ doc('_fivetran_synced') }}"

- name: order
- name: order # applies to connectors created before 2024-06-18
identifier: >
{%- if target.type == 'snowflake' -%} {{ var('recharge_order_identifier', 'ORDER') }}
{%- else -%} {{ var('recharge_order_identifier', 'order') }} {%- endif -%}
Expand Down Expand Up @@ -425,6 +425,51 @@ sources:
- name: _fivetran_synced
description: "{{ doc('_fivetran_synced') }}"

- name: orders # applies to connectors created on or after 2024-06-18
identifier: "{{ var('recharge_orders_identifier', 'orders') }}"
description: Table of all orders after a charge is successfully processed.
columns:
- name: id
description: "{{ doc('order_id') }}"
- name: customer_id
description: "{{ doc('customer_id') }}"
- name: address_id
description: "{{ doc('address_id') }}"
- name: charge_id
description: The unique numeric identifier of the charge.
- name: is_deleted
description: Boolean indicating if the order (record) is deleted.
- name: email
description: The email address of the customer.
- name: transaction_id
description: The unique alphanumeric identifier of the transaction.
- name: charge_status
description: "{{ doc('charge_status') }}"
- name: is_prepaid
description: Boolean indicating if the Order is prepaid.
- name: status
description: "{{ doc('order_status') }}"
- name: total_price
description: The sum of all prices of the item in the order with taxes and discounts included (must be positive).
- name: type
description: "{{ doc('type') }}"
- name: external_order_id_ecommerce
description: Unique numeric identifier within your external ecommerce platform for the order.
- name: external_order_number_ecommerce
description: The unique order number within your external ecommerce platform.
- name: created_at
description: The date and time when the order was created.
- name: updated_at
description: The date and time when the order was last updated.
- name: processed_at
description: The date and time when the order was submitted.
- name: scheduled_at
description: The date and time when the order will be shipped.
- name: shipped_date
description: The date when the order will be processed.
- name: _fivetran_synced
description: "{{ doc('_fivetran_synced') }}"

- name: order_line_item
identifier: "{{ var('recharge_order_line_item_identifier','order_line_item') }}"
description: Table of all order line items. Each line containing information about an item in the order.
Expand Down
3 changes: 2 additions & 1 deletion models/tmp/stg_recharge__order_tmp.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

select *
from {{ var('order') }}
from
{{ var('orders') if var('recharge__using_orders', recharge_source.recharge_does_table_exist('orders')) else var('order') }}

0 comments on commit 806f31c

Please sign in to comment.