Skip to content

Commit

Permalink
Merge pull request #10 from fivetran/dbt_version_upgrade
Browse files Browse the repository at this point in the history
Salesforce package upgrades
  • Loading branch information
kristin-bagnall authored Oct 23, 2020
2 parents 5f81995 + 53becf7 commit 7cce447
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 170 deletions.
48 changes: 13 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions dbt_project.yml
Original file line number Diff line number Diff line change
@@ -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
31 changes: 0 additions & 31 deletions models/base/schema.yml

This file was deleted.

22 changes: 0 additions & 22 deletions models/base/stg_salesforce_account.sql

This file was deleted.

34 changes: 0 additions & 34 deletions models/base/stg_salesforce_opportunity.sql

This file was deleted.

20 changes: 0 additions & 20 deletions models/base/stg_salesforce_user.sql

This file was deleted.

20 changes: 0 additions & 20 deletions models/base/stg_salesforce_user_role.sql

This file was deleted.

24 changes: 21 additions & 3 deletions models/salesforce_sales_snapshot.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 3 additions & 2 deletions packages.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
packages:
- package: fishtown-analytics/dbt_utils
version: 0.3.0

- package: fivetran/salesforce_source
version: 0.1.0

0 comments on commit 7cce447

Please sign in to comment.