|
23 | 23 | ) |
24 | 24 | from sqlmesh.core.node import IntervalUnit |
25 | 25 | from sqlmesh.core.snapshot import Snapshot, SnapshotChangeCategory, SnapshotEvaluator |
| 26 | +from sqlmesh.utils.date import to_timestamp |
26 | 27 | from sqlmesh.utils.errors import ConfigError, SQLMeshError |
27 | 28 | from sqlmesh.utils.metaprogramming import Executable |
28 | 29 |
|
@@ -192,6 +193,48 @@ def test_promote(mocker: MockerFixture, adapter_mock, make_snapshot): |
192 | 193 | ) |
193 | 194 |
|
194 | 195 |
|
| 196 | +def test_promote_forward_only(mocker: MockerFixture, adapter_mock, make_snapshot): |
| 197 | + evaluator = SnapshotEvaluator(adapter_mock) |
| 198 | + |
| 199 | + model = SqlModel( |
| 200 | + name="test_schema.test_model", |
| 201 | + kind=IncrementalByTimeRangeKind(time_column="a"), |
| 202 | + query=parse_one("SELECT a FROM tbl WHERE ds BETWEEN @start_ds and @end_ds"), |
| 203 | + ) |
| 204 | + |
| 205 | + snapshot = make_snapshot(model) |
| 206 | + snapshot.categorize_as(SnapshotChangeCategory.FORWARD_ONLY) |
| 207 | + snapshot.version = "test_version" |
| 208 | + |
| 209 | + evaluator.promote([snapshot], EnvironmentNamingInfo(name="test_env"), is_dev=True) |
| 210 | + |
| 211 | + snapshot.unpaused_ts = to_timestamp("2023-01-01") |
| 212 | + evaluator.promote([snapshot], EnvironmentNamingInfo(name="test_env"), is_dev=True) |
| 213 | + |
| 214 | + adapter_mock.create_schema.assert_has_calls( |
| 215 | + [ |
| 216 | + call("test_schema__test_env", catalog_name=None), |
| 217 | + call("test_schema__test_env", catalog_name=None), |
| 218 | + ] |
| 219 | + ) |
| 220 | + adapter_mock.create_view.assert_has_calls( |
| 221 | + [ |
| 222 | + call( |
| 223 | + "test_schema__test_env.test_model", |
| 224 | + parse_one( |
| 225 | + f"SELECT * FROM sqlmesh__test_schema.test_schema__test_model__{snapshot.fingerprint.to_version()}__temp" |
| 226 | + ), |
| 227 | + ), |
| 228 | + call( |
| 229 | + "test_schema__test_env.test_model", |
| 230 | + parse_one( |
| 231 | + "SELECT * FROM sqlmesh__test_schema.test_schema__test_model__test_version" |
| 232 | + ), |
| 233 | + ), |
| 234 | + ] |
| 235 | + ) |
| 236 | + |
| 237 | + |
195 | 238 | def test_cleanup(mocker: MockerFixture, adapter_mock, make_snapshot): |
196 | 239 | evaluator = SnapshotEvaluator(adapter_mock) |
197 | 240 |
|
|
0 commit comments