2121from sqlmesh .core import analytics
2222from sqlmesh .core import constants as c
2323from sqlmesh .core .console import Console , get_console
24+ from sqlmesh .core .environment import EnvironmentNamingInfo
2425from sqlmesh .core .notification_target import (
2526 NotificationTarget ,
2627)
3233 SnapshotEvaluator ,
3334 SnapshotIntervals ,
3435 SnapshotId ,
36+ SnapshotInfoLike ,
37+ SnapshotTableInfo ,
3538)
3639from sqlmesh .core .state_sync import StateSync
3740from sqlmesh .core .state_sync .base import PromotionResult
@@ -306,14 +309,16 @@ def _update_views(
306309
307310 completed = False
308311 try :
309- self .snapshot_evaluator .promote (
312+ self ._promote_snapshots (
313+ plan ,
310314 [snapshots [s .snapshot_id ] for s in promotion_result .added ],
311315 environment .naming_info ,
312316 deployability_index = deployability_index ,
313317 on_complete = lambda s : self .console .update_promotion_progress (s , True ),
314318 )
315319 if promotion_result .removed_environment_naming_info :
316- self .snapshot_evaluator .demote (
320+ self ._demote_snapshots (
321+ plan ,
317322 promotion_result .removed ,
318323 promotion_result .removed_environment_naming_info ,
319324 on_complete = lambda s : self .console .update_promotion_progress (s , False ),
@@ -323,6 +328,32 @@ def _update_views(
323328 finally :
324329 self .console .stop_promotion_progress (success = completed )
325330
331+ def _promote_snapshots (
332+ self ,
333+ plan : EvaluatablePlan ,
334+ target_snapshots : t .Iterable [Snapshot ],
335+ environment_naming_info : EnvironmentNamingInfo ,
336+ deployability_index : t .Optional [DeployabilityIndex ] = None ,
337+ on_complete : t .Optional [t .Callable [[SnapshotInfoLike ], None ]] = None ,
338+ ) -> None :
339+ self .snapshot_evaluator .promote (
340+ target_snapshots ,
341+ environment_naming_info ,
342+ deployability_index = deployability_index ,
343+ on_complete = on_complete ,
344+ )
345+
346+ def _demote_snapshots (
347+ self ,
348+ plan : EvaluatablePlan ,
349+ target_snapshots : t .Iterable [SnapshotTableInfo ],
350+ environment_naming_info : EnvironmentNamingInfo ,
351+ on_complete : t .Optional [t .Callable [[SnapshotInfoLike ], None ]] = None ,
352+ ) -> None :
353+ self .snapshot_evaluator .demote (
354+ target_snapshots , environment_naming_info , on_complete = on_complete
355+ )
356+
326357 def _restate (self , plan : EvaluatablePlan , snapshots_by_name : t .Dict [str , Snapshot ]) -> None :
327358 if not plan .restatements :
328359 return
0 commit comments