Skip to content

Commit 8f1bbcd

Browse files
fix(plan): only follow views that are migrated
An upstream view that is not paused stays in place, so its child views do not need to be recreated. Signed-off-by: ReguiguiMohamed <mohamedreguigui2004@gmail.com>
1 parent c3f4ee8 commit 8f1bbcd

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

‎sqlmesh/core/plan/stages.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,9 @@ def build(self, plan: EvaluatablePlan) -> t.List[PlanStage]:
285285
for s_id in dag:
286286
snapshot = snapshots[s_id]
287287
if snapshot.is_view and any(
288-
p_id in snapshot_ids_to_migrate and snapshots[p_id].is_view
288+
p_id in snapshot_ids_to_migrate
289+
and snapshots[p_id].is_view
290+
and snapshots[p_id].supports_schema_migration_in_prod
289291
for p_id in snapshot.parents
290292
):
291293
snapshot_ids_to_migrate.add(s_id)

‎tests/core/test_plan_stages.py‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1688,14 +1688,17 @@ def test_build_plan_stages_indirect_non_breaking_view_migration(
16881688
assert isinstance(stages[8], FinalizeEnvironmentStage)
16891689

16901690

1691+
@pytest.mark.parametrize("base_view_unpaused", [False, True])
16911692
def test_build_plan_stages_migrates_views_downstream_of_migrated_view(
1692-
snapshot_a: Snapshot, make_snapshot, mocker: MockerFixture
1693+
snapshot_a: Snapshot, make_snapshot, mocker: MockerFixture, base_view_unpaused: bool
16931694
) -> None:
16941695
base_view = make_snapshot(
16951696
SqlModel(name="base_view", query=parse_one("select * from a"), kind=ModelKindName.VIEW),
16961697
nodes={'"a"': snapshot_a.model},
16971698
)
16981699
base_view.categorize_as(SnapshotChangeCategory.BREAKING)
1700+
if base_view_unpaused:
1701+
base_view.unpaused_ts = 1
16991702
public_view = make_snapshot(
17001703
SqlModel(
17011704
name="public_view", query=parse_one("select * from base_view"), kind=ModelKindName.VIEW
@@ -1760,7 +1763,8 @@ def test_build_plan_stages_migrates_views_downstream_of_migrated_view(
17601763
stages = build_plan_stages(plan, state_reader, None)
17611764

17621765
migrate_stage = next(s for s in stages if isinstance(s, MigrateSchemasStage))
1763-
assert {s.snapshot_id for s in migrate_stage.snapshots} == {s.snapshot_id for s in snapshots}
1766+
expected = [snapshot_a, forward_only] if base_view_unpaused else snapshots
1767+
assert {s.snapshot_id for s in migrate_stage.snapshots} == {s.snapshot_id for s in expected}
17641768

17651769

17661770
def test_build_plan_stages_virtual_environment_mode_filtering(

0 commit comments

Comments
 (0)