Understand dbt project objects

A DBT PROJECT is a schema-level object that contains versioned source files for your dbt project in Snowflake. You can connect a dbt project object to a workspace, or you can create and manage the object independently of a workspace.

A dbt project object is typically based on a dbt project directory that contains a dbt_project.yml file. This is the pattern that Snowflake uses when you deploy (create) a dbt project object from within a workspace.

dbt project objects support role-based access control (RBAC). You can CREATE, ALTER, and DROP dbt project objects like other schema-level objects in Snowflake. You can use the EXECUTE DBT PROJECT command from a Snowflake warehouse to execute dbt commands like test and run. You can also use tasks to schedule execution of these commands.

dbt 项目对象如何更新

dbt project objects don't automatically update as you edit the workspace. You must execute ALTER DBT PROJECT ... ADD VERSION each time you want to redeploy and update the files of the dbt project object.

要创建生产管道,建议创建 dbt 项目对象,并 通过任务调度其执行。由于每个 dbt 项目对象版本都是不可变的,因此这样做可以确保运行之间不会发生任何变化,除非有人显式添加新版本。

To update the dbt project object's files, you must add a new version in a workspace, for example:

ALTER DBT PROJECT testdbt.public.my_dbt_project_object
  ADD VERSION FROM 'snow://workspace/user$.public."all_my_dbt_projects"/versions/last';

If your dbt project object is backed by Git and you want to automate your testing and deployment, run the Snow CLI snow dbt deploy command with the --force option, as shown in the following example:

snow dbt deploy --source 'snow://workspace/user$.public."all_my_dbt_projects"/versions/last'  --force my_dbt_project;

--force 使您能够添加版本;如果没有它,则相当于在已创建的对象上运行 CREATE DBT PROJECT,这将会失败。

For more information about versioning, see Versions for dbt project objects and files.