Skip to content

Commit 8235611

Browse files
not expose in the public api protectprod; remove backup state tables
1 parent 85248f6 commit 8235611

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
@@ -1567,9 +1567,7 @@ def apply(
15671567
)
15681568

15691569
@python_api_analytics
1570-
def invalidate_environment(
1571-
self, name: str, sync: bool = False, protect_prod: t.Optional[bool] = True
1572-
) -> None:
1570+
def invalidate_environment(self, name: str, sync: bool = False) -> None:
15731571
"""Invalidates the target environment by setting its expiration timestamp to now.
15741572
15751573
Args:
@@ -1579,7 +1577,7 @@ def invalidate_environment(
15791577
protect_prod: If True, prevents invalidation of the production environment.
15801578
"""
15811579
name = Environment.sanitize_name(name)
1582-
self.state_sync.invalidate_environment(name, protect_prod)
1580+
self.state_sync.invalidate_environment(name)
15831581
if sync:
15841582
self._cleanup_environments()
15851583
self.console.log_success(f"Environment '{name}' deleted.")
@@ -2556,13 +2554,14 @@ def _context_diff(
25562554
def _destroy(self) -> None:
25572555
# Invalidate all environments, including prod
25582556
for environment in self.state_reader.get_environments():
2559-
self.invalidate_environment(name=environment.name, protect_prod=False)
2557+
self.state_sync.invalidate_environment(name=environment.name, protect_prod=False)
2558+
self.console.log_success(f"Environment '{environment.name}' invalidated.")
25602559

25612560
# Run janitor to clean up all objects
25622561
self._run_janitor(ignore_ttl=True)
25632562

2564-
# Remove state tables
2565-
self.state_sync.remove_state()
2563+
# Remove state tables, including backup tables
2564+
self.state_sync.remove_state(including_backup=True)
25662565
self.console.log_status_update("State tables removed.")
25672566

25682567
# 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)