Fix window function missing PARTITION BY causing incorrect customer activity calculations
harbor run -t snowflake-labs/dbt-fix-customer-churnharbor download snowflake-labs/dbt-fix-customer-churnBuild a dbt model called fct_customer_activity that tracks customer order history for churn analysis.
Create the model at:
/app/dbt_models_duckdb/models/marts/customer/fct_customer_activity.sql/app/dbt_models_snowflake/models/marts/customer/fct_customer_activity.sqlThe model should have these columns:
customer_id - Customer identifieremail - Customer email addressorder_id - Order identifierorder_date - Order date (DATE type, not timestamp)previous_order_date - Previous order's date for this customer (DATE type). Use the DATE-typed order_date for window function calculations, not the raw timestamp.days_since_last_order - Days between consecutive orders (based on DATE values)is_reactivated_order - True if customers was inactive over 90 daysOne row per order. Use stg_orders__orders as the source. Materialize as a table.
This task supports both DuckDB and Snowflake. Run echo $DB_TYPE in a shell BEFORE you write any code or spawn any subagents — the live env determines which backend the verifier runs against. Do NOT assume a default from this prose. Both /app/dbt_models_duckdb/ and /app/dbt_models_snowflake/ exist on disk; the verifier only checks the project matching the live $DB_TYPE.
DB_TYPE=duckdb$DUCKDB_PATH (default: /app/database/retail.duckdb)DB_TYPE=snowflakeSNOWFLAKE_ACCOUNTSNOWFLAKE_USERSNOWFLAKE_PASSWORDSNOWFLAKE_DATABASE - The clone database to useSNOWFLAKE_SCHEMASNOWFLAKE_WAREHOUSESNOWFLAKE_ROLE (optional)Note: For Snowflake, the entrypoint automatically creates a clone database and sets SNOWFLAKE_DATABASE. The clone is destroyed when the task completes.
You must configure dbt to connect to the database:
profiles.yml in the dbt project directory with profile name retail_dw_masterDBT_PROFILES_DIR environment variable to the directory containing profiles.ymlConfigure with type: duckdb and the database path from $DUCKDB_PATH.
Configure with type: snowflake using password authentication:
schema: to $SNOWFLAKE_SCHEMA — do NOT leave it blank. A blank or omitted schema makes Snowflake silently default to PUBLIC, so your models get built in the wrong schema and the verifier cannot find them.