Skip to content

Commit

Permalink
Merge pull request #2 from EvavW/models-module
Browse files Browse the repository at this point in the history
finish fundamentals
  • Loading branch information
EvavW authored Apr 8, 2022
2 parents 471e8ef + c14a4eb commit f79a5ad
Show file tree
Hide file tree
Showing 11 changed files with 96 additions and 64 deletions.
27 changes: 0 additions & 27 deletions models/example/my_first_dbt_model.sql

This file was deleted.

6 changes: 0 additions & 6 deletions models/example/my_second_dbt_model.sql

This file was deleted.

21 changes: 0 additions & 21 deletions models/example/schema.yml

This file was deleted.

13 changes: 13 additions & 0 deletions models/staging/jaffle_shop/jaffle_shop,md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{% docs order_status %}

One of the following values:

| status | definition |
|----------------|--------------------------------------------------|
| placed | Order placed, not yet shipped |
| shipped | Order has been shipped, not yet been delivered |
| completed | Order has been received by customers |
| return pending | Customer indicated they want to return this item |
| returned | Item has been returned |

{% enddocs %}
19 changes: 19 additions & 0 deletions models/staging/jaffle_shop/src_jaffle_shop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
version: 2

sources:
- name: jaffle_shop
database: dbt-tutorial

schema: jaffle_shop
tables:
- name: customers
loaded_at_field: _batched_at
freshness:
warn_after: {count: 12, period: hour}
error_after: {count: 24, period: hour}
- name: orders
loaded_at_field: _batched_at
freshness:
warn_after: {count: 12, period: hour}
error_after: {count: 24, period: hour}

5 changes: 2 additions & 3 deletions models/staging/jaffle_shop/stg_customers.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
select
select
id as customer_id,
first_name,
last_name

from dbt-tutorial.jaffle_shop.customers
from {{ source('jaffle_shop', 'customers') }}
36 changes: 36 additions & 0 deletions models/staging/jaffle_shop/stg_jaffle_shop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
version: 2

models:
- name: stg_customers
description: Staged customer data from our jaffle shop app.
columns:
- name: customer_id
description: The primary key for customers.
tests:
- unique
- not_null

- name: stg_orders
description: Staged order data from our jaffle shop app.
columns:
- name: order_id
description: Primary key for orders.
tests:
- unique
- not_null
- name: status
description: "{{ doc('order_status') }}"
tests:
- accepted_values:
values:
- completed
- shipped
- returned
- placed
- return_pending
- name: customer_id
description: Foreign key to stg_customers.customer_id.
tests:
- relationships:
to: ref('stg_customers')
field: customer_id
3 changes: 1 addition & 2 deletions models/staging/jaffle_shop/stg_orders.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ select
user_id as customer_id,
order_date,
status

from dbt-tutorial.jaffle_shop.orders
from {{ source('jaffle_shop', 'orders') }}
10 changes: 5 additions & 5 deletions models/staging/stripe/stg_payments.sql
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
select
id as payment_id,
orderid as order_id,
paymentmethod,
paymentmethod as payment_method,
status,
amount,
created,
_batched_at
-- amount is stored in cents, convert it to dollars
amount / 100 as amount,
created as created_at
from {{ source('stripe', 'payment') }}

from dbt-tutorial.stripe.payment
12 changes: 12 additions & 0 deletions models/staging/stripe/stg_payments.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: 2

sources:
- name: stripe
database: dbt-tutorial
schema: stripe
tables:
- name: payment
loaded_at_field: _batched_at
freshness:
warn_after: {count: 12, period: hour}
error_after: {count: 24, period: hour}
8 changes: 8 additions & 0 deletions tests/assert_positive_value_for_total_amount.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-- Refunds have a negative amount, so the total amount should always be >= 0.
-- Therefore return records where this isn't true to make the test fail.
select
order_id,
sum(amount) as total_amount
from {{ ref('stg_payments') }}
group by 1
having not(total_amount >= 0)

0 comments on commit f79a5ad

Please sign in to comment.