diff --git a/projects/demo/models/staging/decidim/elections/schema.yml b/projects/demo/models/staging/decidim/elections/schema.yml new file mode 100644 index 00000000..f591bd74 --- /dev/null +++ b/projects/demo/models/staging/decidim/elections/schema.yml @@ -0,0 +1,12 @@ +version: 2 + +sources: + - name: decidim + database: "{{ env_var('DBNAME') }}" + schema: public + tables: + - name: decidim_elections_elections + - name: decidim_elections_questions + - name: decidim_elections_response_options + - name: decidim_elections_voters + - name: decidim_elections_votes diff --git a/projects/demo/models/staging/decidim/elections/stg_decidim_elections.sql b/projects/demo/models/staging/decidim/elections/stg_decidim_elections.sql new file mode 100644 index 00000000..48c14597 --- /dev/null +++ b/projects/demo/models/staging/decidim/elections/stg_decidim_elections.sql @@ -0,0 +1,45 @@ +{% set relation = adapter.get_relation( + database=target.database, + schema='public', + identifier='decidim_elections_elections' +) %} + +{% if relation is not none %} + SELECT + id, + decidim_component_id, + title, + description, + announcement, + start_at, + end_at, + results_availability, + published_at, + deleted_at, + created_at, + updated_at, + census_manifest, + census_settings, + published_results_at, + votes_count, + FROM {{ source('decidim', 'decidim_elections_elections') }} +{% else %} + SELECT + CAST(NULL AS BIGINT) AS id, + CAST(NULL AS BIGINT) AS decidim_component_id, + CAST(NULL AS JSONB) AS title, + CAST(NULL AS JSONB) AS description, + CAST(NULL AS JSONB) AS announcement, + CAST(NULL AS TIMESTAMP) AS start_at, + CAST(NULL AS TIMESTAMP) AS end_at, + CAST(NULL AS TEXT) AS results_availability, + CAST(NULL AS TIMESTAMP) AS published_at, + CAST(NULL AS TIMESTAMP) AS deleted_at, + CAST(NULL AS TIMESTAMP) AS created_at, + CAST(NULL AS TIMESTAMP) AS updated_at, + CAST(NULL AS TEXT) AS census_manifest, + CAST(NULL AS JSONB) AS census_settings, + CAST(NULL AS TIMESTAMP) AS published_results_at, + CAST(NULL AS BIGINT) AS votes_count + LIMIT 0 +{% endif %} \ No newline at end of file diff --git a/projects/demo/models/staging/decidim/elections/stg_decidim_elections_questions.sql b/projects/demo/models/staging/decidim/elections/stg_decidim_elections_questions.sql new file mode 100644 index 00000000..f8384033 --- /dev/null +++ b/projects/demo/models/staging/decidim/elections/stg_decidim_elections_questions.sql @@ -0,0 +1,40 @@ +{% set relation = adapter.get_relation( + database=target.database, + schema='public', + identifier='decidim_elections_questions' +) %} + +{% if relation is not none %} + SELECT + id, + election_id, + body, + description, + mandatory, + question_type, + multiple_option, + position, + created_at, + updated_at, + published_results_at, + voting_enabled_at, + votes_count, + response_options_count + FROM {{ source('decidim', 'decidim_elections_questions') }} +{% else %} + SELECT + CAST(NULL AS BIGINT) AS id, + CAST(NULL AS BIGINT) AS election_id, + CAST(NULL AS JSONB) AS body, + CAST(NULL AS JSONB) AS description, + CAST(NULL AS BOOLEAN) AS mandatory, + CAST(NULL AS TEXT) AS question_type, + CAST(NULL AS BIGINT) AS position, + CAST(NULL AS TIMESTAMP) AS created_at, + CAST(NULL AS TIMESTAMP) AS updated_at, + CAST(NULL AS TIMESTAMP) AS published_results_at, + CAST(NULL AS TIMESTAMP) AS voting_enabled_at, + CAST(NULL AS BIGINT) AS votes_count, + CAST(NULL AS BIGINT) AS response_options_count + LIMIT 0 +{% endif %} \ No newline at end of file diff --git a/projects/demo/models/staging/decidim/elections/stg_decidim_elections_response_options.sql b/projects/demo/models/staging/decidim/elections/stg_decidim_elections_response_options.sql new file mode 100644 index 00000000..d8364774 --- /dev/null +++ b/projects/demo/models/staging/decidim/elections/stg_decidim_elections_response_options.sql @@ -0,0 +1,25 @@ +{% set relation = adapter.get_relation( + database=target.database, + schema='public', + identifier='decidim_elections_response_options' +) %} + +{% if relation is not none %} + SELECT + id, + question_id, + body, + created_at, + updated_at, + votes_count + FROM {{ source('decidim', 'decidim_elections_response_options') }} +{% else %} + SELECT + CAST(NULL AS BIGINT) AS id, + CAST(NULL AS BIGINT) AS question_id, + CAST(NULL AS JSONB) AS body, + CAST(NULL AS TIMESTAMP) AS created_at, + CAST(NULL AS TIMESTAMP) AS updated_at, + CAST(NULL AS BIGINT) AS votes_count + LIMIT 0 +{% endif %} \ No newline at end of file diff --git a/projects/demo/models/staging/decidim/elections/stg_decidim_elections_voters.sql b/projects/demo/models/staging/decidim/elections/stg_decidim_elections_voters.sql new file mode 100644 index 00000000..96b53964 --- /dev/null +++ b/projects/demo/models/staging/decidim/elections/stg_decidim_elections_voters.sql @@ -0,0 +1,23 @@ +{% set relation = adapter.get_relation( + database=target.database, + schema='public', + identifier='decidim_elections_voters' +) %} + +{% if relation is not none %} + SELECT + id, + election_id, + data, + created_at, + updated_at + FROM {{ source('decidim', 'decidim_elections_voters') }} +{% else %} + SELECT + CAST(NULL AS BIGINT) AS id, + CAST(NULL AS BIGINT) AS election_id, + CAST(NULL AS JSONB) AS data, + CAST(NULL AS TIMESTAMP) AS created_at, + CAST(NULL AS TIMESTAMP) AS updated_at + LIMIT 0 +{% endif %} \ No newline at end of file diff --git a/projects/demo/models/staging/decidim/elections/stg_decidim_elections_votes.sql b/projects/demo/models/staging/decidim/elections/stg_decidim_elections_votes.sql new file mode 100644 index 00000000..cd32dcad --- /dev/null +++ b/projects/demo/models/staging/decidim/elections/stg_decidim_elections_votes.sql @@ -0,0 +1,25 @@ +{% set relation = adapter.get_relation( + database=target.database, + schema='public', + identifier='decidim_elections_votes' +) %} + +{% if relation is not none %} + SELECT + id, + question_id, + response_option_id, + voter_uid, + created_at, + updated_at + FROM {{ source('decidim', 'decidim_elections_votes') }} +{% else %} + SELECT + CAST(NULL AS BIGINT) AS id, + CAST(NULL AS BIGINT) AS question_id, + CAST(NULL AS BIGINT) AS response_option_id, + CAST(NULL AS TEXT) AS voter_uid, + CAST(NULL AS TIMESTAMP) AS created_at, + CAST(NULL AS TIMESTAMP) AS updated_at + LIMIT 0 +{% endif %} \ No newline at end of file