dbt_artifacts
dbt_artifacts copied to clipboard
Add support for dynamic schema name generation for artifacts
This request was initially surfaced here in dbt slack.
Hi there. It is possible to use Jinja inside dbt_project to dynamically build the schema name for different environments when used in a package variable? I'm using dbt_artifacts and want the schema to be
adt(stands for audit) in prod, but<target.user>_adtin dev.
The goal here is for the dbt_artifacts_schema (currently set in vars) to be dynamic, based on user name and environment.
@jaypeedevlin and I played around with using the generate_schema_name macro to do this. It works fine in create_dbt_artifacts_tables() to replace the logic in the set database_name (here) with logic that utilizes the generate_database_name() macro. The problem arises when we attempt to update the database in the sources.yml file (here). The macro isn't acceptable in this file, and therefore this solution isn't feasible.
Two proposed approaches for tackling this would be:
- Make the source tables in to dbt models so that we can utilize the
generate_schema_name()macro - Make some assumptions about how users will structure their projects and create vars that reflect those assumptions. (For instance, a
prodanddevlocation for the artifacts.)