Skip to content

Commit 9203402

Browse files
Jw/snow 2306298 dcm improve ux (#2583)
feat: [SNOW-2306298] improve UX of dcm commands
1 parent 24146a2 commit 9203402

File tree

8 files changed

+39
-39
lines changed

8 files changed

+39
-39
lines changed

src/snowflake/cli/_plugins/dcm/manager.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -113,21 +113,15 @@ def sync_local_files(project_identifier: FQN) -> str:
113113
if MANIFEST_FILE_NAME not in definitions:
114114
definitions.append(MANIFEST_FILE_NAME)
115115

116-
# Create a temporary stage for this deployment session
117-
stage_manager = StageManager()
118-
unquoted_name = unquote_identifier(project_identifier.name)
119-
stage_fqn = FQN.from_string(
120-
f"DCM_{unquoted_name}_{int(time.time())}_TMP_STAGE"
121-
).using_context()
122-
123-
with cli_console.phase("Creating temporary stage for deployment"):
124-
stage_manager.create(fqn=stage_fqn, temporary=True)
125-
cli_console.step(f"Created temporary stage: {stage_fqn}")
126-
127-
with cli_console.phase("Syncing local files to temporary stage"):
116+
with cli_console.phase(f"Uploading definition files"):
117+
unquoted_name = unquote_identifier(project_identifier.name)
118+
stage_fqn = FQN.from_string(
119+
f"DCM_{unquoted_name}_{int(time.time())}_TMP_STAGE"
120+
).using_context()
128121
sync_artifacts_with_stage(
129122
project_paths=ProjectPaths(project_root=Path.cwd()),
130123
stage_root=stage_fqn.identifier,
124+
use_temporary_stage=True,
131125
artifacts=[PathMapping(src=definition) for definition in definitions],
132126
pattern_type=PatternMatchingType.REGEX,
133127
)

src/snowflake/cli/_plugins/nativeapp/sf_sql_facade.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,7 @@ def create_stage(
632632
role: str | None = None,
633633
database: str | None = None,
634634
schema: str | None = None,
635+
temporary: bool = False,
635636
):
636637
"""
637638
Creates a stage.
@@ -641,13 +642,14 @@ def create_stage(
641642
@param [Optional] role: Role to switch to while running this script. Current role will be used if no role is passed in.
642643
@param [Optional] database: Database to use while running this script, unless the stage name is database-qualified.
643644
@param [Optional] schema: Schema to use while running this script, unless the stage name is schema-qualified.
645+
@param [Optional] temporary: determines if stage should be temporary. Default is false.
644646
"""
645647
fqn = FQN.from_string(name)
646648
identifier = to_identifier(fqn.name)
647649
database = fqn.database or database
648650
schema = fqn.schema or schema
649651

650-
query = f"create stage if not exists {identifier}"
652+
query = f"create{' temporary' if temporary else ''} stage if not exists {identifier}"
651653
if encryption_type:
652654
query += f" encryption = (type = '{encryption_type}')"
653655
if enable_directory:

src/snowflake/cli/api/artifacts/upload.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
def sync_artifacts_with_stage(
1414
project_paths: ProjectPaths,
1515
stage_root: str,
16+
use_temporary_stage: bool = False,
1617
prune: bool = False,
1718
artifacts: Optional[List[PathMapping]] = None,
1819
pattern_type: PatternMatchingType = PatternMatchingType.GLOB,
@@ -33,6 +34,7 @@ def sync_artifacts_with_stage(
3334
prune=prune,
3435
recursive=True,
3536
stage_path_parts=stage_path_parts,
37+
use_temporary_stage=use_temporary_stage,
3638
print_diff=True,
3739
)
3840
project_paths.clean_up_output()

src/snowflake/cli/api/entities/utils.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ def sync_deploy_root_with_stage(
8787
prune: bool,
8888
recursive: bool,
8989
stage_path_parts: StagePathParts,
90+
use_temporary_stage: bool = False,
9091
role: str | None = None,
9192
package_name: str | None = None,
9293
local_paths_to_sync: List[Path] | None = None,
@@ -103,6 +104,7 @@ def sync_deploy_root_with_stage(
103104
prune (bool): Whether to prune artifacts from the stage that don't exist locally.
104105
recursive (bool): Whether to traverse directories recursively.
105106
stage_path_parts (StagePathParts): stage path parts object.
107+
use_temporary_stage (bool): specifies if new stage should be temporary.
106108
107109
package_name (str): supported for Native App compatibility. Should be None out of Native App context.
108110
@@ -120,8 +122,11 @@ def sync_deploy_root_with_stage(
120122
elif not package_name:
121123
# ensure stage exists
122124
stage_fqn = FQN.from_stage(stage_path_parts.stage)
123-
console.step(f"Creating stage {stage_fqn} if not exists.")
124-
StageManager().create(fqn=stage_fqn)
125+
if use_temporary_stage:
126+
console.step(f"Creating temporary stage {stage_fqn}.")
127+
else:
128+
console.step(f"Creating stage {stage_fqn} if not exists.")
129+
StageManager().create(fqn=stage_fqn, temporary=use_temporary_stage)
125130
else:
126131
# ensure stage exists - nativeapp behavior
127132
sql_facade = get_snowflake_facade()
@@ -134,10 +139,10 @@ def sync_deploy_root_with_stage(
134139
)
135140
if not sql_facade.stage_exists(stage_fqn):
136141
sql_facade.create_schema(schema, database=package_name)
137-
sql_facade.create_stage(stage_fqn)
142+
sql_facade.create_stage(stage_fqn, temporary=use_temporary_stage)
138143

139144
# Perform a diff operation and display results to the user for informational purposes
140-
if print_diff:
145+
if print_diff and not use_temporary_stage:
141146
console.step(
142147
f"Performing a diff between the Snowflake stage: {stage_path_parts.path} and your local deploy_root: {deploy_root.resolve()}."
143148
)
@@ -199,8 +204,7 @@ def sync_deploy_root_with_stage(
199204
# Upload diff-ed files to the stage
200205
if diff.has_changes():
201206
console.step(
202-
"Updating the Snowflake stage from your local %s directory."
203-
% deploy_root.resolve(),
207+
f"Uploading files from local {deploy_root.resolve()} directory to{' temporary' if use_temporary_stage else ''} stage."
204208
)
205209
sync_local_diff_with_stage(
206210
role=role,

tests/dcm/test_commands.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55

66
DCMProjectManager = "snowflake.cli._plugins.dcm.commands.DCMProjectManager"
77
ObjectManager = "snowflake.cli._plugins.dcm.commands.ObjectManager"
8-
get_entity_for_operation = (
9-
"snowflake.cli._plugins.dcm.commands.get_entity_for_operation"
10-
)
118

129

1310
@pytest.fixture

tests/dcm/test_manager.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ def test_calls_sync_artifacts_with_stage(
295295
PathMapping(src="manifest.yml", dest=None, processors=[]),
296296
]
297297
assert call_args.kwargs["pattern_type"] == PatternMatchingType.REGEX
298+
assert call_args.kwargs["use_temporary_stage"] is True
298299

299300
actual_project_root = call_args.kwargs["project_paths"].project_root
300301
expected_project_root = project_dir.resolve()

tests/nativeapp/test_manager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def test_sync_deploy_root_with_stage(
157157
mock_stage_exists.assert_called_once_with(stage_fqn)
158158
if not stage_exists:
159159
mock_create_schema.assert_called_once_with(stage_schema, database=package_name)
160-
mock_create_stage.assert_called_once_with(stage_fqn)
160+
mock_create_stage.assert_called_once_with(stage_fqn, temporary=False)
161161
mock_compute_stage_diff.assert_called_once_with(
162162
local_root=dm.project_root / pkg_model.deploy_root,
163163
stage_path=DefaultStagePathParts.from_fqn("app_pkg.app_src.stage"),
@@ -222,7 +222,7 @@ def test_sync_deploy_root_with_stage_subdir(
222222
mock_stage_exists.assert_called_once_with(stage_fqn)
223223
if not stage_exists:
224224
mock_create_schema.assert_called_once_with(stage_schema, database=package_name)
225-
mock_create_stage.assert_called_once_with(stage_fqn)
225+
mock_create_stage.assert_called_once_with(stage_fqn, temporary=False)
226226
mock_compute_stage_diff.assert_called_once_with(
227227
local_root=dm.project_root / pkg_model.deploy_root,
228228
stage_path=DefaultStagePathParts.from_fqn(stage_fqn, "v1"),

tests_integration/nativeapp/__snapshots__/test_deploy.ambr

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
added: app/README.md -> README.md
99
added: app/manifest.yml -> manifest.yml
1010
added: app/setup_script.sql -> setup_script.sql
11-
Updating the Snowflake stage from your local @@DEPLOY_ROOT@@ directory.
11+
Uploading files from local @@DEPLOY_ROOT@@ directory to stage.
1212
Validating Snowflake Native App setup script.
1313
Deployed successfully. Application package and stage are up-to-date.
1414

@@ -23,7 +23,7 @@
2323
added: app/README.md -> README.md
2424
added: app/manifest.yml -> manifest.yml
2525
added: app/setup_script.sql -> setup_script.sql
26-
Updating the Snowflake stage from your local @@DEPLOY_ROOT@@ directory.
26+
Uploading files from local @@DEPLOY_ROOT@@ directory to stage.
2727
Validating Snowflake Native App setup script.
2828
Deployed successfully. Application package and stage are up-to-date.
2929

@@ -38,7 +38,7 @@
3838
added: app/README.md -> README.md
3939
added: app/manifest.yml -> manifest.yml
4040
added: app/setup_script.sql -> setup_script.sql
41-
Updating the Snowflake stage from your local @@DEPLOY_ROOT@@ directory.
41+
Uploading files from local @@DEPLOY_ROOT@@ directory to stage.
4242
Validating Snowflake Native App setup script.
4343
Deployed successfully.
4444

@@ -53,7 +53,7 @@
5353
added: app/README.md -> README.md
5454
added: app/manifest.yml -> manifest.yml
5555
added: app/setup_script.sql -> setup_script.sql
56-
Updating the Snowflake stage from your local @@DEPLOY_ROOT@@ directory.
56+
Uploading files from local @@DEPLOY_ROOT@@ directory to stage.
5757
Validating Snowflake Native App setup script.
5858
Deployed successfully. Application package and stage are up-to-date.
5959

@@ -67,7 +67,7 @@
6767
Local changes to be deployed:
6868
added: app/manifest.yml -> manifest.yml
6969
added: app/setup_script.sql -> setup_script.sql
70-
Updating the Snowflake stage from your local @@DEPLOY_ROOT@@ directory.
70+
Uploading files from local @@DEPLOY_ROOT@@ directory to stage.
7171
Deployed successfully. Application package and stage are up-to-date.
7272

7373
'''
@@ -81,7 +81,7 @@
8181
added: app/v2/README.md -> README.md
8282
added: app/v2/manifest.yml -> manifest.yml
8383
added: app/v2/setup.sql -> setup.sql
84-
Updating the Snowflake stage from your local @@DEPLOY_ROOT@@/v2 directory.
84+
Uploading files from local @@DEPLOY_ROOT@@/v2 directory to stage.
8585
Validating Snowflake Native App setup script.
8686
Deployed successfully. Application package and stage are up-to-date.
8787

@@ -96,7 +96,7 @@
9696
added: app/README.md -> README.md
9797
added: app/manifest.yml -> manifest.yml
9898
added: app/setup_script.sql -> setup_script.sql
99-
Updating the Snowflake stage from your local @@DEPLOY_ROOT@@ directory.
99+
Uploading files from local @@DEPLOY_ROOT@@ directory to stage.
100100
Validating Snowflake Native App setup script.
101101
Deployed successfully. Application package and stage are up-to-date.
102102

@@ -109,7 +109,7 @@
109109
Performing a diff between the Snowflake stage: stage and your local deploy_root: @@DEPLOY_ROOT@@.
110110
Local changes to be deployed:
111111
added: app/nested/dir/file.txt -> nested/dir/file.txt
112-
Updating the Snowflake stage from your local @@DEPLOY_ROOT@@ directory.
112+
Uploading files from local @@DEPLOY_ROOT@@ directory to stage.
113113
Deployed successfully. Application package and stage are up-to-date.
114114

115115
'''
@@ -134,7 +134,7 @@
134134
Performing a diff between the Snowflake stage: stage and your local deploy_root: @@DEPLOY_ROOT@@.
135135
Deleted paths to be removed from your stage:
136136
deleted: README.md
137-
Updating the Snowflake stage from your local @@DEPLOY_ROOT@@ directory.
137+
Uploading files from local @@DEPLOY_ROOT@@ directory to stage.
138138
Deployed successfully. Application package and stage are up-to-date.
139139

140140
'''
@@ -145,7 +145,7 @@
145145
Performing a diff between the Snowflake stage: stage and your local deploy_root: @@DEPLOY_ROOT@@.
146146
Deleted paths to be removed from your stage:
147147
deleted: README.md
148-
Updating the Snowflake stage from your local @@DEPLOY_ROOT@@ directory.
148+
Uploading files from local @@DEPLOY_ROOT@@ directory to stage.
149149
Deployed successfully. Application package and stage are up-to-date.
150150

151151
'''
@@ -170,7 +170,7 @@
170170
Performing a diff between the Snowflake stage: stage and your local deploy_root: @@DEPLOY_ROOT@@.
171171
Deleted paths to be removed from your stage:
172172
deleted: README.md
173-
Updating the Snowflake stage from your local @@DEPLOY_ROOT@@ directory.
173+
Uploading files from local @@DEPLOY_ROOT@@ directory to stage.
174174
Deployed successfully.
175175

176176
'''
@@ -181,7 +181,7 @@
181181
Performing a diff between the Snowflake stage: stage and your local deploy_root: @@DEPLOY_ROOT@@.
182182
Deleted paths to be removed from your stage:
183183
deleted: README.md
184-
Updating the Snowflake stage from your local @@DEPLOY_ROOT@@ directory.
184+
Uploading files from local @@DEPLOY_ROOT@@ directory to stage.
185185
Deployed successfully.
186186

187187
'''
@@ -206,7 +206,7 @@
206206
Performing a diff between the Snowflake stage: stage/v1 and your local deploy_root: @@DEPLOY_ROOT@@/v1.
207207
Deleted paths to be removed from your stage:
208208
deleted: README.md
209-
Updating the Snowflake stage from your local @@DEPLOY_ROOT@@/v1 directory.
209+
Uploading files from local @@DEPLOY_ROOT@@/v1 directory to stage.
210210
Deployed successfully. Application package and stage are up-to-date.
211211

212212
'''
@@ -217,7 +217,7 @@
217217
Performing a diff between the Snowflake stage: stage/v1 and your local deploy_root: @@DEPLOY_ROOT@@/v1.
218218
Deleted paths to be removed from your stage:
219219
deleted: README.md
220-
Updating the Snowflake stage from your local @@DEPLOY_ROOT@@/v1 directory.
220+
Uploading files from local @@DEPLOY_ROOT@@/v1 directory to stage.
221221
Deployed successfully. Application package and stage are up-to-date.
222222

223223
'''
@@ -231,7 +231,7 @@
231231
added: app/v1/README.md -> README.md
232232
added: app/v1/manifest.yml -> manifest.yml
233233
added: app/v1/setup.sql -> setup.sql
234-
Updating the Snowflake stage from your local @@DEPLOY_ROOT@@/v1 directory.
234+
Uploading files from local @@DEPLOY_ROOT@@/v1 directory to stage.
235235
Validating Snowflake Native App setup script.
236236
Deployed successfully. Application package and stage are up-to-date.
237237

0 commit comments

Comments
 (0)