datnguye/dbterd

[FEAT] Include all refs when rendering a single model

Closed this issue ยท 4 comments

Is your feature request related to a problem? Please describe.

Currently when you render a single model w/ dbterd it will only output that model itself without its referenced tables. I couldn't find an option to include referenced models in the output with the model I want to render. It would be nice if there was an option to include all of the referenced models in the final output as well. Refs can be found in the manifest under the node information for a given model.

Describe the solution you'd like
Possibly some sort of flag to include referenced tables in the final output

dbterd run -s "my_model" --include-refs

Thanks @dylan-murray for raising the request, this is definitely a good one ๐Ÿ‘
I'm thinking about to mimic dbt's downstream/upstream selection with + sign, but it might add the complexity to the code base unecessarily ๐Ÿค”

Can I check further on which dbt version are you using? Is it v1.5?

For sure! I think if you could implement the + operator that would work fine as well. It would provide more flexibility, allowing a user to also render everything downstream of a model and not just upstream based off of the refs. The downstream part might be complicated though, I'm not sure if downstream models are readily listed anywhere or if you would have to loop the manifest to find which models are downstream.

I am currently on v1.5 of dbt.

Check point!
So, I don't want to repeat the logic of dbt-core here (not DRY, but Don't Repeat dbt ๐Ÿ˜†), I will try to utilize the dbt Programmatic Invocation bit. This way we can re-use any dbt's selection -- not sure how it's gonna work, but the expected result is:

dbterd --select ... --exclude ... --dbt-selection
# OR
dbterd --select ... --exclude ... --dbt

You should be able to dbterd run -s +model --dbt in v1.5

For information, check it out the CLI Reference