Understand schema generation and customization¶
dbt 使用默认宏 generate_schema_name 来决定在何处构建模型。
By default, it uses your target schema (target.schema) specified from your dbt environment or profile. Unlike dbt Core behavior, the
target schema specified in the profiles.yml file must already exist in Snowflake before you
deploy your dbt project object.
Otherwise, the project fails to compile or execute.
通常,每个开发者都有自己的目标架构,例如 analytics_dev。对于较大的项目,您可以设置自定义架构来对模型进行分组,并在 dbt_project.yml 文件中指定架构配置键。dbt 将其追加到目标架构(例如,<target_schema>_<custom_schema>),以保持中间模型和面向用户的模型分离。
模型的自定义架构不会替换目标架构;相反,dbt 会将它们组合起来以避免冲突。例如 analytics_dev_staging。这是因为,如果 dbt 忽略目标架构并仅使用自定义架构(在这种情况下,staging),每个开发者都会写入到相同的架构并相互覆盖。
如果您想要不同的行为(例如,仅使用自定义架构、在用户名前面添加前缀、添加环境前缀等),请在 /macros/ 中替换 generate_schema_name,以更改最终架构名称的构建方式。有关更多信息和示例,请参阅 dbt 文档中的 更改 dbt 生成架构名称的方式 (https://docs.getdbt.com/docs/build/custom-schemas#changing-the-way-dbt-generates-a-schema-name)。