@@ -276,8 +276,10 @@ def promote(
276276
277277 def demote (
278278 self ,
279- target_snapshots : t .Iterable [SnapshotInfoLike ],
279+ target_snapshots : t .Iterable [Snapshot ],
280280 environment_naming_info : EnvironmentNamingInfo ,
281+ table_mapping : t .Optional [t .Dict [str , str ]] = None ,
282+ deployability_index : t .Optional [DeployabilityIndex ] = None ,
281283 on_complete : t .Optional [t .Callable [[SnapshotInfoLike ], None ]] = None ,
282284 ) -> None :
283285 """Demotes the given collection of snapshots in the target environment by removing its view.
@@ -290,7 +292,13 @@ def demote(
290292 with self .concurrent_context ():
291293 concurrent_apply_to_snapshots (
292294 target_snapshots ,
293- lambda s : self ._demote_snapshot (s , environment_naming_info , on_complete ),
295+ lambda s : self ._demote_snapshot (
296+ s ,
297+ environment_naming_info ,
298+ deployability_index = deployability_index ,
299+ on_complete = on_complete ,
300+ table_mapping = table_mapping ,
301+ ),
294302 self .ddl_concurrent_tasks ,
295303 )
296304
@@ -970,25 +978,32 @@ def _promote_snapshot(
970978 snapshots : t .Optional [t .Dict [SnapshotId , Snapshot ]] = None ,
971979 table_mapping : t .Optional [t .Dict [str , str ]] = None ,
972980 ) -> None :
973- if snapshot .is_model :
974- adapter = (
975- self .get_adapter (snapshot .model_gateway )
976- if environment_naming_info .gateway_managed
977- else self .adapter
978- )
979- table_name = snapshot .table_name (deployability_index .is_representative (snapshot ))
980- view_name = snapshot .qualified_view_name .for_environment (
981- environment_naming_info , dialect = adapter .dialect
982- )
983- render_kwargs : t .Dict [str , t .Any ] = dict (
984- start = start ,
985- end = end ,
986- execution_time = execution_time ,
987- engine_adapter = adapter ,
988- deployability_index = deployability_index ,
989- table_mapping = table_mapping ,
990- runtime_stage = RuntimeStage .PROMOTING ,
991- )
981+ if not snapshot .is_model :
982+ return
983+
984+ adapter = (
985+ self .get_adapter (snapshot .model_gateway )
986+ if environment_naming_info .gateway_managed
987+ else self .adapter
988+ )
989+ table_name = snapshot .table_name (deployability_index .is_representative (snapshot ))
990+ view_name = snapshot .qualified_view_name .for_environment (
991+ environment_naming_info , dialect = adapter .dialect
992+ )
993+ render_kwargs : t .Dict [str , t .Any ] = dict (
994+ start = start ,
995+ end = end ,
996+ execution_time = execution_time ,
997+ engine_adapter = adapter ,
998+ deployability_index = deployability_index ,
999+ table_mapping = table_mapping ,
1000+ runtime_stage = RuntimeStage .PROMOTING ,
1001+ )
1002+
1003+ with (
1004+ adapter .transaction (),
1005+ adapter .session (snapshot .model .render_session_properties (** render_kwargs )),
1006+ ):
9921007 _evaluation_strategy (snapshot , adapter ).promote (
9931008 table_name = table_name ,
9941009 view_name = view_name ,
@@ -1007,10 +1022,15 @@ def _promote_snapshot(
10071022
10081023 def _demote_snapshot (
10091024 self ,
1010- snapshot : SnapshotInfoLike ,
1025+ snapshot : Snapshot ,
10111026 environment_naming_info : EnvironmentNamingInfo ,
1027+ deployability_index : t .Optional [DeployabilityIndex ],
10121028 on_complete : t .Optional [t .Callable [[SnapshotInfoLike ], None ]],
1029+ table_mapping : t .Optional [t .Dict [str , str ]] = None ,
10131030 ) -> None :
1031+ if not snapshot .is_model :
1032+ return
1033+
10141034 adapter = (
10151035 self .get_adapter (snapshot .model_gateway )
10161036 if environment_naming_info .gateway_managed
@@ -1019,7 +1039,18 @@ def _demote_snapshot(
10191039 view_name = snapshot .qualified_view_name .for_environment (
10201040 environment_naming_info , dialect = adapter .dialect
10211041 )
1022- _evaluation_strategy (snapshot , adapter ).demote (view_name )
1042+ with (
1043+ adapter .transaction (),
1044+ adapter .session (
1045+ snapshot .model .render_session_properties (
1046+ engine_adapter = adapter ,
1047+ deployability_index = deployability_index ,
1048+ table_mapping = table_mapping ,
1049+ runtime_stage = RuntimeStage .DEMOTING ,
1050+ )
1051+ ),
1052+ ):
1053+ _evaluation_strategy (snapshot , adapter ).demote (view_name )
10231054
10241055 if on_complete is not None :
10251056 on_complete (snapshot )
0 commit comments