By running dbt docs generate and dbt docs serve, I can generate a documentation for my models that contains all column names automatically. If I do something like this:
models/.yml
version: 2
models:
- name: events
description: This table contains clickstream events from the marketing website
the documentation that is generated already contains a list of columns + their type. However, the column description column is empty. If I want to add a description, I can do something like this:
version: 2
models:
- name: events
description: This table contains clickstream events from the marketing website
columns:
- name: event_id
description: This is a unique identifier for the event
tests:
- unique
- not_null
However, in this way, I will have to manually type all column names. Is there any way I can automate this? Such that the column names can be automatically extracted in a list etc and I only have to write the descriptions? I will have to do this for multiple files.
The canonical way to do this is with the codegen package, which generates the files exactly as you have described.
If you are working in VS Code, I can recommend using the dbt Power User VS Code Extension: https://www.dbt-power-user.com/
It has a great GUI and you can synchronize your models with the database and extract all column names and data types.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With