Deploy DCM Project
Overview
This sub-skill provides a safe, structured workflow for deploying DCM project changes to Snowflake. Deployment is a critical operation that can create, modify, or delete database objects.
⚠️ CRITICAL SAFETY RULES
- NEVER deploy without running plan first
- NEVER deploy without explicit user confirmation
- ALWAYS highlight destructive changes (DROP, data-affecting ALTER)
- ALWAYS recommend using deployment aliases
Prerequisites
Before deploying, ensure:
- Analyze has been run successfully (no errors)
- Plan has been run successfully (no PLAN_FAILED status)
- User has reviewed the plan summary
- User has given explicit confirmation to proceed
Deployment Workflow
Step 0: Pre-Flight Checks
A. Scan for legacy DDL hooks:
Before proceeding, scan definition files for ATTACH PRE_HOOK or ATTACH POST_HOOK. If found, inform the user that DDL hooks are not supported in the current version of DCM and offer to extract the hook contents into pre_deploy.sql / post_deploy.sql companion scripts. ⚠️ Warn that companion scripts do NOT support Jinja — any {{ }} variables must be replaced with literal values or shell variable substitution. Do not proceed with plan until hooks are resolved.
B. Detect companion scripts:
Check the project root for these files:
pre_deploy.sql— must run beforesnow dcm plan(creates objects the planner validates against)post_deploy.sql— must run aftersnow dcm deploypost_deployment_grants.sql— must run after deploy (existing behavior)
If any are found, present a single consolidated summary:
"I found companion scripts for this project:
pre_deploy.sql— will run before plan (⚠️ may require elevated roles like ACCOUNTADMIN)post_deploy.sql— will run after deploypost_deployment_grants.sql— will run after deployShall I run these at the appropriate times during the deployment workflow?"
Get a single approval. If pre_deploy.sql exists, proceed to run it before Step 1.
Running pre_deploy.sql:
snow sql -f pre_deploy.sql -c <connection> --role ACCOUNTADMIN
⚠️ Objects in pre_deploy.sql often require elevated roles (ACCOUNTADMIN for integrations — including the storage integrations that external stages reference, SECURITYADMIN for network policies). Warn the user about role requirements.
Step 1: Verify Analyze Passed
If analyze hasn't been run recently:
snow dcm raw-analyze <identifier> -c <connection> \
--target <target> \
⚠️ CRITICAL: Read and Parse the Output
You MUST read and parse command output.
Do NOT proceed if there are errors.
Step 2: Run Plan (or Use Existing Output)
Check if plan output already exists:
- If
out/plan/plan_result.jsonexists and is current, read it instead of rerunning - Only rerun plan if explicitly requested by user or if definitions have changed
If plan needs to be run:
snow dcm plan <identifier> -c <connection> \
--target <target> \
--save-output
⚠️ CRITICAL: Read and Parse the Output
You MUST read and parse out/plan/plan_result.json.
For detailed instructions, see: Parent SKILL.md - Critical: Reading Output Files
Do NOT proceed to deployment without parsing the plan output.
Step 3: Present Plan Summary
Parse the plan output and present a clear summary:
╔══════════════════════════════════════════════════════════════╗
║ 📊 DEPLOYMENT PLAN ║
╠══════════════════════════════════════════════════════════════╣
║ Project: <DATABASE.SCHEMA.PROJECT_NAME> ║
║ Target: <target_name> ║
║ Connection: <connection_name> ║
╠══════════════════════════════════════════════════════════════╣
║ ║
║ ✅ CREATE: X objects ║
║ • TABLE: MY_DB.RAW.NEW_TABLE ║
║ • DYNAMIC_TABLE: MY_DB.ANALYTICS.SUMMARY ║
║ • TASK: MY_DB.ETL.TSK_DAILY_LOAD ║
║ • ROLE: MY_DB_READER ║
║ ║
║ ⚠️ ALTER: Y objects ║
║ • TABLE: MY_DB.RAW.CUSTOMERS ║
║ └─ Add column: EMAIL (VARCHAR) ║
║ └─ Change column: AMOUNT (NUMBER → NUMBER(15,2)) ║
║ • TASK: MY_DB.ETL.TSK_PROCESS_ORDERS ║
║ └─ Task will be auto-suspended, modified, and resumed ║
║ ║
║ 🚨 DROP: Z objects ║
║ • VIEW: MY_DB.SERVE.OLD_REPORT ║
║ ⚠️ WARNING: This object and its data will be deleted ║
║ ║
╚══════════════════════════════════════════════════════════════╝
Note on Tasks: When tasks are modified during deployment, DCM automatically suspends/resumes them - no manual intervention needed.
Step 4: Highlight Risky Changes
For each of these scenarios, add explicit warnings:
| Change Type | Risk Level | Warning Message |
|---|---|---|
| DROP TABLE | 🚨 HIGH | "All data in this table will be permanently deleted" |
| DROP VIEW | ⚠️ MEDIUM | "This view will be removed; dependent queries will fail" |
| DROP DYNAMIC TABLE | 🚨 HIGH | "All computed data will be lost" |
| DROP TASK | ⚠️ MEDIUM | "Scheduled operations will stop; task will be deleted" |
| ALTER TASK | ℹ️ INFO | "Task will be auto-suspended, modified, and auto-resumed" |
| Column DROP | 🚨 HIGH | "Data in this column will be permanently lost" |
| Column TYPE change | ⚠️ MEDIUM | "May fail if existing data is incompatible with new type" |
| GRANT revocation | ⚠️ MEDIUM | "Users/roles may lose access" |
Step 5: Offer Preview (Optional)
Ask the user:
"Before deployment, would you like to preview data in any of the objects that will be modified or dropped?"
If yes:
snow dcm preview <identifier> -c <connection> \
--object <fully.qualified.object.name> \
--target <target> \
--limit 10
This is especially useful for:
- Verifying data before DROP operations
- Checking current state before ALTER operations
Step 6: Request Explicit Confirmation
Present a clear confirmation prompt:
╔══════════════════════════════════════════════════════════════╗
║ ⚠️ DEPLOYMENT CONFIRMATION ║
╠══════════════════════════════════════════════════════════════╣
║ ║
║ You are about to deploy changes to LIVE Snowflake ║
║ infrastructure. ║
║ ║
║ • Creates: X objects ║
║ • Alters: Y objects ║
║ • Drops: Z objects ║
║ ║
║ Target Database: <database> ║
║ Using Connection: <connection> ║
║ ║
║ This action CANNOT be automatically undone. ║
║ ║
╠══════════════════════════════════════════════════════════════╣
║ ║
║ Type "yes" to confirm deployment, or "no" to cancel. ║
║ ║
╚══════════════════════════════════════════════════════════════╝
DO NOT PROCEED unless user explicitly confirms with "yes".
Step 7: Execute Deployment
Suggest an alias for tracking:
"Would you like to add a deployment alias for tracking? (e.g., 'v1.0', 'add-email-column', 'initial-setup')"
snow dcm deploy <identifier> -c <connection> \
--target <target> \
--alias "<user-provided-alias-or-timestamp>"
Step 8: Verify Deployment
After successful deployment:
Confirm success - Report the deployment completed
Check for tests - From the analyze output, determine if the project has data quality tests:
Do any definitions have DATA_METRIC_SCHEDULE or ATTACH DATA METRIC FUNCTION?Offer to run tests:
"This project has data quality tests defined. Would you like to run them to verify the deployment?"
Step 8.1: Run Post-Deploy Script (If Any)
If post_deploy.sql exists and user approved companion scripts in Step 0:
snow sql -f post_deploy.sql -c <connection>
⚠️ If the script requires a specific role (e.g., objects referencing integrations created by ACCOUNTADMIN), add --role <ROLE> or ensure the script includes USE ROLE statements.
This creates objects that depend on DEFINE'd entities (for example semantic views). These scripts are safe to re-run if they use CREATE IF NOT EXISTS or CREATE OR REPLACE.
Step 8.2: Apply Unsupported Grants (If Any)
Check if the project has a post_deployment_grants.sql file (grants that DCM cannot apply):
If file exists, present to user:
"The following grants could not be applied by DCM and require manual execution:
- [list grants from post_deployment_grants.sql]
These typically include:
GRANT ... ON ACCOUNT,GRANT IMPORTED PRIVILEGES, warehouse grants to database roles, etc.Would you like me to execute these grants now? (Requires appropriate privileges)"
⚠️ CHECKPOINT: Get explicit approval before running post-deployment grants.
Step 9: Run Tests (If Requested)
If the project has tests and user wants to run them:
Refresh dynamic tables first (ensures fresh data):
snow dcm refresh <identifier> -c <connection>Run tests:
snow dcm test <identifier> -c <connection>Report test results - Summarize pass/fail status
Post-Deployment
Viewing Deployment History
snow dcm list-deployments <identifier> -c <connection>
Rolling Back
DCM doesn't have automatic rollback. To "undo" a deployment:
- Modify definition files to previous state
- Run plan to see what will change
- Deploy the reverted definitions
Recommendation: Keep definition files in version control (git) for easy rollback.
Error Handling
Plan Fails
If plan returns PLAN_FAILED:
- Check the
errorfield in the output - Common causes:
- Invalid SQL syntax
- Missing dependencies
- Permission issues
- Object state conflicts
Deployment Fails
If deploy fails:
- Note the error message
- Check Snowflake query history for failed DDL
- Some objects may have been created/modified before failure
- Run plan again to see remaining changes
Partial Deployment
If deployment partially succeeds:
- Some objects were created/modified
- Run plan to see what's left
- Fix any errors and re-deploy
Stuck Deploy / Project Lock
Snowflake holds a server-side project lock for the entire duration of any snow dcm deploy execution. If the CLI times out, is killed client-side, or the deploy stalls for any reason, the Snowflake-side execution continues running and the lock remains held. Common causes include slow DDL operations, long-running Dynamic Table initializations, or transient Snowflake issues.
Symptoms:
- CLI hangs with the progress bar frozen at some percentage for 10-15 minutes with no movement
- Re-attempting deploy fails with:
Cannot execute DCM project because it is currently being executed by another process
Fix: find and cancel the stuck query
Step 1 - Discover the running deploy query:
SELECT query_id, LEFT(query_text, 100) AS query_text, start_time
FROM TABLE(<DB>.INFORMATION_SCHEMA.QUERY_HISTORY_BY_USER(RESULT_LIMIT=>50))
WHERE execution_status = 'RUNNING'
AND query_text ILIKE '%EXECUTE DCM PROJECT%'
AND start_time >= DATEADD('hour', -1, CURRENT_TIMESTAMP())
ORDER BY start_time ASC;
- If no rows are returned: The server-side execution may have just completed before you ran the query. Wait 30 seconds and verify with
snow dcm plan. If plan still fails with the lock error, contact Snowflake Support — do not attempt further cancellation steps. - If one row is returned: Present the
query_id,query_text, andstart_timeto the user and ask for explicit confirmation before proceeding to Step 2. - If multiple rows are returned: Present all rows to the user and ask which
query_idto cancel. If the user wants to cancel all of them, do so one at a time instart_time ASCorder, requiring separate confirmation for each.
Step 2 - Cancel the query (requires user confirmation):
Show the user the query details from Step 1 and ask: "Found stuck query <query_id> started at <start_time>. Cancel it now?" Only proceed after the user confirms.
SELECT SYSTEM$CANCEL_QUERY('<query_id_from_above>');
After the query is cancelled, verify with snow dcm plan. If plan succeeds, the lock is gone — redeploy. If plan still returns the lock error, re-run the Step 1 discovery query. If no rows are returned at that point, contact Snowflake Support.
Do NOT use snow dcm drop-deployment to release the lock. It operates on deployment metadata only and may return a Snowflake internal error when the project is in a stuck state.
Quick Reference
Commands Used
| Command | Purpose |
|---|---|
snow dcm raw-analyze |
Validate project, find errors |
snow dcm plan |
Preview what will change |
snow dcm preview |
View sample data from objects |
snow dcm deploy |
Apply changes to Snowflake |
snow dcm refresh |
Refresh dynamic tables |
snow dcm test |
Run data quality tests |
snow dcm list-deployments |
View deployment history |
Always Include
-c <connection>: Connection name--target <target>: Target name from manifest.yml (bundles project identifier + templating config)--save-output: [important!] For plan command only
Recommended
--alias "<name>": For deploy, to track deployment history