|sf-cli|를 사용하여 |sf-dbt| 관리하기

참고

The dbt Projects on Snowflake features in Snowflake CLI are available only in version 3.13.0 or later.

You can use Snowflake CLI to manage dbt projects with the following operations:

Deploying a dbt project object

The snow dbt deploy command uploads local files to a temporary stage and creates a new dbt project object, updates it by making a new version, or completely recreates it. A valid dbt project must contain two files:

  • dbt_project.yml: A standard dbt configuration file that specifies the profile to use.

  • profiles.yml: A dbt connection profile definition referenced in dbt_project.yml. profiles.yaml must define the database, role, schema, and type.

    • By default, dbt Projects on Snowflake 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 exist before you create your dbt Project in order for it to compile or execute successfully.

    <profile_name>:
    target: dev
    outputs:
      dev:
        database: <database_name>
        role: <role_name>
        schema: <schema_name>
        type: snowflake
    
    Copy

The following examples illustrate how to use the snow dbt deploy command:

  • :codenowrap:`jaffle_shop`이라는 dbt 프로젝트 오브젝트를 배포합니다.

    snow dbt deploy jaffle_shop
    
    Copy
  • Deploy a project named jaffle_shop from a specified directory and create or add a new version depending on whether the dbt project object already exists:

    snow dbt deploy jaffle_shop --source /path/to/dbt/directory --profiles-dir ~/.dbt/ --force
    
    Copy
  • Deploy a project named jaffle_shop from a specified directory using a custom profiles directory and enabling external access integrations:

    snow dbt deploy jaffle_shop --source /path/to/dbt/directory
    --profiles-dir ~/.dbt/ --default-target dev
    --external-access-integration dbthub-integration
    --external-access-integration github-integration
    --force
    
    Copy

Listing all available dbt project objects

The snow dbt list command lists all available dbt project objects on Snowflake.

The following examples illustrate how to use the snow dbt list command:

  • 사용 가능한 모든 dbt 프로젝트 오브젝트를 나열합니다.

    snow dbt list
    
    Copy
  • 이름이 JAFFLE`로 시작하는 dbt 프로젝트 오브젝트를 :codenowrap:`product 데이터베이스에 나열합니다.

    snow dbt list --like JAFFLE% --in database product
    
    Copy

Executing a dbt project object command

The snow dbt execute command executes one of the following dbt commands on a Snowflake dbt project object:

dbt 명령 사용에 대한 자세한 내용은 `dbt 명령 참조<https://docs.getdbt.com/reference/dbt-commands>`_ 섹션을 참조하세요.

The following examples illustrate how to use the snow dbt execute command:

  • dbt test 명령을 실행합니다.

    snow dbt execute jaffle_shop test
    
    Copy
  • run dbt 명령을 비동기적으로 실행합니다.

    snow dbt execute --run-async jaffle_shop run --select @source:snowplow,tag:nightly models/export
    
    Copy

Describing a dbt project object

The snow dbt describe command describes a dbt project object on Snowflake.

The following example describes the dbt project object named my_dbt_project on Snowflake:

snow dbt describe my_dbt_project
Copy

Dropping a dbt project object

The snow dbt drop command deletes a dbt project object on Snowflake.

The following example deletes the dbt project object named my_dbt_project on Snowflake:

snow dbt drop my_dbt_project
Copy

Use snow dbt commands in a CI/CD workflow

참고

CI/CD워크플로를 빌드할 때 Github와 Snowflake CLI 같은 git 서버만 필요합니다. Git 리포지토리 오브젝트는 필요하지 않습니다.

|sf-cli|를 사용해 dbt 명령을 실행하여 CI/CD 파이프라인을 빌드할 수 있습니다. 이러한 파이프라인은 일반적으로 새 풀 요청과 같은 새 코드를 테스트하거나, 기본 분기에 병합될 때마다 프로덕션 애플리케이션을 업데이트하는 데 사용됩니다.

snow dbt 명령을 사용하여 CI/CD 워크플로를 빌드하려면 다음 단계를 따르세요.

  1. dbt 프로젝트를 준비합니다.

    1. dbt 프로젝트를 다운로드하거나 새 프로젝트를 시작합니다.

      • 기본 프로젝트 디렉터리에 dbt_project.ymlprofiles.yml 파일이 포함되어 있는지 확인합니다.

      • :file:`dbt_project.yml`에서 참조된 프로필 이름이 :file:`profiles.yml`에 정의되어 있는지 확인합니다.

        참고

        Snowflake의 dbt 프로젝트 오브젝트에는 비밀번호가 필요하지 않으므로, :file:`profiles.yml`에 비밀번호가 포함된 경우 이를 제거할 때까지 배포가 중지됩니다.

  2. Snowflake CLI GitHub 작업을 설정합니다.

    지침에 따라 :doc:`Snowflake CLI에 대한 GitHub 작업을 설정 </developer-guide/snowflake-cli/cicd/integrate-ci-cd>`하고, Snowflake에 대한 :ref:`연결을 확인<label-cli_test_connection>`하세요.

  3. 워크플로를 정의합니다.

    조직의 요구 사항에 따라 워크플로에서 실행해야 하는 명령을 결정합니다. 다음 예제에서는 :codenowrap:`product_pipeline`이라는 dbt 프로젝트 오브젝트 버전을 새 파일로 업데이트하는 CI 워크플로를 설명하고, 변환 작업을 실행하며, 마지막으로 테스트를 실행합니다.

    - name: Execute Snowflake CLI command
      run: |
        snow dbt deploy product_pipeline
        snow dbt execute product_pipeline run
        snow dbt execute product_pipeline test
    
    Copy