将项目定义文件从版本 1.x 迁移到版本 2.0¶
要将版本 1.x 项目定义文件转换为版本 2 格式,请执行以下操作:
转到包含版本 1.x
snowflake.yml
文件的项目目录。输入
snow helpers v1-to-v2
命令。如果版本 1.x 文件转换成功,则该命令将显示一条类似于以下内容的消息:
cd <project-directory> snow helpers v1-to-v2
Project definition migrated to version 2.
如果您的项目定义文件已经更新到版本 2,则该命令会显示以下消息:
cd <project-directory> snow helpers v1-to-v2
Project definition is already at version 2.
如果您尝试在不使用
--[no]-migrate-local-overrides
选项的情况下转换包含snowflake.local.yml
文件的项目文件,则该命令会生成类似于以下内容的错误:
如果您尝试在不使用
--accept-templates
选项的情况下转换包含模板的项目文件,则该命令会生成类似于以下内容的错误:cd <project-directory> snow helpers v1-to-v2+- Error-------------------------------------------------------------------+ | snowflake.local.yml file detected, please specify | | --migrate-local-overrides to include or --no-migrate-local-overrides to | | exclude its values. | +--------------------------------------------------------------------------+如果您转换包含模板的项目定义文件并使用
--accept-templates
选项,则该命令会转换该文件并显示一条类似于以下内容的警告消息:cd <project-directory> snow helpers v1-to-v2WARNING snowflake.cli._plugins.workspace.commands:commands.py:60 Your V1 definition contains templates. We cannot guarantee the correctness of the migration. Project definition migrated to version 2
转换 Native App 项目¶
本节显示了 Snowflake Native App 项目从 V1 到 V2 转换的示例,列出了属性名称的变更,并提供了一些有助于迁移的技巧。
Snowflake Native App 转换示例¶
V1 项目文件 |
V2 项目文件 |
---|---|
definition_version: 1
native_app:
name: myapp
source_stage: app_src.stage
artifacts:
- src: app/*
dest: ./
processors:
- native app setup
- name: templates
properties:
foo: bar
package:
role: pkg_role
distribution: external
application:
name: myapp_app
warehouse: app_wh
|
definition_version: 2
entities:
pkg:
type: application package
meta:
role: pkg_role
identifier: <% fn.concat_ids('myapp', '_pkg_', fn.sanitize_id(fn.get_username('unknown_user')) | lower) %>
manifest: app/manifest.yml
artifacts:
- src: app/*
dest: ./
processors:
- name: native app setup
- name: templates
properties:
foo: bar
stage: app_src.stage
app:
meta:
warehouse: app_wh
identifier: myapp_app
type: application
from:
target: pkg
|
Native App 项目定义从 V1 到 V2 的属性变更¶
V1 属性 |
V2 属性 |
---|---|
|
没有等效内容。如果需要,请使用模板变量进行移植。 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
:codenowrap:`<application entity>.meta.post_deploy`(请参阅上面的注释) |
|
|
|
|
|
|
|
|
|
:codenowrap:`<package entity>.meta.post_deploy`(请参阅上面的注释) |
|
|
|
:codenowrap:`<package entity>.meta.post_deploy`(请参阅上面的注释) |
|
|
迁移技巧¶
在迁移 Snowflake Native App 包脚本时,
v1-to-v2
命令会将其转换为package post-deploy
hook,并将包脚本文件中的{{package_name}}
替换为等效的模板表达式。迁移现有模板表达式时,
ctx.native_app
、ctx.streamlit
和:codenowrap:ctx.snowpark
变量不再被接受。具有等效模板表达式的v1-to-v2
命令会改为引用特定的实体名称。例如,如果该包迁移到snowflake.yml
文件中名为pkg
的实体,则ctx.native_app.package.name
可以被ctx.entities.pkg.identifier
替换。
转换 Streamlit 项目¶
本节显示了 Streamlit 项目从 V1 到 V2 转换的示例,列出了属性名称的变更,并提供了一些有助于迁移的技巧。
Streamlit 转换示例¶
V1 项目文件 |
V2 项目文件 |
---|---|
definition_version: 1
streamlit:
name: test_streamlit
stage: streamlit
query_warehouse: test_warehouse
main_file: "streamlit_app.py"
title: "My Fancy Streamlit"
|
definition_version: 2
entities:
test_streamlit:
identifier:
name: test_streamlit
type: streamlit
title: My Fancy Streamlit
query_warehouse: test_warehouse
main_file: streamlit_app.py
pages_dir: None
stage: streamlit
artifacts:
- streamlit_app.py
|
Streamlit 项目定义从 V1 到 V2 的属性变更¶
V1 属性 |
V2 属性 |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Streamlit 迁移技巧¶
无。
转换 Snowpark 项目¶
本节显示了 Snowpark 项目从 V1 到 V2 转换的示例,列出了属性名称的变更,并提供了一些有助于迁移的技巧。
Snowpark 转换示例¶
V1 项目文件 |
V2 项目文件 |
---|---|
definition_version: 1
snowpark:
project_name: "my_snowpark_project"
stage_name: "dev_deployment"
src: "app/"
functions:
- name: func1
handler: "app.func1_handler"
signature:
- name: "a"
type: "string"
default: "default value"
- name: "b"
type: "variant"
returns: string
runtime: 3.10
procedures:
- name: procedureName
handler: "hello"
signature:
- name: "name"
type: "string"
returns: string
|
definition_version: 2
entities:
procedureName:
imports: []
external_access_integrations: []
secrets: {}
meta:
use_mixins:
- snowpark_shared
identifier:
name: procedureName
handler: hello
returns: string
signature:
- name: name
type: string
stage: dev_deployment
artifacts:
- src: app
dest: my_snowpark_project
type: procedure
execute_as_caller: false
func1:
imports: []
external_access_integrations: []
secrets: {}
meta:
use_mixins:
- snowpark_shared
identifier:
name: func1
handler: app.func1_handler
returns: string
signature:
- name: a
type: string
default: default value
- name: b
type: variant
runtime: '3.10'
stage: dev_deployment
artifacts:
- src: app
dest: my_snowpark_project
type: function
mixins:
snowpark_shared:
stage: dev_deployment
artifacts:
- src: app/
dest: my_snowpark_project
|
Snowpark 项目定义从 V1 到 V2 的属性变更¶
V1 属性 |
V2 属性 |
---|---|
|
|
|
|
|
|
:codenowrap:`snowpark.functions`(列表) |
|
:codenowrap:`snowpark.procedures`(列表) |
|
V1 属性 |
V2 属性 |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
:codenowrap:`execute_as_caller`(仅适用于过程) |
Snowpark 迁移技巧¶
迁移 Snowpark 项目时,每个函数(来自
snowpark.functions
数组)或过程(来自snowpark.procedures
数组)都会映射到顶级实体。现在,为每个函数和过程定义了所有顶级 Snowpark 项目属性(例如
src
)。为了减少重复,Snowflake 建议您声明mixin
并将其包含在每个迁移的函数和过程实体中。