Hey @drege
Thanks so much for moving this to Discourse!
You’re completely right, filenames for models in dbt must be unique, even if they live in different directories, or are materialized in separate custom schemas.
This is because the ref
function only takes one argument – the filename. I you try to have two files with the same name, dbt will give you back an error like this:
$ dbt run
Running with dbt=0.14.2
Encountered an error:
Compilation Error
dbt found two resources with the name "stg_payments". Since these resources have the same name,
dbt will be unable to find the correct resource when ref("stg_payments") is used. To fix this,
change the name of one of these resources:
- model.jaffle_shop.stg_payments (models/staging/jaffle_shop/stg_payments.sql)
- model.jaffle_shop.stg_payments (models/staging/stripe/stg_payments.sql)
To get around this limitation, we often following a naming pattern like <source>__<object>.sql
. For this example we’d have:
stg_stripe__payments.sql
, andstg_jaffle_shop__payments.sql
We’ve written lots more on the naming conventions we use over in this article:
Pro tip: if you consistently use the same separator in your filenames, you can actually tell dbt to use the first part of your filename as the custom schema, and the second part as the view/table name. @brandyn recently wrote a great post on this over here: