diff --git a/projects/marseille/models/marts/proposals_with_impersonation_info.sql b/projects/marseille/models/marts/proposals_with_impersonation_info.sql index c6c9b6d..fb4a942 100644 --- a/projects/marseille/models/marts/proposals_with_impersonation_info.sql +++ b/projects/marseille/models/marts/proposals_with_impersonation_info.sql @@ -1,9 +1,14 @@ -SELECT - proposals.* - --(CASE - --WHEN proposals.created_at BETWEEN impersonations.started_at AND impersonations.ended_at THEN true ELSE false END - --) AS authored_by_impersonation -FROM {{ ref("proposals") }} AS proposals -LEFT JOIN {{ ref("decidim_impersonation_logs") }} AS impersonations ON proposals.first_author_id = impersonations.user_id +WITH proposals_under_impersonation AS ( + SELECT + proposals.id AS proposal_id + FROM {{ ref("proposals") }} AS proposals + LEFT JOIN {{ ref("decidim_impersonation_logs") }} AS impersonations ON proposals.first_author_id = impersonations.user_id WHERE proposals.created_at BETWEEN impersonations.started_at AND impersonations.ended_at - ORDER BY proposals.id \ No newline at end of file + ORDER BY proposals.id +) + +SELECT + *, + (CASE WHEN proposals_under_impersonation.proposal_id IS NOT NULL THEN true ELSE false END) AS authored_under_impersonation +FROM {{ ref("proposals") }} AS proposals +LEFT JOIN proposals_under_impersonation ON proposals.id = proposals_under_impersonation.proposal_id \ No newline at end of file diff --git a/projects/marseille/models/marts/schema.yml b/projects/marseille/models/marts/schema.yml new file mode 100644 index 0000000..42fd1cf --- /dev/null +++ b/projects/marseille/models/marts/schema.yml @@ -0,0 +1,13 @@ +unit_tests: + - name: + description: "" + model: proposals_with_impersonation_info + given: + - input: ref('') + format: dict + rows: + - {} + expect: + format: dict + rows: + - {} \ No newline at end of file