Skip to content

Commit

Permalink
Merge pull request #23 from OpenSourcePolitics/add_private_field_lyon
Browse files Browse the repository at this point in the history
adding awesome proposal fields models to Lyon
  • Loading branch information
JeanLouisLamezec authored Oct 18, 2024
2 parents c138450 + 2d95bbd commit 445d488
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
WITH parsed_data AS (
SELECT
decidim_awesome_proposal_extra_fields.id,
decidim_awesome_proposal_extra_fields.proposal_id,
xpath('//text()', unnest(xpath('//dt', xml_data)))::text AS private_field_description,
unnest(xpath('//dd/div/text()', unnest(xpath('//dd', xml_data))))::text AS private_field_content
FROM
{{ ref ("stg_decidim_awesome_proposal_extra_fields")}} AS decidim_awesome_proposal_extra_fields,
LATERAL xmlparse(document private_body) AS xml_data
)
SELECT
parsed_data.id,
parsed_data.proposal_id,
replace(replace(private_field_description, '{"', ''), '"}', '') AS private_field_description,
parsed_data.private_field_content
FROM
parsed_data
WHERE
private_field_content IS NOT NULL
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
SELECT
decidim_awesome_proposal_extra_fields.id,
decidim_awesome_proposal_extra_fields.proposal_id,
decidim_awesome_proposal_extra_fields.private_field_description,
decidim_awesome_proposal_extra_fields.private_field_content,
decidim_proposals_proposals.decidim_component_id,
components.ps_title
FROM
{{ ref ("int_decidim_awesome_proposal_extra_fields")}} AS decidim_awesome_proposal_extra_fields
JOIN {{ ref ("stg_decidim_proposals")}} AS decidim_proposals_proposals ON decidim_awesome_proposal_extra_fields.proposal_id = decidim_proposals_proposals.id
JOIN {{ ref ("components")}} AS components ON decidim_proposals_proposals.decidim_component_id = components.id
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
WITH source AS (
SELECT * FROM {{ source('decidim', 'decidim_awesome_proposal_extra_fields') }}
)


SELECT
id,
decidim_proposal_id AS proposal_id,
updated_at,
created_at,
replace(decrypted_private_body, ' ', '') AS private_body
FROM source
8 changes: 8 additions & 0 deletions projects/lyon/models/staging/decidim/schema.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: 2

sources:
- name: decidim
database: "{{ env_var('DBNAME') }}"
schema: public
tables:
- name: decidim_awesome_proposal_extra_fields

0 comments on commit 445d488

Please sign in to comment.