From 7e9248aa6eac98986eed9ec03707dfbe6872c964 Mon Sep 17 00:00:00 2001 From: Pablo Martin Date: Fri, 11 Oct 2024 17:08:59 +0200 Subject: [PATCH 1/3] added properties --- models/staging/hubspot/stg_hubspot__deals.sql | 60 ++++++++++++++++++- 1 file changed, 58 insertions(+), 2 deletions(-) diff --git a/models/staging/hubspot/stg_hubspot__deals.sql b/models/staging/hubspot/stg_hubspot__deals.sql index 8749383..acfa79d 100644 --- a/models/staging/hubspot/stg_hubspot__deals.sql +++ b/models/staging/hubspot/stg_hubspot__deals.sql @@ -1,12 +1,68 @@ with raw_deals as (select * from {{ source("hubspot", "deals") }}), - stg_core__deals as ( + stg_hubspot__deals as ( select {{ adapter.quote("id") }} as id_deal, {{ adapter.quote("archived") }} as archived, {{ adapter.quote("contacts") }} as contacts, {{ adapter.quote("companies") }} as companies, {{ adapter.quote("line_items") }} as line_items, + {{ adapter.quote("properties") }} + ->> 'hubspot_owner_id' as id_hubspot_account_owner, + {{ adapter.quote("properties") }}->> 'dedicated_am' as account_manager, + {{ adapter.quote("properties") }} + ->> 'contract_signed_date' as contract_signed_date_utc, + {{ adapter.quote("properties") }}->> 'live_date' as live_date_utc, + {{ adapter.quote("properties") }} + ->> 'cancellation_date' as cancellation_date_utc, + {{ adapter.quote("properties") }}->> 'dealname' as deal_name, + {{ adapter.quote("properties") }}->> 'sales_stage' as sales_stage, + {{ adapter.quote("properties") }}->> 'dealstage' as deal_stage, + {{ adapter.quote("properties") }}->> 'deal_source' as deal_source, + {{ adapter.quote("properties") }} ->> 'lead_source' as lead_source, + round( + ({{ adapter.quote("properties") }} ->> 'amount_of_properties')::numeric, + 0 + )::integer -- Yes, somehow we managed to input decimals here sometimes + as amount_of_properties, + {{ adapter.quote("properties") }}->> 'demo_scheduled' as is_demo_scheduled, + {{ adapter.quote("properties") }} + ->> 'sales_demo_scheduled' as demo_scheduled_date_utc, + {{ adapter.quote("properties") }}->> 'demo_completed' as is_demo_completed, + {{ adapter.quote("properties") }} + ->> 'meeting_status__hubspot_' as demo_details, + {{ adapter.quote("properties") }}->> 'date_meeting' as onboarding_date_utc, + {{ adapter.quote("properties") }}->> 'onboarding_stage' as onboarding_stage, + {{ adapter.quote("properties") }}->> 'onboarding_owner' as onboarding_owner, + {{ adapter.quote("properties") }} + ->> 'onboarding_owner__cloned_' as onboarding_owner__cloned_, + {{ adapter.quote("properties") }} + ->> 'onboarding_call_completed' as is_onboarding_call_completed, + {{ adapter.quote("properties") }} + ->> 'meeting_scheduled' as is_onboarding_scheduled, + {{ adapter.quote("properties") }} + ->> 'cancellation_category' as cancellation_category, + {{ adapter.quote("properties") }} + ->> 'cancellation_details' as cancellation_details, + {{ adapter.quote("properties") }} + ->> 'last_nps_survey_date' as last_nps_survey_date_utc, + ({{ adapter.quote("properties") }} ->> 'last_nps_survey_rating')::integer + as last_nps_survey_rating, + {{ adapter.quote("properties") }} + ->> 'last_nps_survey_comment' as last_nps_survey_comment, + {{ adapter.quote("properties") }} + ->> 'customer_nps_sentiment' as customer_nps_sentiment, + {{ adapter.quote("properties") }} + ->> 'notes_last_contacted' as last_contacted_at_utc, + cast( + {{ adapter.quote("properties") }} ->> 'notes_last_contacted' as date + ) as last_contacted_date_utc, + ({{ adapter.quote("properties") }} ->> 'num_contacted_notes')::integer + as amount_times_contacted, + {{ adapter.quote("properties") }} + ->> 'free_trial_start_date' as free_trial_start_date_utc, + {{ adapter.quote("properties") }} + ->> 'free_trial_end_date' as free_trial_end_date_utc, {{ adapter.quote("properties") }} as properties, {{ adapter.quote("createdAt") }} as created_at_utc, cast({{ adapter.quote("createdAt") }} as date) as created_date_utc, @@ -17,4 +73,4 @@ with from raw_deals ) select * -from stg_core__deals +from stg_hubspot__deals From e5b18f2ce7c44e65c8b9ba583e8d37aa595b9747 Mon Sep 17 00:00:00 2001 From: Pablo Martin Date: Tue, 15 Oct 2024 14:37:09 +0200 Subject: [PATCH 2/3] rename col --- models/staging/hubspot/stg_hubspot__deals.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/models/staging/hubspot/stg_hubspot__deals.sql b/models/staging/hubspot/stg_hubspot__deals.sql index acfa79d..f3012fc 100644 --- a/models/staging/hubspot/stg_hubspot__deals.sql +++ b/models/staging/hubspot/stg_hubspot__deals.sql @@ -17,13 +17,13 @@ with ->> 'cancellation_date' as cancellation_date_utc, {{ adapter.quote("properties") }}->> 'dealname' as deal_name, {{ adapter.quote("properties") }}->> 'sales_stage' as sales_stage, - {{ adapter.quote("properties") }}->> 'dealstage' as deal_stage, + {{ adapter.quote("properties") }}->> 'dealstage' as id_deal_stage, {{ adapter.quote("properties") }}->> 'deal_source' as deal_source, {{ adapter.quote("properties") }} ->> 'lead_source' as lead_source, round( ({{ adapter.quote("properties") }} ->> 'amount_of_properties')::numeric, 0 - )::integer -- Yes, somehow we managed to input decimals here sometimes + )::integer -- Yes, somehow we managed to input decimals here sometimes, lol as amount_of_properties, {{ adapter.quote("properties") }}->> 'demo_scheduled' as is_demo_scheduled, {{ adapter.quote("properties") }} From d9a90d7d24e1506a4aceb7ab5c477a793a6c73a8 Mon Sep 17 00:00:00 2001 From: Pablo Martin Date: Tue, 15 Oct 2024 15:41:20 +0200 Subject: [PATCH 3/3] partial schema. Not doing more because deals is a monster --- models/staging/hubspot/schema.yml | 196 ++++++++++++++++++++++++++++++ 1 file changed, 196 insertions(+) diff --git a/models/staging/hubspot/schema.yml b/models/staging/hubspot/schema.yml index 30fbe46..d8f110b 100644 --- a/models/staging/hubspot/schema.yml +++ b/models/staging/hubspot/schema.yml @@ -259,3 +259,199 @@ models: - name: dwh_extracted_at_utc data_type: timestamp description: Timestamp of when the record was read from source. + + - name: stg_hubspot__deals + description: | + Our deals in Hubspot. A deal is a commercial relationship with a client + company. It's possible for a single company to have multiple deals, but + it's frequent for them to only have one. + + Deals are one of the spines of Superhog's data. You will find references + to Deal Ids in both our in-house systems and Xero. + columns: + - name: id_deal + data_type: character varying + description: Unique ID for this deal. + tests: + - unique + - not_null + + - name: archived + data_type: boolean + description: Whether the deal is archived. + + - name: contacts + data_type: jsonb + description: An array of contact IDs. + + - name: companies + data_type: jsonb + description: An array of company IDs. + + - name: line_items + data_type: jsonb + description: "" + + - name: id_hubspot_account_owner + data_type: text + description: | + The ID of the owner of the Deal. This is typically the Superhog + employee who closed the deal, so most probably one of our sales + colleagues. + + You can join this with the Owners table. + + - name: account_manager + data_type: text + description: | + The name of the account manager that is currently taking care of this + deal. + + - name: contract_signed_date_utc + data_type: text + description: Date in which the contract was signed + + - name: live_date_utc + data_type: text + description: Date in which the account went live + + - name: cancellation_date_utc + data_type: text + description: Date in which an account that was being used was cancelled + + - name: deal_name + data_type: text + description: "" + + - name: sales_stage + data_type: text + description: "" + + - name: id_deal_stage + data_type: text + description: | + ID of the stage the deal is in. Can be denormalized with our + deal_pipeline_stages table. + + - name: deal_source + data_type: text + description: | + General indicator of the source of this deal. + + - name: lead_source + data_type: text + description: | + Whether the deal was inbound sourced (they came to us) or outbound + sourced (we reached out proactively to the customer). + + - name: amount_of_properties + data_type: integer + description: amount of properties the owner told us they manage + + - name: is_demo_scheduled + data_type: text + description: "" + + - name: demo_scheduled_date_utc + data_type: text + description: date at which the demo is scheduled for + + - name: is_demo_completed + data_type: text + description: "" + + - name: demo_details + data_type: text + description: "" + + - name: onboarding_date_utc + data_type: text + description: "" + + - name: onboarding_stage + data_type: text + description: "" + + - name: onboarding_owner + data_type: text + description: "" + + - name: onboarding_owner__cloned_ + data_type: text + description: "" + + - name: is_onboarding_call_completed + data_type: text + description: boolean for completed onboarding + + - name: is_onboarding_scheduled + data_type: text + description: "" + + - name: cancellation_category + data_type: text + description: categorization as to why they cancelled the account + + - name: cancellation_details + data_type: text + description: "" + + - name: last_nps_survey_date_utc + data_type: text + description: "" + + - name: last_nps_survey_rating + data_type: integer + description: "" + + - name: last_nps_survey_comment + data_type: text + description: "" + + - name: customer_nps_sentiment + data_type: text + description: "" + + - name: last_contacted_at_utc + data_type: text + description: "" + + - name: last_contacted_date_utc + data_type: date + description: "" + + - name: amount_times_contacted + data_type: integer + description: "" + + - name: free_trial_start_date_utc + data_type: text + description: "" + + - name: free_trial_end_date_utc + data_type: text + description: "" + + - name: properties + data_type: jsonb + description: "" + + - name: created_at_utc + data_type: timestamp with time zone + description: "" + + - name: created_date_utc + data_type: date + description: "" + + - name: updated_at_utc + data_type: timestamp with time zone + description: "" + + - name: updated_date_utc + data_type: date + description: "" + + - name: dwh_extracted_at_utc + data_type: timestamp with time zone + description: ""