I'd like to list and count all the DBT models (every single .sql
table) within my DBT project.
I see the dbt ls
https://docs.getdbt.com/reference/commands/listbut I'm new and can't make it work in order to list all the models.
Any suggestions?
Best Answer
dbt ls
on its own will list all nodes which include tests, snapshots, seeds, etc. To list just the models you can run dbt ls --resource-type model
. However, you don't want to pipe that directly into wc
because dbt prints out logging info by default. To get around that you can add -q
to the dbt
command.
dbt -q ls --resource-type model | wc -l
I tried
dbt ls --select my_project
where my_project
should be defined in the dbt_project.yml
by the variable name:
. This returns
my_project.my_folder.my_schema1.model1my_project.my_folder.my_schema1.model2[...]my_project.my_folder.my_schema2.model1[...]
So
dbt ls --select my_project | wc -l
gave me the number of models in my_project
.
In case is needed to skip some WARNING (or anything else) records adding an egrep -v
should help:
dbt ls --select my_project | egrep -v 'WARNING' | wc -l
I dont think this directly solves your issue but:
dbt docs generate
Does print out the number of models found.