Skip to content

Commit 4000e07

Browse files
Merge pull request #23 from Snowflake-Labs/dcm-migrate-review-fixes
Refactor DCM migration tools to support object-type filtering and imp…
2 parents 11b3a13 + 6f0df8a commit 4000e07

4 files changed

Lines changed: 341 additions & 163 deletions

File tree

migration-tools/Cortex_Code_Skill/dcm-migrate/SKILL.md

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ Scans a database, retrieves DDL for all objects (tables, views, dynamic tables,
4949

5050
Automatically skips (reported as UNSUPPORTED):
5151
- **Semantic views** (not yet supported by DCM)
52+
- **Data metric functions** (GET_DDL signature does not match regular functions)
5253
- **Non-SQL functions and procedures** (Python, Java, JavaScript, Scala)
5354
- **External stages** (have a URL — manage outside DCM)
5455
- **OWNERSHIP grants** (implicit from object creation)
@@ -64,18 +65,20 @@ When an unsupported row appears in the output, the reason is given in the `file_
6465
```bash
6566
SNOWFLAKE_CONNECTION_NAME=<connection> uv run --project <SKILL_DIR> \
6667
python <SKILL_DIR>/scripts/ddl_to_dcm.py \
67-
--database <DB_NAME> \
68-
--output <PROJECT_DIR>/sources/definitions \
69-
[--schemas SCHEMA1 SCHEMA2 ...] \
70-
[--group-by-type] \
68+
--db-name <DB_NAME> \
69+
[--schema-list SCHEMA1 SCHEMA2 ...] \
70+
[--object-types TYPE1 TYPE2 ...] \
71+
[--group-files-by-type] \
72+
--output-path <PROJECT_DIR>/sources/definitions \
7173
[--role <ROLE_NAME>]
7274
```
7375

7476
**Arguments:**
75-
- `--database` (required): Source database name
76-
- `--output` (required): Local directory for generated definition files
77-
- `--schemas` (optional): Space-separated schema allow-list; omit for all schemas
78-
- `--group-by-type` (optional): Write one file per object type per schema (recommended for large databases)
77+
- `--db-name` (required): Source database name
78+
- `--schema-list` (optional): Space-separated schema allow-list; omit for all schemas
79+
- `--object-types` (optional): Space-separated object-type allow-list. Accepted values (case-insensitive, spaces or underscores): `TABLE`, `VIEW`, `DYNAMIC TABLE`, `TASK`, `FUNCTION`, `PROCEDURE`, `SEQUENCE`, `FILE FORMAT`, `ALERT`, `TAG`, `STAGE`, `SCHEMA`, `GRANT`. Omit for all supported types. Any unknown value aborts the run with an ERROR row before any Snowflake calls are made.
80+
- `--group-files-by-type` (optional): Write one file per object type per schema (recommended for large databases)
81+
- `--output-path` (required): Local directory for generated definition files
7982
- `--connection` (optional): Snowflake connection name override. Normally use the `SNOWFLAKE_CONNECTION_NAME` env var instead.
8083
- `--role` (optional): Only migrate objects owned by this role. Filters schemas, tables, views, dynamic tables, tasks, functions, procedures, sequences, file formats, alerts, tags, and internal stages by the `owner` column. Recommended for non-ACCOUNTADMIN users to avoid permission errors on unowned objects.
8184

@@ -155,9 +158,10 @@ Collect from the user:
155158

156159
1. **Source database** (required)
157160
2. **Schema allow-list** (optional; omit for all schemas)
158-
3. **Target DCM project** — new or existing?
159-
4. **Connection** — which Snowflake connection to use
160-
5. **Group by type** — one file per type per schema (recommended) or one file per object
161+
3. **Object-type allow-list** (optional; omit for all supported types). Accepted values: `TABLE`, `VIEW`, `DYNAMIC TABLE`, `TASK`, `FUNCTION`, `PROCEDURE`, `SEQUENCE`, `FILE FORMAT`, `ALERT`, `TAG`, `STAGE`, `SCHEMA`, `GRANT`.
162+
4. **Target DCM project** — new or existing?
163+
5. **Connection** — which Snowflake connection to use
164+
6. **Group by type** — one file per type per schema (recommended) or one file per object
161165

162166
**Path handling:** Files must be on the local filesystem (DCM CLI requires it). If the user specifies a workspace/stage path, explain this and offer to sync after migration via `snow stage copy`.
163167

@@ -242,13 +246,13 @@ Collect from the user:
242246

243247
#### Local mode
244248

245-
Run `ddl_to_dcm.py` using the command from the **Tools** section above, with `--output <project_dir>/sources/definitions --group-by-type`. Add `--schemas` if only specific schemas should be migrated. If the user chose **owned-only** in Step 1, add `--role <ROLE_NAME>` (using the role from `SELECT CURRENT_ROLE()`). Parse the JSON output from stdout.
249+
Run `ddl_to_dcm.py` using the command from the **Tools** section above, with `--output-path <project_dir>/sources/definitions --group-files-by-type`. Add `--schema-list` if only specific schemas should be migrated, and `--object-types` if only specific object types should be migrated. If the user chose **owned-only** in Step 1, add `--role <ROLE_NAME>` (using the role from `SELECT CURRENT_ROLE()`). Parse the JSON output from stdout.
246250

247251
#### Workspaces mode
248252

249253
Replicate the logic of `ddl_to_dcm.py` inline using SQL queries and agent file writes:
250254

251-
1. **Discover objects:** `SHOW OBJECTS IN DATABASE`, `SHOW SCHEMAS IN DATABASE`, `SHOW SEMANTIC VIEWS IN DATABASE` (to exclude semantic views). Per schema: `SHOW TASKS`, `SHOW USER FUNCTIONS`, `SHOW USER PROCEDURES`, `SHOW SEQUENCES`, `SHOW FILE FORMATS`, `SHOW ALERTS`. If owned-only, filter by the `owner` column. Query `INFORMATION_SCHEMA.PROCEDURES`/`FUNCTIONS` to skip non-SQL callables.
255+
1. **Discover objects:** `SHOW OBJECTS IN DATABASE`, `SHOW SCHEMAS IN DATABASE`, `SHOW SEMANTIC VIEWS IN DATABASE` (to exclude semantic views). Per schema: `SHOW TASKS`, `SHOW USER FUNCTIONS`, `SHOW USER PROCEDURES`, `SHOW SEQUENCES`, `SHOW FILE FORMATS`, `SHOW ALERTS`. If owned-only, filter by the `owner` column. Query `INFORMATION_SCHEMA.PROCEDURES`/`FUNCTIONS` to skip non-SQL callables. On `SHOW USER FUNCTIONS` rows, skip any row with `is_data_metric = 'Y'` (reported as UNSUPPORTED: `data metric function`). If the user provided an object-type allow-list, validate every value against the canonical set (`TABLE`, `VIEW`, `DYNAMIC TABLE`, `TASK`, `FUNCTION`, `PROCEDURE`, `SEQUENCE`, `FILE FORMAT`, `ALERT`, `TAG`, `STAGE`, `SCHEMA`, `GRANT`) before any scanning, and skip the discovery steps for types that are not allowed.
252256

253257
2. **Convert DDL:** For each object, run `GET_DDL`, replace `CREATE` with `DEFINE`, uppercase the type keyword, expand same-schema bare references to FQNs. For functions/procedures, use the signature form for `GET_DDL` and expand the bare name to a quoted FQN.
254258

@@ -272,6 +276,7 @@ Review the generated definitions for objects that DCM does not support with DEFI
272276
| External Stages (with URL) | Unsupported | Reported as UNSUPPORTED; manage outside DCM |
273277
| Streams | Not yet handled | Silently skipped by the migration |
274278
| Semantic Views | Unsupported | Recreate manually after deploy; the migration skips them |
279+
| Data Metric Functions | Unsupported | Recreate manually after deploy; the migration skips them |
275280
| Non-SQL Functions/Procedures (Python, Java, etc.) | Unsupported | Recreate manually after deploy; the migration skips them |
276281
| Integrations, Network Rules | Unsupported | Move to `pre_deploy.sql` |
277282

0 commit comments

Comments
 (0)