17
17
from sqlmesh .core .snapshot .definition import (
18
18
SnapshotInfoMixin ,
19
19
)
20
- from sqlmesh .utils import Verbosity , rich as srich
20
+ from sqlmesh .utils import Verbosity , rich as srich , to_snake_case
21
21
from sqlmesh .utils .date import to_ts
22
22
from sqlmesh .utils .errors import SQLMeshError
23
23
@@ -73,7 +73,7 @@ def __init__(
73
73
def explain (self , stages : t .List [stages .PlanStage ]) -> None :
74
74
tree = Tree ("[bold]Explained plan[/bold]" )
75
75
for stage in stages :
76
- handler_name = f"visit_{ _to_snake_case (stage .__class__ .__name__ )} "
76
+ handler_name = f"visit_{ to_snake_case (stage .__class__ .__name__ )} "
77
77
if not hasattr (self , handler_name ):
78
78
logger .error ("Unexpected stage: %s" , stage .__class__ .__name__ )
79
79
continue
@@ -97,6 +97,9 @@ def visit_physical_layer_update_stage(self, stage: stages.PhysicalLayerUpdateSta
97
97
"[bold]Validate SQL and create physical layer tables and views if they do not exist[/bold]"
98
98
)
99
99
for snapshot in stage .snapshots :
100
+ if snapshot .snapshot_id not in stage .snapshots_with_missing_intervals :
101
+ continue
102
+
100
103
is_deployable = (
101
104
stage .deployability_index .is_deployable (snapshot )
102
105
if self .environment_naming_info .name != c .PROD
@@ -114,7 +117,9 @@ def visit_physical_layer_update_stage(self, stage: stages.PhysicalLayerUpdateSta
114
117
115
118
if snapshot .is_view :
116
119
create_tree = Tree ("Create view if it doesn't exist" )
117
- elif snapshot .is_forward_only and snapshot .previous_versions :
120
+ elif (
121
+ snapshot .is_forward_only and snapshot .previous_versions and not snapshot .is_managed
122
+ ):
118
123
prod_table = snapshot .table_name (True )
119
124
create_tree = Tree (
120
125
f"Clone { prod_table } into { table_name } and then update its schema if it doesn't exist"
@@ -224,7 +229,7 @@ def visit_virtual_layer_update_stage(self, stage: stages.VirtualLayerUpdateStage
224
229
"[bold]Delete views in the virtual layer for models that were removed[/bold]"
225
230
)
226
231
for snapshot in stage .demoted_snapshots :
227
- display_name = self ._display_name (snapshot )
232
+ display_name = self ._display_name (snapshot , stage . demoted_environment_naming_info )
228
233
demote_tree .add (display_name )
229
234
230
235
if stage .promoted_snapshots :
@@ -233,14 +238,31 @@ def visit_virtual_layer_update_stage(self, stage: stages.VirtualLayerUpdateStage
233
238
tree .add (self ._limit_tree (demote_tree ))
234
239
return tree
235
240
241
+ def visit_create_snapshot_records_stage (
242
+ self , stage : stages .CreateSnapshotRecordsStage
243
+ ) -> t .Optional [Tree ]:
244
+ return None
245
+
236
246
def visit_environment_record_update_stage (
237
247
self , stage : stages .EnvironmentRecordUpdateStage
238
248
) -> t .Optional [Tree ]:
239
249
return None
240
250
241
- def _display_name (self , snapshot : SnapshotInfoMixin ) -> str :
251
+ def visit_unpause_stage (self , stage : stages .UnpauseStage ) -> t .Optional [Tree ]:
252
+ return None
253
+
254
+ def visit_finalize_environment_stage (
255
+ self , stage : stages .FinalizeEnvironmentStage
256
+ ) -> t .Optional [Tree ]:
257
+ return None
258
+
259
+ def _display_name (
260
+ self ,
261
+ snapshot : SnapshotInfoMixin ,
262
+ environment_naming_info : t .Optional [EnvironmentNamingInfo ] = None ,
263
+ ) -> str :
242
264
return snapshot .display_name (
243
- self .environment_naming_info ,
265
+ environment_naming_info or self .environment_naming_info ,
244
266
self .default_catalog if self .verbosity < Verbosity .VERY_VERBOSE else None ,
245
267
dialect = self .dialect ,
246
268
)
@@ -273,9 +295,3 @@ def _get_explainer_console(
273
295
verbosity = console .verbosity ,
274
296
console = console .console ,
275
297
)
276
-
277
-
278
- def _to_snake_case (name : str ) -> str :
279
- return "" .join (
280
- f"_{ c .lower ()} " if c .isupper () and idx != 0 else c .lower () for idx , c in enumerate (name )
281
- )
0 commit comments