Skip to content

Fix: Surface destructive schema changes on forward-only models during dev plans (#5719)#5732

Open
brucearctor wants to merge 2 commits intoSQLMesh:mainfrom
brucearctor:fix/destructive-schema-change-dev-plan
Open

Fix: Surface destructive schema changes on forward-only models during dev plans (#5719)#5732
brucearctor wants to merge 2 commits intoSQLMesh:mainfrom
brucearctor:fix/destructive-schema-change-dev-plan

Conversation

@brucearctor
Copy link

Summary

Fixes #5719. Destructive schema changes on forward-only models are now surfaced at plan-build time during dev plans (sqlmesh plan dev), not just prod plans.

Problem

When a forward-only model has columns removed or types narrowed, sqlmesh plan dev and PR checks would succeed, but the production deployment would fail with a DestructiveChangeError during MigrateSchemasStage. This left the production environment in an unfinalized state.

Root Cause

PlanBuilder._check_destructive_additive_changes already checked for destructive schema changes at plan-build time (regardless of is_dev), but only for directly modified snapshots. Indirectly modified forward-only models (e.g., downstream models inheriting schema changes from an upstream dependency) were not checked. The evaluator-level check in MigrateSchemasStage catches these for prod, but that stage is skipped for dev plans.

Changes

sqlmesh/core/plan/builder.py

  • Extract schema diffing into reusable _check_schema_change helper method
  • Pass indirectly_modified mapping to _check_destructive_additive_changes
  • Add a second loop to check indirectly modified forward-only snapshots for destructive/additive schema changes

tests/core/test_plan.py

Add 5 new tests for is_dev=True scenarios:

  • test_forward_only_destructive_change_dev_plan — ERROR mode raises PlanError
  • test_forward_only_destructive_change_dev_plan_warn — WARN mode logs warning
  • test_forward_only_destructive_change_dev_plan_allow — ALLOW mode passes silently
  • test_forward_only_indirect_destructive_change_dev_plan — indirect modification path exercised
  • test_forward_only_flag_destructive_change_dev_plan--forward-only flag with dev plan

Test Results

All 27 forward-only/destructive tests pass (5 new + 22 existing), zero regressions.

… dev plans (SQLMesh#5719)

Extend _check_destructive_additive_changes in PlanBuilder to also inspect
indirectly modified forward-only snapshots for destructive/additive schema
changes. Previously, only directly modified snapshots were checked, and the
evaluator-level check (MigrateSchemasStage) is skipped for dev plans.

Changes:
- Refactor schema diffing into reusable _check_schema_change helper
- Pass indirectly_modified mapping to _check_destructive_additive_changes
- Add loop to check indirectly modified forward-only snapshots
- Add 5 new tests for is_dev=True scenarios (ERROR/WARN/ALLOW modes,
  indirect modification, --forward-only flag)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Destructive schema changes on forward-only models not surfaced until prod deploy

1 participant