Managing DCM projects using Snowflake CLI

You can manage a DCM project using Snowflake CLI. For more information about DCM projects, see Snowflake DCM Projects.

Install Snowflake CLI with DCM project features

To use the snow dcm commands, you must install Snowflake CLI version 3.16.0 or later. For more information, see Installing Snowflake CLI.

Verify you have a valid connection to Snowflake

Snowflake CLI requires a working connection to interact with Snowflake. For information about managing connections, see Configuring Snowflake CLI.

Enable DCM commands in Snowflake CLI

To use DCM commands, you must enable the SNOWFLAKE_CLI_FEATURES_ENABLE_SNOWFLAKE_PROJECTS feature flag, using either of the following methods:

  • Set the SNOWFLAKE_CLI_FEATURES_ENABLE_SNOWFLAKE_PROJECTS environment variable to true before running the command.

  • Set the enable_snowflake_projects configuration option to true in the config.toml file, as shown in the following example:

    [cli.features]
    enable_snowflake_projects = true
    

Initialize a DCM project from a template

  • To initialize a DCM project from a template, use the snow init command:

    snow init <project_dir_name> --template dcm_project
    

    where <project_dir_name> is the directory with the DCM project files. This directory is created by the snow init command and is populated with the project files generated from the specified template.

    For example, the following command creates the project files in the MY_PROJECT directory:

    snow init MY_PROJECT --template dcm_project
    

Snowflake CLI commands

To support DCM Projects, Snowflake CLI added the following commands:

Create and deploy DCM projects

This section describes how to create, validate, and deploy DCM projects using Snowflake CLI.

Create a DCM project

Use the snow dcm create command to create a new DCM project in Snowflake. The project identifier can be specified directly as an argument or resolved from the manifest.yml file.

  • Create a project using the identifier from the default target specified in the manifest :

    snow dcm create
    
  • Create a project using the identifier from the dev target specified in the manifest:

    snow dcm create --target dev
    
  • Create a project only if it does not already exist:

    snow dcm create --if-not-exists
    

For more information, see snow dcm create.

Plan a DCM project

Use the snow dcm plan command to validate your project before deploying. This command shows what changes would be applied without actually making any modifications.

  • Validate a project:

    snow dcm plan
    
  • Validate with variable substitution:

    snow dcm plan -D "db_name=my_database" -D "schema_name=my_schema"
    
  • Validate using a specific target profile and save the output:

    snow dcm plan --target dev --save-output
    

    When using --save-output, the command saves the response and artifacts to a local out/ directory.

For more information, see snow dcm plan.

Deploy a DCM project

Use the snow dcm deploy command to apply changes defined in your DCM project to Snowflake..

  • Deploy a project:

    snow dcm deploy
    
  • Deploy with variable substitution:

    snow dcm deploy -D "table_name='MY_DB.PUBLIC.MY_TABLE'"
    
  • Deploy with an alias for the deployment:

    snow dcm deploy --alias v1.0
    
  • Deploy from a specific directory using a target profile:

    snow dcm deploy --from /path/to/project --target prod
    

For more information, see snow dcm deploy.

Preview a DCM project

Use the snow dcm preview command to return rows from any table, view, or dynamic table defined in your project. This command is useful for testing your definitions before or after deployment.

  • Preview data from a table:

    snow dcm preview --object MY_DB.PUBLIC.MY_TABLE
    
  • Preview with a row limit:

    snow dcm preview --object MY_DB.PUBLIC.MY_VIEW --limit 10
    
  • Preview with variable substitution:

    snow dcm preview --object MY_DB.PUBLIC.MY_VIEW -D "filter_date='2024-01-01'"
    

For more information, see snow dcm preview.

Test a DCM project

Use the snow dcm test command to run all expectations (data metric functions) defined in your project. This command validates data quality rules and returns pass/fail results.

  • Test a project:

    snow dcm test
    
  • Test using a target profile:

    snow dcm test --target dev
    
  • Test and save the results:

    snow dcm test --save-output
    

The command returns exit code 0 if all tests pass, or exit code 1 if any test fails.

For more information, see snow dcm test.

Refresh a DCM project

Use the snow dcm refresh command to refresh all dynamic tables defined in your DCM project. This triggers an immediate refresh of the data.

  • Refresh dynamic tables in a project:

    snow dcm refresh
    
  • Refresh using a target profile:

    snow dcm refresh --target prod
    
  • Refresh and save the output:

    snow dcm refresh --save-output
    

The command reports the status of each dynamic table, including the number of rows inserted and deleted.

For more information, see snow dcm refresh.

Drop a DCM project

Use the snow dcm drop command to drop a DCM project. This command deletes the project and all its versions. The stage associated with the project is not deleted.

  • Drop a project:

    snow dcm drop
    
  • Drop a project only if it exists:

    snow dcm drop --if-exists
    

For more information, see snow dcm drop.

Manage deployed DCM projects

After deploying a DCM project, you can list and manage individual deployments.

List deployed DCM projects

Use the snow dcm list-deployments command to list all deployments of a given DCM project.

  • List deployments for a project:

    snow dcm list-deployments
    
  • List deployments using a target profile:

    snow dcm list-deployments --target dev
    

The output shows the deployment name and alias (if set) for each deployment.

For more information, see snow dcm list-deployments.

Drop deployed DCM projects

Use the snow dcm drop-deployment command to drop a specific deployment from a DCM project.

  • Drop a deployment by name:

    snow dcm drop-deployment --deployment 'DEPLOYMENT$1'
    

    Note

    For deployment names containing $, use single quotes to prevent shell expansion.

  • Drop a deployment by alias:

    snow dcm drop-deployment --deployment v1.0
    
  • Drop a deployment only if it exists:

    snow dcm drop-deployment --deployment v1.0 --if-exists
    

For more information, see snow dcm drop-deployment.