Skip to content

Commit

Permalink
Escape upstream descriptions in generate_model_yaml and cascade drop …
Browse files Browse the repository at this point in the history
…source tables in Redshift (#159)

* Escape upstream descriptions in generate_model_yaml

* Add config to implement late binding views

* Add config to implement late binding views IN THE TEST PACKAGE

* Add cascade to source table create operation table drops

* Make cascade drop redshift only

---------

Co-authored-by: gwen windflower <gwenwindflower@gmail.com>
  • Loading branch information
wircho and gwenwindflower authored Feb 28, 2024
1 parent 62516fd commit cb34ce4
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 13 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## Fixes
- Column `description` fields are now correctly escaped in `generate_model_yaml` ([#142](https://github.com/dbt-labs/dbt-codegen/issues/142))

# dbt-codegen v0.11.0

## 🚨 Breaking change
Expand Down
4 changes: 2 additions & 2 deletions dbt_project.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: 'codegen'
version: '0.5.0'
name: "codegen"
version: "0.5.0"

require-dbt-version: [">=1.1.0", "<2.0.0"]
config-version: 2
Expand Down
16 changes: 10 additions & 6 deletions integration_tests/dbt_project.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: 'codegen_integration_tests'
version: '1.0'
name: "codegen_integration_tests"
version: "1.0"
config-version: 2

profile: 'integration_tests'
profile: "integration_tests"

model-paths: ["models"]
analysis-paths: ["analyses"]
Expand All @@ -12,12 +12,16 @@ macro-paths: ["macros"]

target-path: "target"
clean-targets:
- "target"
- "dbt_packages"
- "target"
- "dbt_packages"

seeds:
+schema: raw_data
+quote_columns: false

vars:
my_table_reference: table_c
my_table_reference: table_c

models:
+bind: false

4 changes: 2 additions & 2 deletions integration_tests/macros/operations/create_source_table.sql
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ reset enable_case_sensitive_identifier;
{% do adapter.create_schema(target_schema) %}

{% set drop_table_sql %}
drop table if exists {{ target_schema }}.codegen_integration_tests__data_source_table
drop table if exists {{ target_schema }}.codegen_integration_tests__data_source_table {% if target.type == "redshift" %}cascade{% endif %}
{% endset %}

{{ run_query(drop_table_sql) }}
Expand All @@ -33,7 +33,7 @@ create table {{ target_schema }}.codegen_integration_tests__data_source_table as
{{ run_query(create_table_sql) }}

{% set drop_table_sql_case_sensitive %}
drop table if exists {{ target_schema }}.codegen_integration_tests__data_source_table_case_sensitive
drop table if exists {{ target_schema }}.codegen_integration_tests__data_source_table_case_sensitive {% if target.type == "redshift" %}cascade{% endif %}
{% endset %}

{{ run_query(drop_table_sql_case_sensitive) }}
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/models/schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ models:
- name: model_data_a
columns:
- name: col_a
description: description column a
description: 'description column "a"'
5 changes: 5 additions & 0 deletions integration_tests/package-lock.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
packages:
- local: ../
- package: dbt-labs/dbt_utils
version: 1.1.1
sha1_hash: de2deba3d66ce03d8c02949013650cc9b94f6030
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ models:
description: ""
columns:
- name: col_a
description: "description column a"
description: "description column \"a\""

- name: col_b
description: ""
Expand Down
2 changes: 1 addition & 1 deletion macros/generate_model_yaml.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
{% if include_data_types %}
{% do model_yaml.append(' data_type: ' ~ codegen.data_type_format_model(column)) %}
{% endif %}
{% do model_yaml.append(' description: "' ~ column_desc_dict.get(column.name | lower,'') ~ '"') %}
{% do model_yaml.append(' description: ' ~ (column_desc_dict.get(column.name | lower,'') | tojson)) %}
{% do model_yaml.append('') %}

{% if column.fields|length > 0 %}
Expand Down

0 comments on commit cb34ce4

Please sign in to comment.