Skip to content

Commit

Permalink
feat(pipeline) : Add mes-aides, mediation-numerique to Brevo contacts
Browse files Browse the repository at this point in the history
They will also be part of the notification campaign about displaying
their e-mail address in the API.
  • Loading branch information
vperron committed Aug 15, 2024
1 parent 73536f7 commit ec6e658
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 4 deletions.
6 changes: 3 additions & 3 deletions pipeline/dags/notify_rgpd_contacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ def _sync_new_contacts_to_brevo():
from dag_utils import constants, pg
from dag_utils.sources import brevo

dora_contacts = pg.hook().get_records(
known_contacts = pg.hook().get_records(
sql=(
"SELECT courriel, ARRAY_AGG(contact_uid) as contact_uids "
"FROM public_intermediate.int_dora__contacts "
"FROM public_intermediate.int__union__contacts "
"GROUP BY courriel"
)
)
Expand All @@ -44,7 +44,7 @@ def _sync_new_contacts_to_brevo():
# If the email is not new but linked to a new contact UID, update the associated
# list accordingly.
new_contacts_map = defaultdict(list)
for email, contact_uids in dora_contacts:
for email, contact_uids in known_contacts:
for contact_uid in contact_uids:
if contact_uid not in brevo_contacts_uid_set:
if email in brevo_contacts_map:
Expand Down
13 changes: 13 additions & 0 deletions pipeline/dbt/models/intermediate/_models.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,19 @@ models:
data_tests:
- check_adresse: *union-common-check-args

- name: int__union__contacts
description: |
Gathers contacts from all sources
columns:
- name: contact_uid
data_tests:
- unique
- not_null
- name: courriel
data_tests:
- not_null
- dbt_utils.not_empty_string

- name: int__union_services
description: |
Gathers services from all sources
Expand Down
14 changes: 14 additions & 0 deletions pipeline/dbt/models/intermediate/int__union__contacts.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
WITH final AS (
{{
dbt_utils.union_relations(
relations=[
ref('int_dora__contacts'),
ref('int_mediation_numerique__contacts'),
ref('int_mes_aides__contacts'),
],
source_column_name=None
)
}}
)

SELECT * FROM final
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ models:
- not_null
- dbt_utils.not_empty_string

- name: int_mediation_numerique__contacts
columns:
- name: contact_uid
data_tests:
- unique
- not_null
- name: courriel
data_tests:
- not_null
- dbt_utils.not_empty_string


- name: int_mediation_numerique__services
data_tests:
- dbt_utils.unique_combination_of_columns:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
WITH final AS (
SELECT
courriel AS "courriel",
'mediation-numerique:structures:' || id AS contact_uid
FROM {{ ref('stg_mediation_numerique__structures') }}
WHERE courriel IS NOT NULL
)

SELECT * FROM final
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@ models:
- not_null
- dbt_utils.not_empty_string

- name: int_mes_aides__contacts
columns:
- name: contact_uid
data_tests:
- unique
- not_null
- name: courriel
data_tests:
- not_null
- dbt_utils.not_empty_string

- name: int_mes_aides__structures
data_tests:
- check_structure:
Expand Down Expand Up @@ -53,4 +64,4 @@ models:
- not_null
- relationships:
to: ref('int_mes_aides__adresses')
field: id
field: id
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
WITH structure_contacts AS (
SELECT
email AS "courriel",
'mes-aides:garages:' || id AS contact_uid
FROM {{ ref('stg_mes_aides__garages') }}
WHERE email IS NOT NULL
),

service_contacts AS (
SELECT
email AS "courriel",
'mes-aides:aides:' || id AS contact_uid
FROM {{ ref('stg_mes_aides__aides') }}
WHERE email IS NOT NULL
),

final AS (
SELECT * FROM structure_contacts
UNION ALL
SELECT * FROM service_contacts
)

SELECT * FROM final

0 comments on commit ec6e658

Please sign in to comment.