11
11
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
12
# See the License for the specific language governing permissions and
13
13
# limitations under the License.
14
- import time
15
14
from typing import List , Optional
16
15
17
16
import typer
18
- from snowflake .cli ._plugins .dcm .dcm_project_entity_model import (
19
- DCMProjectEntityModel ,
20
- )
21
17
from snowflake .cli ._plugins .dcm .manager import DCMProjectManager
22
18
from snowflake .cli ._plugins .object .command_aliases import add_object_command_aliases
23
19
from snowflake .cli ._plugins .object .commands import scope_option
24
20
from snowflake .cli ._plugins .object .manager import ObjectManager
25
- from snowflake .cli ._plugins .stage .manager import StageManager
26
- from snowflake .cli .api .artifacts .upload import sync_artifacts_with_stage
27
- from snowflake .cli .api .cli_global_context import get_cli_context
28
- from snowflake .cli .api .commands .decorators import with_project_definition
29
21
from snowflake .cli .api .commands .flags import (
30
22
IfExistsOption ,
31
23
IfNotExistsOption ,
32
24
OverrideableOption ,
33
- entity_argument ,
34
25
identifier_argument ,
35
26
like_option ,
36
27
variables_option ,
37
28
)
38
29
from snowflake .cli .api .commands .snow_typer import SnowTyperFactory
39
- from snowflake .cli .api .commands .utils import get_entity_for_operation
40
30
from snowflake .cli .api .console .console import cli_console
41
- from snowflake .cli .api .constants import ObjectType
31
+ from snowflake .cli .api .constants import (
32
+ ObjectType ,
33
+ )
42
34
from snowflake .cli .api .exceptions import CliError
43
35
from snowflake .cli .api .feature_flags import FeatureFlag
44
36
from snowflake .cli .api .identifiers import FQN
47
39
QueryJsonValueResult ,
48
40
QueryResult ,
49
41
)
50
- from snowflake .cli .api .project .project_paths import ProjectPaths
51
- from snowflake .cli .api .project .util import unquote_identifier
52
42
53
43
app = SnowTyperFactory (
54
44
name = "dcm" ,
@@ -127,14 +117,19 @@ def deploy(
127
117
"""
128
118
Applies changes defined in DCM Project to Snowflake.
129
119
"""
130
- result = DCMProjectManager ().execute (
131
- project_name = identifier ,
132
- configuration = configuration ,
133
- from_stage = from_stage if from_stage else _sync_local_files (),
134
- variables = variables ,
135
- alias = alias ,
136
- output_path = None ,
137
- )
120
+ manager = DCMProjectManager ()
121
+ if not from_stage :
122
+ from_stage = manager .sync_local_files (project_identifier = identifier )
123
+ with cli_console .spinner () as spinner :
124
+ spinner .add_task (description = f"Deploying dcm project { identifier } " , total = None )
125
+ result = manager .execute (
126
+ project_identifier = identifier ,
127
+ configuration = configuration ,
128
+ from_stage = from_stage ,
129
+ variables = variables ,
130
+ alias = alias ,
131
+ output_path = None ,
132
+ )
138
133
return QueryJsonValueResult (result )
139
134
140
135
@@ -154,21 +149,27 @@ def plan(
154
149
"""
155
150
Plans a DCM Project deployment (validates without executing).
156
151
"""
157
- result = DCMProjectManager ().execute (
158
- project_name = identifier ,
159
- configuration = configuration ,
160
- from_stage = from_stage if from_stage else _sync_local_files (),
161
- dry_run = True ,
162
- variables = variables ,
163
- output_path = output_path ,
164
- )
152
+ manager = DCMProjectManager ()
153
+ if not from_stage :
154
+ from_stage = manager .sync_local_files (project_identifier = identifier )
155
+
156
+ with cli_console .spinner () as spinner :
157
+ spinner .add_task (description = f"Planning dcm project { identifier } " , total = None )
158
+ result = manager .execute (
159
+ project_identifier = identifier ,
160
+ configuration = configuration ,
161
+ from_stage = from_stage ,
162
+ dry_run = True ,
163
+ variables = variables ,
164
+ output_path = output_path ,
165
+ )
166
+
165
167
return QueryJsonValueResult (result )
166
168
167
169
168
170
@app .command (requires_connection = True )
169
- @with_project_definition ()
170
171
def create (
171
- entity_id : str = entity_argument ( "dcm" ) ,
172
+ identifier : FQN = dcm_identifier ,
172
173
if_not_exists : bool = IfNotExistsOption (
173
174
help = "Do nothing if the project already exists."
174
175
),
@@ -177,25 +178,18 @@ def create(
177
178
"""
178
179
Creates a DCM Project in Snowflake.
179
180
"""
180
- cli_context = get_cli_context ()
181
- project : DCMProjectEntityModel = get_entity_for_operation (
182
- cli_context = cli_context ,
183
- entity_id = entity_id ,
184
- project_definition = cli_context .project_definition ,
185
- entity_type = "dcm" ,
186
- )
187
181
om = ObjectManager ()
188
- if om .object_exists (object_type = "dcm" , fqn = project . fqn ):
189
- message = f"DCM Project '{ project . fqn } ' already exists."
182
+ if om .object_exists (object_type = "dcm" , fqn = identifier ):
183
+ message = f"DCM Project '{ identifier } ' already exists."
190
184
if if_not_exists :
191
185
return MessageResult (message )
192
186
raise CliError (message )
193
187
194
188
dpm = DCMProjectManager ()
195
- with cli_console .phase (f"Creating DCM Project '{ project . fqn } '" ):
196
- dpm .create (project = project )
189
+ with cli_console .phase (f"Creating DCM Project '{ identifier } '" ):
190
+ dpm .create (project_identifier = identifier )
197
191
198
- return MessageResult (f"DCM Project '{ project . fqn } ' successfully created." )
192
+ return MessageResult (f"DCM Project '{ identifier } ' successfully created." )
199
193
200
194
201
195
@app .command (requires_connection = True )
@@ -207,7 +201,7 @@ def list_deployments(
207
201
Lists deployments of given DCM Project.
208
202
"""
209
203
pm = DCMProjectManager ()
210
- results = pm .list_deployments (project_name = identifier )
204
+ results = pm .list_deployments (project_identifier = identifier )
211
205
return QueryResult (results )
212
206
213
207
@@ -235,40 +229,10 @@ def drop_deployment(
235
229
236
230
dpm = DCMProjectManager ()
237
231
dpm .drop_deployment (
238
- project_name = identifier ,
232
+ project_identifier = identifier ,
239
233
deployment_name = deployment_name ,
240
234
if_exists = if_exists ,
241
235
)
242
236
return MessageResult (
243
237
f"Deployment '{ deployment_name } ' dropped from DCM Project '{ identifier } '."
244
238
)
245
-
246
-
247
- def _sync_local_files () -> str :
248
- cli_context = get_cli_context ()
249
- project_entity = get_entity_for_operation (
250
- cli_context = cli_context ,
251
- entity_id = None ,
252
- project_definition = cli_context .project_definition ,
253
- entity_type = "dcm" ,
254
- )
255
-
256
- # Create a temporary stage for this deployment session
257
- stage_manager = StageManager ()
258
- unquoted_name = unquote_identifier (project_entity .fqn .name )
259
- stage_fqn = FQN .from_string (
260
- f"DCM_{ unquoted_name } _{ int (time .time ())} _TMP_STAGE"
261
- ).using_context ()
262
-
263
- with cli_console .phase ("Creating temporary stage for deployment" ):
264
- stage_manager .create (fqn = stage_fqn , temporary = True )
265
- cli_console .step (f"Created temporary stage: { stage_fqn } " )
266
-
267
- with cli_console .phase ("Syncing local files to temporary stage" ):
268
- sync_artifacts_with_stage (
269
- project_paths = ProjectPaths (project_root = cli_context .project_root ),
270
- stage_root = stage_fqn .identifier ,
271
- artifacts = project_entity .artifacts ,
272
- )
273
-
274
- return stage_fqn .identifier
0 commit comments