diff --git a/CHANGELOG.md b/CHANGELOG.md index 079252e..5e1cd0b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -59,6 +59,16 @@ dispatch: # dbt-codegen v0.8.0 +# 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/README.md b/README.md index 653d1ca..3f8e461 100644 --- a/README.md +++ b/README.md @@ -61,6 +61,13 @@ the database to your source definition * `include_schema` (optional, default=False): Whether you want to add the schema to your source definition +### 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 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" diff --git a/macros/generate_base_model.sql b/macros/generate_base_model.sql index bc6129a..edb1c14 100644 --- a/macros/generate_base_model.sql +++ b/macros/generate_base_model.sql @@ -38,7 +38,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 0971489..9eef803 100644 --- a/macros/generate_model_import_ctes.sql +++ b/macros/generate_model_import_ctes.sql @@ -396,7 +396,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 f226536..2a696a2 100644 --- a/macros/generate_model_yaml.sql +++ b/macros/generate_model_yaml.sql @@ -49,7 +49,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 31fd3e7..76cda02 100644 --- a/macros/generate_source.sql +++ b/macros/generate_source.sql @@ -77,7 +77,7 @@ {% if execute %} {% set joined = sources_yaml | join ('\n') %} - {{ log(joined, info=True) }} + {{ print(joined) }} {% do return(joined) %} {% endif %}