Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions .github/workflows/rc031_models_run_preproduction.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: rc031_models_run_preproduction

on:
workflow_dispatch:

env:
DBNAME: ${{ secrets.RC031_DBNAME_PROD }}
HOST_PREPROD: ${{ secrets.HOST_PREPROD }}
PASSWORD_PREPROD: ${{ secrets.PASSWORD_PREPROD }}
PORT_PREPROD: ${{ secrets.PORT_PREPROD }}
TARGET_SCHEMA: ${{ secrets.SCHEMA_PROD }}
USER_PREPROD: ${{ secrets.USER_PREPROD }}
PARTICIPATION_HOST_NAME: ${{ secrets.RC031_PARTICIPATION_HOST_NAME }}
WORKING_DIRECTORY: ./projects/rc031


jobs:
rc031_models_run_preproduction:
name: rc031_models_run_preproduction
runs-on: ubuntu-latest

steps:
- name: Check out
uses: actions/checkout@master

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.12.x"
cache: 'pip'

- name: Install dependencies
run: |
pip install -r requirements.txt

- name: Run dbt deps
working-directory: ${{ env.WORKING_DIRECTORY }}
run: dbt deps --target preprod

- name: Run dbt models
working-directory: ${{ env.WORKING_DIRECTORY }}
run: dbt run --target preprod

- name: Test dbt models
working-directory: ${{ env.WORKING_DIRECTORY }}
run: dbt test --target preprod

48 changes: 48 additions & 0 deletions .github/workflows/rc031_models_run_production.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: rc031_models_run_production

on:
workflow_dispatch:

env:
DBNAME: ${{ secrets.RC031_DBNAME_PROD }}
HOST: ${{ secrets.HOST }}
PASSWORD: ${{ secrets.PASSWORD }}
PORT: ${{ secrets.PORT }}
TARGET_SCHEMA: ${{ secrets.SCHEMA_PROD }}
USER: ${{ secrets.USER }}
PARTICIPATION_HOST_NAME: ${{ secrets.RC031_PARTICIPATION_HOST_NAME }}
WORKING_DIRECTORY: ./projects/rc031


jobs:
rc031_models_run:
name: rc031_models_run_production
runs-on: ubuntu-latest

steps:
- name: Check out
uses: actions/checkout@master

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.12.x"
cache: 'pip'

- name: Install dependencies
run: |
pip install -r requirements.txt

- name: Run dbt deps
working-directory: ${{ env.WORKING_DIRECTORY }}
run: dbt deps --target prod

- name: Run dbt models
working-directory: ${{ env.WORKING_DIRECTORY }}
run: dbt run --target prod

- name: Test dbt models
working-directory: ${{ env.WORKING_DIRECTORY }}
run: dbt test --target prod


9 changes: 5 additions & 4 deletions projects/demo/.env.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
DBNAME=
HOST=
PASSWORD=
PORT=
HOST_PREPROD=
PORT_PREPROD=
USER_PREPROD=
PASSWORD_PREPROD=
TARGET_SCHEMA=
USER=
PARTICIPATION_HOST_NAME=
4 changes: 2 additions & 2 deletions projects/demo/macros/coalesce_legacy_and_new_columns.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% macro coalesce_legacy_and_new_columns(relation, legacy_column_name, new_column_name) %}
{% macro coalesce_legacy_and_new_columns(relation, legacy_column_name, new_column_name, cast_type="TEXT") %}
{% set columns = adapter.get_columns_in_relation(relation) %}
{% set column_names = columns | map(attribute="name") %}

Expand All @@ -7,7 +7,7 @@
{% elif new_column_name in column_names %}
{{ new_column_name }} AS {{ legacy_column_name }}
{% else %}
{{ get_column_if_exists(relation, legacy_column_name, cast_type="TEXT", default_value="NULL", include_alias=True) }}
{{ get_column_if_exists(relation, legacy_column_name, cast_type, default_value="NULL", include_alias=True) }}
{% endif %}

{% endmacro %}
3 changes: 3 additions & 0 deletions projects/demo/models/staging/decidim/forms/schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ sources:
database: "{{ env_var('DBNAME') }}"
schema: public
tables:
- name: decidim_forms_response_options
- name: decidim_forms_response_choices
- name: decidim_forms_responses
- name: decidim_forms_answer_options
- name: decidim_forms_answer_choices
- name: decidim_forms_answers
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{% set relation = adapter.get_relation(
database=target.database,
schema='public',
identifier='decidim_form_response_choices'
identifier='decidim_forms_response_choices'
) %}

{% if relation is not none %}
SELECT
id,
decidim_response_id AS decidim_answer_id,
decidim_response_option_id AS decidim_answer_id,
decidim_response_option_id AS decidim_answer_option_id,
position,
REPLACE(SUBSTR(body, 2, length(body) - 2)::text, '\"', '"') AS body,
custom_body,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{% set relation = adapter.get_relation(
database=target.database,
schema='public',
identifier='decidim_form_response_options'
identifier='decidim_forms_response_options'
) %}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% set relation = adapter.get_relation(
database=target.database,
schema='public',
identifier='decidim_form_responses'
identifier='decidim_forms_responses'
) %}

