From 20425495f9b8303efd2ab0081fb968d0af127dd9 Mon Sep 17 00:00:00 2001 From: Joaquin Ossa Date: Fri, 27 Sep 2024 10:44:48 +0200 Subject: [PATCH 1/2] staging Hubspot contacts --- models/staging/hubspot/_hubspot_sources.yml | 8 +++ models/staging/hubspot/schema.yml | 56 +++++++++++++++++++ .../staging/hubspot/stg_hubspot__contacts.sql | 18 ++++++ 3 files changed, 82 insertions(+) create mode 100644 models/staging/hubspot/_hubspot_sources.yml create mode 100644 models/staging/hubspot/schema.yml create mode 100644 models/staging/hubspot/stg_hubspot__contacts.sql diff --git a/models/staging/hubspot/_hubspot_sources.yml b/models/staging/hubspot/_hubspot_sources.yml new file mode 100644 index 0000000..8d52014 --- /dev/null +++ b/models/staging/hubspot/_hubspot_sources.yml @@ -0,0 +1,8 @@ +version: 2 + +sources: + - name: hubspot + schema: sync_hubspot + tables: + - name: contacts + identifier: contacts diff --git a/models/staging/hubspot/schema.yml b/models/staging/hubspot/schema.yml new file mode 100644 index 0000000..e88c9eb --- /dev/null +++ b/models/staging/hubspot/schema.yml @@ -0,0 +1,56 @@ +version: 2 + +models: + - name: stg_hubspot__contacts + description: "Table with contact information of user in Hubspot." + columns: + - name: id_contact + data_type: character varying + description: "Unique id for each contact information." + tests: + - unique + - not_null + + - name: archived + data_type: boolean + description: "" + + - name: companies + data_type: jsonb + description: "" + + - name: properties + data_type: jsonb + description: "Json with all contact information for this record." + tests: + - not_null + + - name: created_at_utc + data_type: timestamp with time zone + description: "Timestamp of when this record was created." + tests: + - not_null + + - name: created_date_utc + data_type: timestamp without time zone + description: "Date of when this record was created." + tests: + - not_null + + - name: updated_at_utc + data_type: timestamp with time zone + description: "Timestamp of when this record was last updated." + tests: + - not_null + + - name: updated_date_utc + data_type: timestamp without time zone + description: "Date of when this record was last updated." + tests: + - not_null + + - name: dwh_extracted_at_utc + data_type: timestamp with time zone + description: "Timestamp of when data was extracted to DWH." + tests: + - not_null diff --git a/models/staging/hubspot/stg_hubspot__contacts.sql b/models/staging/hubspot/stg_hubspot__contacts.sql new file mode 100644 index 0000000..70c4d7f --- /dev/null +++ b/models/staging/hubspot/stg_hubspot__contacts.sql @@ -0,0 +1,18 @@ +with + raw_contacts as (select * from {{ source("hubspot", "contacts") }}), + stg_core__contacts as ( + select + {{ adapter.quote("id") }} as id_contact, + {{ adapter.quote("archived") }} as archived, + {{ adapter.quote("companies") }} as companies, + {{ adapter.quote("properties") }} as properties, + {{ adapter.quote("createdAt") }} as created_at_utc, + cast({{ adapter.quote("createdAt") }} as date) as created_date_utc, + {{ adapter.quote("updatedAt") }} as updated_at_utc, + cast({{ adapter.quote("updatedAt") }} as date) as updated_date_utc, + {{ adapter.quote("_airbyte_extracted_at") }} as dwh_extracted_at_utc + + from raw_contacts + ) +select * +from stg_core__contacts From 306035d46dc37cf1936f13ce5f030e961b331952 Mon Sep 17 00:00:00 2001 From: Joaquin Ossa Date: Fri, 27 Sep 2024 12:24:27 +0200 Subject: [PATCH 2/2] Hubspot deals --- models/staging/hubspot/_hubspot_sources.yml | 2 + models/staging/hubspot/schema.yml | 61 +++++++++++++++++++ models/staging/hubspot/stg_hubspot__deals.sql | 20 ++++++ 3 files changed, 83 insertions(+) create mode 100644 models/staging/hubspot/stg_hubspot__deals.sql diff --git a/models/staging/hubspot/_hubspot_sources.yml b/models/staging/hubspot/_hubspot_sources.yml index 8d52014..b0b6261 100644 --- a/models/staging/hubspot/_hubspot_sources.yml +++ b/models/staging/hubspot/_hubspot_sources.yml @@ -6,3 +6,5 @@ sources: tables: - name: contacts identifier: contacts + - name: deals + identifier: deals diff --git a/models/staging/hubspot/schema.yml b/models/staging/hubspot/schema.yml index e88c9eb..4cf8542 100644 --- a/models/staging/hubspot/schema.yml +++ b/models/staging/hubspot/schema.yml @@ -54,3 +54,64 @@ models: description: "Timestamp of when data was extracted to DWH." tests: - not_null + - name: stg_hubspot__deals + description: "Table with deal information stored in Hubspot." + columns: + - name: id_deal + data_type: character varying + description: "Unique id for each contact information." + tests: + - unique + - not_null + + - name: archived + data_type: boolean + description: "" + + - name: contacts + data_type: jsonb + description: "List of contact ids for the deal" + + - name: companies + data_type: jsonb + description: "" + + - name: line_items + data_type: jsonb + description: "" + + - name: properties + data_type: jsonb + description: "Json with all information for this deal." + tests: + - not_null + + - name: created_at_utc + data_type: timestamp with time zone + description: "Timestamp of when this record was created." + tests: + - not_null + + - name: created_date_utc + data_type: timestamp without time zone + description: "Date of when this record was created." + tests: + - not_null + + - name: updated_at_utc + data_type: timestamp with time zone + description: "Timestamp of when this record was last updated." + tests: + - not_null + + - name: updated_date_utc + data_type: timestamp without time zone + description: "Date of when this record was last updated." + tests: + - not_null + + - name: dwh_extracted_at_utc + data_type: timestamp with time zone + description: "Timestamp of when data was extracted to DWH." + tests: + - not_null diff --git a/models/staging/hubspot/stg_hubspot__deals.sql b/models/staging/hubspot/stg_hubspot__deals.sql new file mode 100644 index 0000000..8749383 --- /dev/null +++ b/models/staging/hubspot/stg_hubspot__deals.sql @@ -0,0 +1,20 @@ +with + raw_deals as (select * from {{ source("hubspot", "deals") }}), + stg_core__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") }} as properties, + {{ adapter.quote("createdAt") }} as created_at_utc, + cast({{ adapter.quote("createdAt") }} as date) as created_date_utc, + {{ adapter.quote("updatedAt") }} as updated_at_utc, + cast({{ adapter.quote("updatedAt") }} as date) as updated_date_utc, + {{ adapter.quote("_airbyte_extracted_at") }} as dwh_extracted_at_utc + + from raw_deals + ) +select * +from stg_core__deals