Skip to content

Commit af3a16f

Browse files
izeigermanCopilot
andauthored
Fix: Exempt seed models from migration (#5413)
Co-authored-by: Copilot <[email protected]>
1 parent 2d13c2f commit af3a16f

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

sqlmesh/core/snapshot/definition.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1480,7 +1480,7 @@ def expiration_ts(self) -> int:
14801480
@property
14811481
def supports_schema_migration_in_prod(self) -> bool:
14821482
"""Returns whether or not this snapshot supports schema migration when deployed to production."""
1483-
return self.is_paused and self.is_model and not self.is_symbolic
1483+
return self.is_paused and self.is_model and not self.is_symbolic and not self.is_seed
14841484

14851485
@property
14861486
def requires_schema_migration_in_prod(self) -> bool:

tests/core/test_integration.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1678,6 +1678,42 @@ def test_run_with_select_models(
16781678
}
16791679

16801680

1681+
@time_machine.travel("2023-01-08 15:00:00 UTC")
1682+
def test_seed_model_promote_to_prod_after_dev(
1683+
init_and_plan_context: t.Callable,
1684+
):
1685+
context, plan = init_and_plan_context("examples/sushi")
1686+
context.apply(plan)
1687+
1688+
with open(context.path / "seeds" / "waiter_names.csv", "a") as f:
1689+
f.write("\n10,New Waiter")
1690+
1691+
context.load()
1692+
1693+
waiter_names_snapshot = context.get_snapshot("sushi.waiter_names")
1694+
plan = context.plan("dev", skip_tests=True, auto_apply=True, no_prompts=True)
1695+
assert waiter_names_snapshot.snapshot_id in plan.directly_modified
1696+
1697+
# Trigger a metadata change to reuse the previous version
1698+
waiter_names_model = waiter_names_snapshot.model.copy(
1699+
update={"description": "Updated description"}
1700+
)
1701+
context.upsert_model(waiter_names_model)
1702+
context.plan("dev", skip_tests=True, auto_apply=True, no_prompts=True)
1703+
1704+
# Promote all changes to prod
1705+
waiter_names_snapshot = context.get_snapshot("sushi.waiter_names")
1706+
plan = context.plan_builder("prod", skip_tests=True).build()
1707+
# Clear the cache to source the dehydrated model instance from the state
1708+
context.clear_caches()
1709+
context.apply(plan)
1710+
1711+
assert (
1712+
context.engine_adapter.fetchone("SELECT COUNT(*) FROM sushi.waiter_names WHERE id = 10")[0]
1713+
== 1
1714+
)
1715+
1716+
16811717
@time_machine.travel("2023-01-08 15:00:00 UTC")
16821718
def test_plan_with_run(
16831719
init_and_plan_context: t.Callable,

0 commit comments

Comments
 (0)