{% if relation is not none %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ SELECT
{{ stg_proposals_get_state(source('decidim', 'decidim_proposals_proposals')) }} AS state,
{{ get_column_if_exists(source('decidim', 'decidim_proposals_proposals'), 'decidim_proposals_proposal_state_id', 'INTEGER') }},
comments_count,
{{ coalesce_legacy_and_new_columns(source('decidim', 'decidim_proposals_proposals'), 'endorsements_count', 'likes_count') }},
{{ coalesce_legacy_and_new_columns(source('decidim', 'decidim_proposals_proposals'), 'endorsements_count', 'likes_count', 'BIGINT') }},
follows_count,
address
FROM {{ source('decidim', 'decidim_proposals_proposals') }}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% set relation = adapter.get_relation(
database=target.database,
schema='public',
identifier='decidim_taxonomizations'
identifier='decidim_taxonomy_filter_items'
) %}

{% if relation is not none %}
Expand All @@ -11,7 +11,7 @@
taxonomy_item_id,
created_at,
updated_at
FROM {{ source('decidim', 'decidim_taxonomizations') }}
FROM {{ source('decidim', 'decidim_taxonomy_filter_items') }}
{% else %}
SELECT
CAST(NULL AS INTEGER) AS id,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% set relation = adapter.get_relation(
database=target.database,
schema='public',
identifier='decidim_taxonomizations'
identifier='decidim_taxonomy_filters'
) %}

{% if relation is not none %}
Expand All @@ -14,8 +14,8 @@
components_count,
name,
internal_name,
participatory_space_manifests,
FROM {{ source('decidim', 'decidim_taxonomizations') }}
participatory_space_manifests
FROM {{ source('decidim', 'decidim_taxonomy_filters') }}
{% else %}
SELECT
CAST(NULL AS INTEGER) AS id,
Expand Down
3 changes: 3 additions & 0 deletions projects/rc031/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
db_name_dev: RC031_DBNAME_DEV
db_name_prod: RC031_DBNAME_PROD
participation_host_name: RC031_PARTICIPATION_HOST_NAME
34 changes: 34 additions & 0 deletions projects/rc031/dbt_project.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

# Name your project! Project names should contain only lowercase characters
# and underscores. A good package name should reflect your organization's
# name or the intended use of these models
name: 'rc031'
version: '1.0.0'

# This setting configures which "profile" dbt uses for this project.
profile: 'rc031'

# These configurations specify where dbt should look for different types of files.
# The `model-paths` config, for example, states that models in this project can be
# found in the "models/" directory. You probably won't need to change these!
model-paths: ["models"]
analysis-paths: ["analyses"]
test-paths: ["tests"]
seed-paths: ["seeds"]
macro-paths: ["macros"]
snapshot-paths: ["snapshots"]

clean-targets: # directories to be removed by `dbt clean`
- "target"
- "dbt_packages"


# Configuring models
# Full documentation: https://docs.getdbt.com/docs/configuring-models

# In this example config, we tell dbt to build all models in the example/
# directory as views. These settings can be overridden in the individual model
# files using the `{{ config(...) }}` macro.
models:
rc031:
+materialized: table
4 changes: 4 additions & 0 deletions projects/rc031/packages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
packages:
- local: ../demo
- package: dbt-labs/dbt_utils
version: 1.2.0
30 changes: 30 additions & 0 deletions projects/rc031/profiles.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
rc031:
target: preprod
outputs:
dev:
dbname: "{{ env_var('DBNAME') }}"
host: "{{ env_var('HOST') }}"
pass: "{{ env_var('PASSWORD') }}"
port: "{{ env_var('PORT') | as_number }}"
schema: "{{ env_var('TARGET_SCHEMA') }}"
threads: 2
type: postgres
user: "{{ env_var('USER') }}"
preprod:
dbname: "{{ env_var('DBNAME') }}"
host: "{{ env_var('HOST_PREPROD') }}"
pass: "{{ env_var('PASSWORD_PREPROD') }}"
port: "{{ env_var('PORT_PREPROD') | as_number }}"
schema: "{{ env_var('TARGET_SCHEMA') }}"
user: "{{ env_var('USER_PREPROD') }}"
threads: 2
type: postgres
prod:
dbname: "{{ env_var('DBNAME') }}"
host: "{{ env_var('HOST') }}"
pass: "{{ env_var('PASSWORD') }}"
port: "{{ env_var('PORT') | as_number }}"
schema: "{{ env_var('TARGET_SCHEMA') }}"
threads: 2
type: postgres
user: "{{ env_var('USER') }}"
Loading