Hello,
I am new to dbt.
I am using dbt core on top of bigquery.
I have added new schema name under models on the dbt_project.yml file.
models:
universities:
# Applies to all files under models/example/
example:
+materialized: table
schema: myschema
I thought all the output tables/views should be written to myschema, but the output is written into dbt_Tisrael_myschema. Why is that? How can I change it to write to myschema?
Thanks in advance.
Read this https://docs.getdbt.com/docs/build/custom-schemas
Note: @Mike Stanley
originally posted this reply in Slack. It might not have transferred perfectly.
I tried it and it did not work.
It looks like the default target schema is:dbt_
dbt Core environments | dbt Developer Hub (getdbt.com)
Is there any way to change the default target schema with dbt Core?
I do not see the profiles.yml file - it does not exist in dbt core?
Yes, there is a macro called generate schema name, this is the default behavior
{% macro generate_schema_name(custom_schema_name, node) -%}
{%- set default_schema = target.schema -%}
{%- if custom_schema_name is none -%}
{{ default_schema }}
{%- else -%}
{{ default_schema }}_{{ custom_schema_name | trim }}
{%- endif -%}
{%- endmacro %}
You see, if you have a custom_schema_name (myschema), it will append it into the default_schema, which seem to be dbt_Tisrael.
To override this behavior you should create a macro (a .SQL file) inside your macros folder with the same name but with different instructions. For example, if you want the schema to be exactly your custom_schema, you can do it like
{% macro generate_schema_name(custom_schema_name, node) -%}
{%- set default_schema = target.schema -%}
{%- if custom_schema_name is none -%}
{{ default_schema }}
{%- else -%}
{{ custom_schema_name | trim }}
{%- endif -%}
{%- endmacro %}
Just be aware that it is a good practice for each developer have its own schema. So you have no conflicts in development. So be sure this is really what you want to do