diff --git a/README.md b/README.md index bbf3d4f..c2aab98 100644 --- a/README.md +++ b/README.md @@ -16,60 +16,38 @@ salesforce\_sales\_snapshot|A single row snapshot that provides various metrics salesforce\_opportunity\_enhanced|Each record represents an opportunity, enriched with related data about the account and opportunity owner. -## Upcoming changes with dbt version 0.17.0 - -As a result of functionality being released with version 0.17.0 of dbt, there will be some upcoming changes to this package. The staging/adapter models will move into a seperate package, `salesforce_source`, that defines the staging models and adds a source for Salesforce data. The two packages will work together seamlessly. By default, this package will reference models in the source package, unless the config is overridden. - -There are a few benefits to this approach: -* If you want to manage your own transformations, you can still benefit from the source definition, documentation, and staging models of the source package. -* If you have multiple sets of Salesforce data in your warehouse, a package defining sources doesn't make sense. You will have to define your own sources and union that data together. At that point, you will still be able to make use of this package to transform their data. - -When this change occurs, we will release a new version of this package. - ## Installation Instructions -Check [dbt Hub](https://hub.getdbt.com/) for the latest installation instructions, or [read the docs](https://docs.getdbt.com/docs/package-management) for more information on installing packages. +Check [dbt Hub](https://hub.getdbt.com/) for the latest installation instructions, or [read the dbt docs](https://docs.getdbt.com/docs/package-management) for more information on installing packages. ## Configuration - -The following [variables](https://docs.getdbt.com/docs/using-variables) are needed to configure this package: - -**variable**|**information**|**required** ------|-----|----- -account|Table, model, or source containing account details|Yes -opportunity|Table, model, or source containing opportunity details|Yes -user|Table, model, or source containing user details|Yes -user\_role|Table, model, or source containing user role details|Yes - - -An example `dbt_project.yml` configuration: +By default, this package looks for your Salesforce data in the `salesforce` schema of your [target database](https://docs.getdbt.com/docs/running-a-dbt-project/using-the-command-line-interface/configure-your-profile). If this is not where your Salesforce data is, add the following configuration to your `dbt_project.yml` file: ```yml # dbt_project.yml ... +config-version: 2 -models: - salesforce: - vars: - account: "{{ source('salesforce', 'account') }}" # or "{{ ref('salesforce_account_unioned'}) }}" - opportunity: "{{ source('salesforce', 'opportunity') }}" - user: "{{ source('salesforce', 'user') }}" - user_role: "{{ source('salesforce', 'user_role') }}" +vars: + salesforce_schema: your_database_name + salesforce_database: your_schema_name ``` +For additional configurations for the source models, visit the [Salesforce source package](https://github.com/fivetran/dbt_salesforce_source). + ## Contributions Additional contributions to this package are very welcome! Please create issues -or open PRs against `master`. Check out -[this post](https://discourse.getdbt.com/t/contributing-to-a-dbt-package/657) +or open PRs against `master`. Check out [this post](https://discourse.getdbt.com/t/contributing-to-a-dbt-package/657) on the best workflow for contributing to a package. ## Resources: +- Provide [feedback](https://www.surveymonkey.com/r/DQ7K7WW) on our existing dbt packages or what you'd like to see next - Find all of Fivetran's pre-built dbt packages in our [dbt hub](https://hub.getdbt.com/fivetran/) -- Learn more about Fivetran [here](https://fivetran.com/docs) +- Learn more about Fivetran [in the Fivetran docs](https://fivetran.com/docs) - Check out [Fivetran's blog](https://fivetran.com/blog) -- Learn more about dbt [in the docs](https://docs.getdbt.com/docs/introduction) +- Learn more about dbt [in the dbt docs](https://docs.getdbt.com/docs/introduction) - Check out [Discourse](https://discourse.getdbt.com/) for commonly asked questions and answers - Join the [chat](http://slack.getdbt.com/) on Slack for live discussions and support - Find [dbt events](https://events.getdbt.com) near you -- Check out [the blog](https://blog.getdbt.com/) for the latest news on dbt's development and best practices +- Check out [the dbt blog](https://blog.getdbt.com/) for the latest news on dbt's development and best practices diff --git a/dbt_project.yml b/dbt_project.yml index efb19ff..47413df 100644 --- a/dbt_project.yml +++ b/dbt_project.yml @@ -1,12 +1,12 @@ +config-version: 2 + name: 'salesforce' version: '0.0.1' -require-dbt-version: [">=0.16.0", "<0.17.0"] +require-dbt-version: [">=0.18.0", "<0.19.0"] models: salesforce: materialized: table - base: - materialized: ephemeral intermediate: materialized: ephemeral \ No newline at end of file diff --git a/models/base/schema.yml b/models/base/schema.yml deleted file mode 100644 index 9b68cbb..0000000 --- a/models/base/schema.yml +++ /dev/null @@ -1,31 +0,0 @@ -version: 2 - -models: - - - name: stg_salesforce_account - columns: - - name: account_id - tests: - - not_null - - unique - - - name: stg_salesforce_opportunity - columns: - - name: opportunity_id - tests: - - not_null - - unique - - - name: stg_salesforce_user - columns: - - name: user_id - tests: - - not_null - - unique - - - name: stg_salesforce_user_role - columns: - - name: user_role_id - tests: - - not_null - - unique diff --git a/models/base/stg_salesforce_account.sql b/models/base/stg_salesforce_account.sql deleted file mode 100644 index c444c2e..0000000 --- a/models/base/stg_salesforce_account.sql +++ /dev/null @@ -1,22 +0,0 @@ -with base as ( - - select * - from {{ var('account')}} - where not is_deleted - -), fields as ( - - select - - id as account_id, - name as account_name, - industry, - number_of_employees, - account_source - - from base - -) - -select * -from fields \ No newline at end of file diff --git a/models/base/stg_salesforce_opportunity.sql b/models/base/stg_salesforce_opportunity.sql deleted file mode 100644 index 5ef96e3..0000000 --- a/models/base/stg_salesforce_opportunity.sql +++ /dev/null @@ -1,34 +0,0 @@ -with base as ( - - select * - from {{ var('opportunity')}} - where not is_deleted - -), fields as ( - - select - - id as opportunity_id, - account_id as opportunity_account_id, - amount, - probability, - created_date, - is_won, - is_closed, - forecast_category, - stage_name, - owner_id, - close_date, - created_date >= {{ dbt_utils.date_trunc('month', dbt_utils.current_timestamp()) }} as is_created_this_month, - created_date >= {{ dbt_utils.date_trunc('quarter', dbt_utils.current_timestamp()) }} as is_created_this_quarter, - {{ dbt_utils.datediff(dbt_utils.current_timestamp(), 'created_date', 'day') }} as days_since_created, - {{ dbt_utils.datediff('close_date', 'created_date', 'day') }} as days_to_close, - {{ dbt_utils.date_trunc('month', 'close_date') }} = {{ dbt_utils.date_trunc('month', dbt_utils.current_timestamp()) }} as is_closed_this_month, - {{ dbt_utils.date_trunc('quarter', 'close_date') }} = {{ dbt_utils.date_trunc('quarter', dbt_utils.current_timestamp()) }} as is_closed_this_quarter - - from base - -) - -select * -from fields diff --git a/models/base/stg_salesforce_user.sql b/models/base/stg_salesforce_user.sql deleted file mode 100644 index f24b0c4..0000000 --- a/models/base/stg_salesforce_user.sql +++ /dev/null @@ -1,20 +0,0 @@ -with base as ( - - select * - from {{ var('user')}} - -), fields as ( - - select - id as user_id, - name, - city, - state, - manager_id, - user_role_id - from base - -) - -select * -from fields diff --git a/models/base/stg_salesforce_user_role.sql b/models/base/stg_salesforce_user_role.sql deleted file mode 100644 index e972ae1..0000000 --- a/models/base/stg_salesforce_user_role.sql +++ /dev/null @@ -1,20 +0,0 @@ - -with base as ( - - select * - from {{ var('user_role')}} - where not _fivetran_deleted - -), fields as ( - - select - - id as user_role_id, - name as role_name - - from base - -) - -select * -from fields \ No newline at end of file diff --git a/models/salesforce_sales_snapshot.sql b/models/salesforce_sales_snapshot.sql index b59792f..be10790 100644 --- a/models/salesforce_sales_snapshot.sql +++ b/models/salesforce_sales_snapshot.sql @@ -54,7 +54,25 @@ select bookings.*, pipeline.*, lost.*, - round((bookings.bookings_amount_closed_this_month / (bookings.bookings_amount_closed_this_month + lost.lost_amount_this_month)) * 100, 2 ) as win_percent_this_month, - round((bookings.bookings_amount_closed_this_quarter / (bookings.bookings_amount_closed_this_quarter + lost.lost_amount_this_quarter)) * 100, 2 ) as win_percent_this_quarter, - round((bookings.total_bookings_amount / (bookings.total_bookings_amount + lost.total_lost_amount)) * 100, 2) as total_win_percent + case when (bookings.bookings_amount_closed_this_month + lost.lost_amount_this_month) = 0 then null + else + round( + (bookings.bookings_amount_closed_this_month / + (bookings.bookings_amount_closed_this_month + lost.lost_amount_this_month) + ) * 100, 2 ) + end as win_percent_this_month, + case when (bookings.bookings_amount_closed_this_quarter + lost.lost_amount_this_quarter) = 0 then null + else + round( + (bookings.bookings_amount_closed_this_quarter / + (bookings.bookings_amount_closed_this_quarter + lost.lost_amount_this_quarter) + ) * 100, 2 ) + end as win_percent_this_quarter, + case when (bookings.total_bookings_amount + lost.total_lost_amount) = 0 then null + else + round( + (bookings.total_bookings_amount / + (bookings.total_bookings_amount + lost.total_lost_amount) + ) * 100, 2) + end as total_win_percent from bookings, pipeline, lost \ No newline at end of file diff --git a/packages.yml b/packages.yml index a204654..e49f9bf 100644 --- a/packages.yml +++ b/packages.yml @@ -1,3 +1,4 @@ packages: - - package: fishtown-analytics/dbt_utils - version: 0.3.0 \ No newline at end of file + + - package: fivetran/salesforce_source + version: 0.1.0 \ No newline at end of file