The problem I’m having
I am looking for a way to change dbt run behavior in dependency to user config
The context of why I’m trying to do this
We are using dbt Core and have different teams to work with the dbt using Snowflake:
Data engineers
Data analytics
These teams need slightly different behavior of dbt models deployment. As Data Analytics work mostly with Sandbox databases to prototype Data models they need database name to have included in table names in query (using ref macro). For Data Engineers it’s important not to have database name not included as we use clonning and clon database should have reference integrity inside itself.
I know that I can parametrise dbt run, but it will be necessaruy to include variable in each dbt call. I am looking for the way to make a and distribute different different config versions to different user groups. Is there a way to do it?
User management is easier in dbt Cloud, where you can establish governance and better segregate groups. However, if you’re working with dbt Core, to achieve your goal, consider the following approach:
- Find a way to tag each user as either a Data Analyst or Data Engineer.
- Once you know the user’s group, you can create a macro that, depending on the group, saves data in the appropriate location.
ex:
{% macro generate_database_name_role(custom_database_name=None, node=None) -%}
{% set default_database = target.database %}
{% if role_user == "data engineer" %}
{{ default_database }}
{% else %} {# role_user is "data analyst" or "other" #}
sandbox_{{ default_database | trim }}
{% endif %}
{%- endmacro %}
Here’s a base example. If you need more information, I’m happy to help.
Thank you, that makes sense. It’s good although not ideal
I was looking for something like user configuration. What is the difference for dbt cloud?