Skip to content

Commit

Permalink
fix(pipeline): force relation adresses/geocodages
Browse files Browse the repository at this point in the history
Adresses can be deleted by the provider, or by us.
In both cases, deleting the corresponding geocodages is required
to ensure that the relationship between adresses and geocodages stands.

Either that or the relationship test must be downgrade to a warning.
  • Loading branch information
vmttn committed Sep 19, 2024
1 parent 10f240f commit 1f3c83e
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions pipeline/dbt/models/intermediate/int__geocodages.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@
config(
materialized="incremental",
unique_key="adresse_id",
post_hook=[
"
-- adresses can be deleted by the provider, or by us.
-- in both cases, deleting the corresponding geocodages is required
-- to ensure that the relationship between adresses and geocodages stands
WITH deleted_adresses AS (
SELECT geocodages.adresse_id
FROM {{ this }} AS geocodages
LEFT JOIN {{ ref('int__union_adresses') }} AS adresses ON geocodages.adresse_id = adresses._di_surrogate_id
WHERE adresses._di_surrogate_id IS NULL
)
DELETE FROM {{ this }} WHERE {{ this }}.adresse_id IN (SELECT adresse_id FROM deleted_adresses)"
]
)
}}

Expand Down

0 comments on commit 1f3c83e

Please sign in to comment.