Skip to content

Commit

Permalink
Merge pull request #74 from OpenSourcePolitics/0.29_new_columns
Browse files Browse the repository at this point in the history
feat(demo): anticipate new columns for 0.29 migration
  • Loading branch information
JeanLouisLamezec authored Feb 14, 2025
2 parents 9b6cea4 + fe94241 commit f5f652d
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 104 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
{% set lang = var('DBT_LANG', 'fr') %}

WITH source AS (
SELECT * FROM {{ source('decidim', 'decidim_blogs_posts') }}
),
renamed AS (
SELECT
id,
title::jsonb->>'{{ lang }}' AS title,
regexp_replace(body::jsonb->>'{{ lang }}', E'(<[^>]+>)|(&[a-z]+;)', '', 'gi') AS body,
decidim_component_id,
created_at,
decidim_author_id,
'Decidim::Blogs::Post' AS resource_type
FROM source
)
SELECT * FROM renamed

SELECT
id,
title::jsonb->>'{{ lang }}' AS title,
regexp_replace(body::jsonb->>'{{ lang }}', E'(<[^>]+>)|(&[a-z]+;)', '', 'gi') AS body,
decidim_component_id,
created_at,
decidim_author_id,
{{ get_column_if_exists(source('decidim', 'decidim_blogs_posts'), 'published_at', 'TIMESTAMP') }},
'Decidim::Blogs::Post' AS resource_type
FROM {{ source('decidim', 'decidim_blogs_posts') }}
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,20 @@

{% set lang = var('DBT_LANG', 'fr') %}

WITH source AS (
SELECT * FROM {{ source('decidim', 'decidim_forms_questions') }}
),
renamed AS (
SELECT
id,
decidim_questionnaire_id,
position,
question_type,
mandatory,
body::jsonb->>'{{ lang }}' AS body,
description,
max_choices,
created_at,
updated_at,
max_characters
FROM source
)
SELECT * FROM renamed

SELECT
id,
decidim_questionnaire_id,
position,
question_type,
mandatory,
body::jsonb->>'{{ lang }}' AS body,
description,
max_choices,
created_at,
updated_at,
max_characters,
{{ get_column_if_exists(source('decidim', 'decidim_forms_questions'), 'answer_options_count', 'INTEGER') }},
{{ get_column_if_exists(source('decidim', 'decidim_forms_questions'), 'matrix_rows_count', 'INTEGER') }},
{{ get_column_if_exists(source('decidim', 'decidim_forms_questions'), 'display_conditions_count', 'INTEGER') }},
{{ get_column_if_exists(source('decidim', 'decidim_forms_questions'), 'display_conditions_for_other_questions_count', 'INTEGER') }}
FROM {{ source('decidim', 'decidim_forms_questions') }}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ SELECT
decidim_scope_id,
created_at,
published_at,
{{ get_column_if_exists(source('decidim', 'decidim_proposals_proposals'), 'withdrawn_at', 'TIMESTAMP') }},
{{ get_column_if_exists(source('decidim', 'decidim_proposals_proposals'), 'valuation_assignments_count', 'INTEGER') }},
state,
{{ get_column_if_exists(source('decidim', 'decidim_proposals_proposals'), 'decidim_proposals_proposal_state_id', 'INTEGER') }},
comments_count,
endorsements_count,
address,
{{ get_column_if_exists(source('decidim', 'decidim_proposals_proposals'), 'decidim_proposals_proposal_state_id', 'INTEGER') }}
address
FROM {{ source('decidim', 'decidim_proposals_proposals') }}
36 changes: 15 additions & 21 deletions projects/demo/models/staging/decidim/stg_decidim_attachments.sql
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
WITH source AS (
SELECT * FROM {{ source('decidim', 'decidim_attachments') }}
),
renamed as (
SELECT
id,
title,
description,
file,
content_type,
file_size,
attached_to_id,
created_at,
updated_at,
attached_to_type,
weight,
attachment_collection_id
FROM source
)
SELECT * FROM renamed

SELECT
id,
title,
description,
file,
content_type,
file_size,
attached_to_id,
created_at,
updated_at,
attached_to_type,
weight,
attachment_collection_id,
{{ get_column_if_exists(source('decidim', 'decidim_attachments'), 'link', 'TEXT') }}
FROM {{ source('decidim', 'decidim_attachments') }}
40 changes: 18 additions & 22 deletions projects/demo/models/staging/decidim/stg_decidim_comments.sql
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
{% set lang = var('DBT_LANG', 'fr') %}

WITH source AS (
SELECT * FROM {{ source('decidim', 'decidim_comments_comments') }}
),
renamed as (
SELECT
id,
decidim_commentable_type,
decidim_commentable_id,
decidim_author_id,
created_at,
updated_at,
depth,
alignment,
decidim_user_group_id,
decidim_root_commentable_type,
decidim_root_commentable_id,
decidim_author_type,
body::jsonb->>'{{ lang }}' as body,
comments_count
FROM source
)
SELECT * FROM renamed
SELECT
id,
decidim_commentable_type,
decidim_commentable_id,
decidim_author_id,
created_at,
updated_at,
depth,
alignment,
decidim_user_group_id,
decidim_root_commentable_type,
decidim_root_commentable_id,
decidim_author_type,
body::jsonb->>'{{ lang }}' as body,
comments_count,
{{ get_column_if_exists(source('decidim', 'decidim_comments_comments'), 'up_votes_count', 'INTEGER') }},
{{ get_column_if_exists(source('decidim', 'decidim_comments_comments'), 'down_votes_count', 'INTEGER') }}
FROM {{ source('decidim', 'decidim_comments_comments') }}

41 changes: 18 additions & 23 deletions projects/demo/models/staging/decidim/stg_decidim_meetings.sql
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
{% set lang = var('DBT_LANG', 'fr') %}

WITH source AS (
SELECT * FROM {{ source('decidim', 'decidim_meetings_meetings') }}
),
renamed AS (
SELECT
id,
title::jsonb->>'{{ lang }}' AS title,
regexp_replace(description::jsonb->>'{{ lang }}', E'(<[^>]+>)|(&[a-z]+;)', '', 'gi') AS description,
coalesce(nullif(address,''), 'Pas d''adresse') as address,
coalesce(attendees_count, 0) as attendees_count,
created_at,
decidim_scope_id,
decidim_component_id,
start_time,
end_time,
registration_url,
type_of_meeting,
private_meeting,
decidim_author_id,
'Decidim::Meetings::Meeting' as resource_type
FROM source
)
SELECT * FROM renamed
SELECT
id,
title::jsonb->>'{{ lang }}' AS title,
regexp_replace(description::jsonb->>'{{ lang }}', E'(<[^>]+>)|(&[a-z]+;)', '', 'gi') AS description,
coalesce(nullif(address,''), 'Pas d''adresse') as address,
coalesce(attendees_count, 0) as attendees_count,
created_at,
{{ get_column_if_exists(source('decidim', 'decidim_proposals_proposals'), 'withdrawn_at', 'TIMESTAMP') }},
decidim_scope_id,
decidim_component_id,
start_time,
end_time,
registration_url,
type_of_meeting,
private_meeting,
decidim_author_id,
'Decidim::Meetings::Meeting' as resource_type
FROM {{ source('decidim', 'decidim_meetings_meetings') }}

0 comments on commit f5f652d

Please sign in to comment.