Skip to content

Add stg_host_project_ordinals staging model - #1

Open
Diego-Turno wants to merge 1 commit into
mainfrom
pr-review-test
Open

Diego-Turno wants to merge 1 commit into
mainfrom
pr-review-test

Conversation

@Diego-Turno

@Diego-Turno Diego-Turno commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

Business context

Turno is a marketplace connecting short-term-rental hosts with cleaners. A host books a cleaning project, a cleaner completes it, and the host's payment method is charged. Growth and lifecycle analyses need to know when each host account hit its project milestones — specifically the completion dates of the account's 1st, 2nd, 3rd, and 5th marketplace projects, plus the 1st completed project overall (marketplace or not).

This PR adds stg_host_project_ordinals, one row per account_id, exposing those milestone timestamps so downstream models can measure activation and repeat usage (e.g. "how long from first to second marketplace project?").

Business definitions the model must follow:

  • The analyst was asked to consider the paid date as the project's completion date: a project is completed when its payment is captured. There is exactly one successful payment per completed project, and its captured_at timestamp is the completion date used here.
  • Marketplace projects are payment logs with from_marketplace = 1; everything else is non-marketplace.
  • Ordinals are chronological, oldest first: the "2nd marketplace project" is the 2nd-earliest capture for that account.

Team rules

  1. All SQL syntax must be in uppercase.
  2. Descriptions and tests live only in the YML files (code comments allowed when needed).
  3. Never use direct paths to database tables — always use the jinja references:
    • Production tables: {{ source('production', 'table_name') }}
    • dbt tables: {{ ref('table_name') }}
  4. Assume a project only has one successful payment.
  5. Configs belong in the SQL file, not the YML.

Tables and columns used

payment_logs (production) — one row per payment attempt

Column Description
host_id The host being charged
project_id The project being paid for
from_marketplace 1 if the payment is for a marketplace project, 0 otherwise
captured_at When money actually moved; NULL if it never did

hosts (production) — one row per host

Column Description
id Host primary key
account_id The account the host belongs to

projects (production) — one row per project

Column Description
id Project primary key
completed_at When the cleaner completed the project

@TidyDaily TidyDaily deleted a comment from thainaventeu Aug 31, 2026
@TidyDaily TidyDaily deleted a comment from thainaventeu Aug 31, 2026
@TidyDaily TidyDaily deleted a comment from thainaventeu Aug 31, 2026
@TidyDaily TidyDaily deleted a comment from beatrizsbuani Sep 8, 2026
@TidyDaily TidyDaily deleted a comment from beatrizsbuani Sep 8, 2026
@TidyDaily TidyDaily deleted a comment from beatrizsbuani Sep 8, 2026
@TidyDaily TidyDaily deleted a comment from beatrizsbuani Sep 8, 2026
@TidyDaily TidyDaily deleted a comment from beatrizsbuani Sep 8, 2026
@TidyDaily TidyDaily deleted a comment from beatrizsbuani Sep 8, 2026
relation: true
columns: true
description: >
A staging table that captures ordinal marketplace project completion dates (2nd, 3rd, 5th) by account,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its missing the 1st one marketing place completed.

SELECT
h.account_id,
pl.captured_at AS marketplace_project_completed_at,
ROW_NUMBER() OVER (

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DESC should not be used here, because we need the oldest first

pl.captured_at AS marketplace_project_completed_at,
ROW_NUMBER() OVER (
PARTITION BY c.account_id
ORDER BY a.completed_at DESC

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the ORDER BY clause should be captered_at

{{ source('production', 'projects') }} p
ON pl.project_id = p.id
WHERE
pl.from_marketplace = 0

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pl.from_marketplace should be = 1

pl.captured_at AS overall_project_completed_at,
ROW_NUMBER() OVER (
PARTITION BY h.account_id
ORDER BY p.completed_at DESC

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the ORDER BY clause should be captered_at

{{ source('production', 'hosts') }} h
ON pl.host_id = h.id
LEFT JOIN
turno.turno_production_schema.projects p

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to use {{ source('production', 'table_name') }}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants