Skip to content

Commit 4e0ed5c

Browse files
committed
Fix: Exempt seed models from migration
1 parent df7d61b commit 4e0ed5c

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
@@ -1672,6 +1672,42 @@ def test_run_with_select_models(
16721672
}
16731673

16741674

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

0 commit comments

Comments
 (0)