@@ -1688,6 +1688,85 @@ 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 ])
1692+ def test_build_plan_stages_migrates_views_downstream_of_migrated_view (
1693+ snapshot_a : Snapshot , make_snapshot , mocker : MockerFixture , base_view_unpaused : bool
1694+ ) -> None :
1695+ base_view = make_snapshot (
1696+ SqlModel (name = "base_view" , query = parse_one ("select * from a" ), kind = ModelKindName .VIEW ),
1697+ nodes = {'"a"' : snapshot_a .model },
1698+ )
1699+ base_view .categorize_as (SnapshotChangeCategory .BREAKING )
1700+ if base_view_unpaused :
1701+ base_view .unpaused_ts = 1
1702+ public_view = make_snapshot (
1703+ SqlModel (
1704+ name = "public_view" , query = parse_one ("select * from base_view" ), kind = ModelKindName .VIEW
1705+ ),
1706+ nodes = {'"a"' : snapshot_a .model , '"base_view"' : base_view .model },
1707+ )
1708+ public_view .categorize_as (SnapshotChangeCategory .BREAKING )
1709+ forward_only = make_snapshot (
1710+ SqlModel (
1711+ name = "forward_only" ,
1712+ query = parse_one ("select 1, ds from base_view" ),
1713+ kind = dict (
1714+ name = ModelKindName .INCREMENTAL_BY_TIME_RANGE , time_column = "ds" , forward_only = True
1715+ ),
1716+ ),
1717+ nodes = {'"a"' : snapshot_a .model , '"base_view"' : base_view .model },
1718+ )
1719+ forward_only .categorize_as (SnapshotChangeCategory .BREAKING )
1720+ snapshots = [snapshot_a , base_view , public_view , forward_only ]
1721+
1722+ state_reader = mocker .Mock (spec = StateReader )
1723+ state_reader .get_snapshots .return_value = {}
1724+ state_reader .get_environment .return_value = None
1725+
1726+ environment = Environment (
1727+ snapshots = [s .table_info for s in snapshots ],
1728+ start_at = "2023-01-01" ,
1729+ end_at = "2023-01-02" ,
1730+ plan_id = "test_plan" ,
1731+ previous_plan_id = None ,
1732+ promoted_snapshot_ids = [s .snapshot_id for s in snapshots ],
1733+ )
1734+ plan = EvaluatablePlan (
1735+ start = "2023-01-01" ,
1736+ end = "2023-01-02" ,
1737+ new_snapshots = snapshots ,
1738+ environment = environment ,
1739+ no_gaps = False ,
1740+ skip_backfill = False ,
1741+ empty_backfill = False ,
1742+ restatements = {},
1743+ restate_all_snapshots = False ,
1744+ is_dev = False ,
1745+ allow_destructive_models = set (),
1746+ allow_additive_models = set (),
1747+ forward_only = False ,
1748+ end_bounded = False ,
1749+ ensure_finalized_snapshots = False ,
1750+ ignore_cron = False ,
1751+ directly_modified_snapshots = [s .snapshot_id for s in snapshots ],
1752+ indirectly_modified_snapshots = {},
1753+ metadata_updated_snapshots = [],
1754+ removed_snapshots = [],
1755+ requires_backfill = True ,
1756+ models_to_backfill = None ,
1757+ execution_time = "2023-01-02" ,
1758+ disabled_restatement_models = set (),
1759+ environment_statements = None ,
1760+ user_provided_flags = None ,
1761+ )
1762+
1763+ stages = build_plan_stages (plan , state_reader , None )
1764+
1765+ migrate_stage = next (s for s in stages if isinstance (s , MigrateSchemasStage ))
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 }
1768+
1769+
16911770def test_build_plan_stages_virtual_environment_mode_filtering (
16921771 make_snapshot , mocker : MockerFixture
16931772) -> None :
0 commit comments