From bf655f0def24dbfc9591570e00e830a19ca751ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Gr=C3=B8ndal?= Date: Wed, 26 Oct 2022 11:22:12 +0200 Subject: [PATCH 1/3] Use print for outputting codegen --- CHANGELOG.md | 10 ++++++++++ macros/generate_base_model.sql | 2 +- macros/generate_model_import_ctes.sql | 2 +- macros/generate_model_yaml.sql | 2 +- macros/generate_source.sql | 2 +- 5 files changed, 14 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 124ea15..8d246cf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,16 @@ - [@handle](https://github.com/handle) (#XXX) ---> +# Unreleased +## Breaking changes +## New features +## Quality of life +- Now uses `print` instead of `log` to output the generated text into the console. This enables you to invoke dbt with the `--quiet` flag and directly pipe the codegen output into a new file, ending up with valid yaml + +## Under the hood +## Contributors: +- [@JorgenG](https://github.com/JorgenG) (#86) + # dbt-codegen v0.7.0 ## 🚨 Breaking change diff --git a/macros/generate_base_model.sql b/macros/generate_base_model.sql index 2016de6..5587ccd 100644 --- a/macros/generate_base_model.sql +++ b/macros/generate_base_model.sql @@ -33,7 +33,7 @@ select * from renamed {% if execute %} -{{ log(base_model_sql, info=True) }} +{{ print(base_model_sql) }} {% do return(base_model_sql) %} {% endif %} diff --git a/macros/generate_model_import_ctes.sql b/macros/generate_model_import_ctes.sql index 414f1ba..7684890 100644 --- a/macros/generate_model_import_ctes.sql +++ b/macros/generate_model_import_ctes.sql @@ -167,7 +167,7 @@ {%- if execute -%} -{{ log(model_import_ctes, info=True) }} +{{ print(model_import_ctes) }} {% do return(model_import_ctes) %} {% endif %} diff --git a/macros/generate_model_yaml.sql b/macros/generate_model_yaml.sql index f00f910..3452f91 100644 --- a/macros/generate_model_yaml.sql +++ b/macros/generate_model_yaml.sql @@ -39,7 +39,7 @@ {% if execute %} {% set joined = model_yaml | join ('\n') %} - {{ log(joined, info=True) }} + {{ print(joined) }} {% do return(joined) %} {% endif %} diff --git a/macros/generate_source.sql b/macros/generate_source.sql index 366b4b8..de2ba7c 100644 --- a/macros/generate_source.sql +++ b/macros/generate_source.sql @@ -74,7 +74,7 @@ {% if execute %} {% set joined = sources_yaml | join ('\n') %} - {{ log(joined, info=True) }} + {{ print(joined) }} {% do return(joined) %} {% endif %} From ed84a5d9e02f6808db749c7e6424f6acd8b9ed87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Gr=C3=B8ndal?= Date: Wed, 26 Oct 2022 11:30:25 +0200 Subject: [PATCH 2/3] Add example of piping to file in README --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index 0b553b0..f770e6e 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,13 @@ want to subselect from all available tables within a given schema. * `exclude` (optional, default=''): A string you want to exclude from the selection criteria * `name` (optional, default=schema_name): The name of your source +### Outputting to a file +If you use the `dbt run-operation` approach it is possible to output directly to a file by piping the output to a new file and using the `--quiet` CLI flag: + +``` +dbt --quiet run-operation generate_model_yaml --args '{"model_name": "stg_jaffle_shop__orders"}' > models/staging/jaffle_shop/stg_jaffle_shop__orders.yml +``` + ### Usage: 1. Copy the macro into a statement tab in the dbt Cloud IDE, or into an analysis file, and compile your code From 536246d7aeb8f76ce7bbe7cccd9093203a77d4f7 Mon Sep 17 00:00:00 2001 From: Joel Labes Date: Mon, 27 Nov 2023 14:09:53 +1300 Subject: [PATCH 3/3] Bump require-dbt-version --- dbt_project.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dbt_project.yml b/dbt_project.yml index 05cc6d7..91dfcf1 100644 --- a/dbt_project.yml +++ b/dbt_project.yml @@ -1,7 +1,7 @@ name: 'codegen' version: '0.5.0' -require-dbt-version: [">=1.0.0", "<2.0.0"] +require-dbt-version: [">=1.1.0", "<2.0.0"] config-version: 2 target-path: "target"