Skip to content

feat: validate planned constraint name collisions - #360

Closed
Tomoscorbin wants to merge 1 commit into
feature/constraint-lifecycle-redesign-planfrom
feature/validate-constraint-name-collisions
Closed

feat: validate planned constraint name collisions#360
Tomoscorbin wants to merge 1 commit into
feature/constraint-lifecycle-redesign-planfrom
feature/validate-constraint-name-collisions

Conversation

@Tomoscorbin

Copy link
Copy Markdown
Owner

Summary

  • represent missing-table primary keys with AddPrimaryKey, giving every planned constraint creation one action form
  • validate explicit PK and FK creation names across the complete accepted plan set
  • reject case-insensitive collisions within one catalog and schema before execution
  • preserve normal dry-run reporting and dependency blocking
  • document the plan-set validation boundary and the remaining limitation for unseen external constraints

Why

Databricks uses one case-insensitive constraint-name namespace per schema across tables and constraint kinds. Per-table validation cannot detect two individually valid plans that request the same name. Without a plan-set check, one addition could succeed before a later addition failed, leaving a partially applied sync.

The previous missing-table path also embedded a primary key inside CreateTable, forcing global validation to treat new-table primary keys as a special case. Normalizing them to AddPrimaryKey keeps constraint creation uniform.

User impact

A dry run now reports planned explicit-name collisions as ConstraintNameMustBeUniqueInSchema failures. Real runs reject every affected table before executing any of its statements. Independent tables may still execute, and foreign-key dependents are blocked through the existing dependency mechanism.

Unnamed constraints and already-satisfied declarations do not participate. Collisions with unseen or externally managed catalog constraints remain Databricks execution failures.

Validation

  • uv run pytest -q — 1,284 passed, 78 deselected, 97.15% coverage
  • uv run ruff check .
  • uv run ruff format --check .
  • uv run mypy .
  • uv run lint-imports
  • uv run --group docs sphinx-build -W -b html docs /tmp/delta-engine-pr5-docs

Copy link
Copy Markdown
Owner Author

Superseded by #361. We decided not to add a sync-wide collision-preflight boundary: Databricks owns the authoritative schema namespace, a local check would remain incomplete, and explicit naming is optional. #361 documents the execution-time and partial-sync limitation instead.

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.

1 participant