5959from sqlmesh .core .state_sync .db .environment import EnvironmentState
6060from sqlmesh .core .state_sync .db .snapshot import SnapshotState
6161from sqlmesh .core .state_sync .db .version import VersionState
62- from sqlmesh .core .state_sync .db .migrator import StateMigrator
62+ from sqlmesh .core .state_sync .db .migrator import StateMigrator , _backup_table_name
6363from sqlmesh .utils .date import TimeLike , to_timestamp , time_like_to_str , now_timestamp
6464from sqlmesh .utils .errors import ConflictingPlanError , SQLMeshError
6565
@@ -270,7 +270,7 @@ def unpause_snapshots(
270270 ) -> None :
271271 self .snapshot_state .unpause_snapshots (snapshots , unpaused_dt , self .interval_state )
272272
273- def invalidate_environment (self , name : str , protect_prod : t . Optional [ bool ] = True ) -> None :
273+ def invalidate_environment (self , name : str , protect_prod : bool = True ) -> None :
274274 self .environment_state .invalidate_environment (name , protect_prod )
275275
276276 def get_expired_snapshots (
@@ -313,7 +313,7 @@ def snapshots_exist(self, snapshot_ids: t.Iterable[SnapshotIdLike]) -> t.Set[Sna
313313 def nodes_exist (self , names : t .Iterable [str ], exclude_external : bool = False ) -> t .Set [str ]:
314314 return self .snapshot_state .nodes_exist (names , exclude_external )
315315
316- def remove_state (self ) -> None :
316+ def remove_state (self , including_backup : bool = False ) -> None :
317317 """Removes the state store objects."""
318318 for table in (
319319 self .snapshot_state .snapshots_table ,
@@ -325,6 +325,9 @@ def remove_state(self) -> None:
325325 self .version_state .versions_table ,
326326 ):
327327 self .engine_adapter .drop_table (table )
328+ if including_backup :
329+ self .engine_adapter .drop_table (_backup_table_name (table ))
330+
328331 self .snapshot_state .clear_cache ()
329332
330333 def reset (self , default_catalog : t .Optional [str ]) -> None :
0 commit comments