|
11 | 11 | from sqlmesh import migrations |
12 | 12 | from sqlmesh.core.environment import ( |
13 | 13 | Environment, |
14 | | - EnvironmentNamingInfo, |
15 | 14 | EnvironmentStatements, |
16 | 15 | EnvironmentSummary, |
17 | 16 | ) |
|
21 | 20 | SnapshotIdLike, |
22 | 21 | SnapshotIdAndVersionLike, |
23 | 22 | SnapshotInfoLike, |
24 | | - SnapshotTableCleanupTask, |
25 | | - SnapshotTableInfo, |
26 | 23 | SnapshotNameVersion, |
27 | 24 | SnapshotIdAndVersion, |
28 | 25 | ) |
29 | 26 | from sqlmesh.core.snapshot.definition import Interval, SnapshotIntervals |
30 | 27 | from sqlmesh.utils import major_minor |
31 | 28 | from sqlmesh.utils.date import TimeLike |
32 | 29 | from sqlmesh.utils.errors import SQLMeshError |
33 | | -from sqlmesh.utils.pydantic import PydanticModel, ValidationInfo, field_validator |
34 | | -from sqlmesh.core.state_sync.common import StateStream |
| 30 | +from sqlmesh.utils.pydantic import PydanticModel, field_validator |
| 31 | +from sqlmesh.core.state_sync.common import ( |
| 32 | + StateStream, |
| 33 | + ExpiredSnapshotBatch, |
| 34 | + PromotionResult, |
| 35 | + ExpiredBatchRange, |
| 36 | +) |
35 | 37 |
|
36 | 38 | logger = logging.getLogger(__name__) |
37 | 39 |
|
@@ -72,20 +74,6 @@ def _schema_version_validator(cls, v: t.Any) -> int: |
72 | 74 | SCHEMA_VERSION: int = MIN_SCHEMA_VERSION + len(MIGRATIONS) - 1 |
73 | 75 |
|
74 | 76 |
|
75 | | -class PromotionResult(PydanticModel): |
76 | | - added: t.List[SnapshotTableInfo] |
77 | | - removed: t.List[SnapshotTableInfo] |
78 | | - removed_environment_naming_info: t.Optional[EnvironmentNamingInfo] |
79 | | - |
80 | | - @field_validator("removed_environment_naming_info") |
81 | | - def _validate_removed_environment_naming_info( |
82 | | - cls, v: t.Optional[EnvironmentNamingInfo], info: ValidationInfo |
83 | | - ) -> t.Optional[EnvironmentNamingInfo]: |
84 | | - if v and not info.data.get("removed"): |
85 | | - raise ValueError("removed_environment_naming_info must be None if removed is empty") |
86 | | - return v |
87 | | - |
88 | | - |
89 | 77 | class StateReader(abc.ABC): |
90 | 78 | """Abstract base class for read-only operations on snapshot and environment state.""" |
91 | 79 |
|
@@ -315,15 +303,21 @@ def export(self, environment_names: t.Optional[t.List[str]] = None) -> StateStre |
315 | 303 |
|
316 | 304 | @abc.abstractmethod |
317 | 305 | def get_expired_snapshots( |
318 | | - self, current_ts: t.Optional[int] = None, ignore_ttl: bool = False |
319 | | - ) -> t.List[SnapshotTableCleanupTask]: |
320 | | - """Aggregates the id's of the expired snapshots and creates a list of table cleanup tasks. |
| 306 | + self, |
| 307 | + *, |
| 308 | + batch_range: ExpiredBatchRange, |
| 309 | + current_ts: t.Optional[int] = None, |
| 310 | + ignore_ttl: bool = False, |
| 311 | + ) -> t.Optional[ExpiredSnapshotBatch]: |
| 312 | + """Returns a single batch of expired snapshots ordered by (updated_ts, name, identifier). |
321 | 313 |
|
322 | | - Expired snapshots are snapshots that have exceeded their time-to-live |
323 | | - and are no longer in use within an environment. |
| 314 | + Args: |
| 315 | + current_ts: Timestamp used to evaluate expiration. |
| 316 | + ignore_ttl: If True, include snapshots regardless of TTL (only checks if unreferenced). |
| 317 | + batch_range: The range of the batch to fetch. |
324 | 318 |
|
325 | 319 | Returns: |
326 | | - The list of table cleanup tasks. |
| 320 | + A batch describing expired snapshots or None if no snapshots are pending cleanup. |
327 | 321 | """ |
328 | 322 |
|
329 | 323 | @abc.abstractmethod |
@@ -363,16 +357,21 @@ def delete_snapshots(self, snapshot_ids: t.Iterable[SnapshotIdLike]) -> None: |
363 | 357 |
|
364 | 358 | @abc.abstractmethod |
365 | 359 | def delete_expired_snapshots( |
366 | | - self, ignore_ttl: bool = False, current_ts: t.Optional[int] = None |
| 360 | + self, |
| 361 | + batch_range: ExpiredBatchRange, |
| 362 | + ignore_ttl: bool = False, |
| 363 | + current_ts: t.Optional[int] = None, |
367 | 364 | ) -> None: |
368 | 365 | """Removes expired snapshots. |
369 | 366 |
|
370 | 367 | Expired snapshots are snapshots that have exceeded their time-to-live |
371 | 368 | and are no longer in use within an environment. |
372 | 369 |
|
373 | 370 | Args: |
| 371 | + batch_range: The range of snapshots to delete in this batch. |
374 | 372 | ignore_ttl: Ignore the TTL on the snapshot when considering it expired. This has the effect of deleting |
375 | 373 | all snapshots that are not referenced in any environment |
| 374 | + current_ts: Timestamp used to evaluate expiration. |
376 | 375 | """ |
377 | 376 |
|
378 | 377 | @abc.abstractmethod |
|
0 commit comments