Skip to content

Commit a8b0076

Browse files
not expose in the public api protectprod; remove backup state tables
1 parent 94a66db commit a8b0076

5 files changed

Lines changed: 16 additions & 14 deletions

File tree

sqlmesh/core/context.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1529,9 +1529,7 @@ def apply(
15291529
)
15301530

15311531
@python_api_analytics
1532-
def invalidate_environment(
1533-
self, name: str, sync: bool = False, protect_prod: t.Optional[bool] = True
1534-
) -> None:
1532+
def invalidate_environment(self, name: str, sync: bool = False) -> None:
15351533
"""Invalidates the target environment by setting its expiration timestamp to now.
15361534
15371535
Args:
@@ -1541,7 +1539,7 @@ def invalidate_environment(
15411539
protect_prod: If True, prevents invalidation of the production environment.
15421540
"""
15431541
name = Environment.sanitize_name(name)
1544-
self.state_sync.invalidate_environment(name, protect_prod)
1542+
self.state_sync.invalidate_environment(name)
15451543
if sync:
15461544
self._cleanup_environments()
15471545
self.console.log_success(f"Environment '{name}' deleted.")
@@ -2518,13 +2516,14 @@ def _context_diff(
25182516
def _destroy(self) -> None:
25192517
# Invalidate all environments, including prod
25202518
for environment in self.state_reader.get_environments():
2521-
self.invalidate_environment(name=environment.name, protect_prod=False)
2519+
self.state_sync.invalidate_environment(name=environment.name, protect_prod=False)
2520+
self.console.log_success(f"Environment '{environment.name}' invalidated.")
25222521

25232522
# Run janitor to clean up all objects
25242523
self._run_janitor(ignore_ttl=True)
25252524

2526-
# Remove state tables
2527-
self.state_sync.remove_state()
2525+
# Remove state tables, including backup tables
2526+
self.state_sync.remove_state(including_backup=True)
25282527
self.console.log_status_update("State tables removed.")
25292528

25302529
# Finally clear caches

sqlmesh/core/state_sync/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ def delete_expired_snapshots(
347347
"""
348348

349349
@abc.abstractmethod
350-
def invalidate_environment(self, name: str, protect_prod: t.Optional[bool] = True) -> None:
350+
def invalidate_environment(self, name: str, protect_prod: bool = True) -> None:
351351
"""Invalidates the target environment by setting its expiration timestamp to now.
352352
353353
Args:
@@ -356,7 +356,7 @@ def invalidate_environment(self, name: str, protect_prod: t.Optional[bool] = Tru
356356
"""
357357

358358
@abc.abstractmethod
359-
def remove_state(self) -> None:
359+
def remove_state(self, including_backup: bool = False) -> None:
360360
"""Removes the state store objects."""
361361

362362
@abc.abstractmethod

sqlmesh/core/state_sync/db/environment.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def update_environment_statements(
108108
columns_to_types=self._environment_statements_columns_to_types,
109109
)
110110

111-
def invalidate_environment(self, name: str, protect_prod: t.Optional[bool] = True) -> None:
111+
def invalidate_environment(self, name: str, protect_prod: bool = True) -> None:
112112
"""Invalidates the environment.
113113
114114
Args:

sqlmesh/core/state_sync/db/facade.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
from sqlmesh.core.state_sync.db.environment import EnvironmentState
6060
from sqlmesh.core.state_sync.db.snapshot import SnapshotState
6161
from 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
6363
from sqlmesh.utils.date import TimeLike, to_timestamp, time_like_to_str, now_timestamp
6464
from 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:

tests/integrations/github/cicd/test_github_controller.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ def test_try_invalidate_pr_environment(github_client, make_controller, mocker: M
437437
invalidate_controller._context._state_sync = mocker.MagicMock()
438438
invalidate_controller.try_invalidate_pr_environment()
439439
invalidate_controller._context._state_sync.invalidate_environment.assert_called_once_with(
440-
"hello_world_2", True
440+
"hello_world_2"
441441
)
442442

443443
no_invalidate_controller = make_controller(

0 commit comments

Comments
 (0)