Skip to content

refactor: model desired and observed constraints - #355

Open
Tomoscorbin wants to merge 2 commits into
feature/constraint-lifecycle-redesign-planfrom
feature/model-constraint-lifecycle
Open

refactor: model desired and observed constraints#355
Tomoscorbin wants to merge 2 commits into
feature/constraint-lifecycle-redesign-planfrom
feature/model-constraint-lifecycle

Conversation

@Tomoscorbin

@Tomoscorbin Tomoscorbin commented Aug 13, 2026

Copy link
Copy Markdown
Owner

Summary

  • split key constraints into Desired* declarations and Observed* catalog occurrences
  • use lifecycle-specific desired_name and catalog_name fields
  • define primary- and foreign-key equality and hashing by relational definition across lifecycle variants
  • share normalization and identity through private functions instead of additional constraint-shaped base classes
  • make desired and observed tables reject constraint values from the wrong lifecycle
  • make the information-schema reader the sole production constructor of observed constraints
  • reconcile primary keys with direct equality and foreign keys with a deterministic set-based one-to-one match

Why

Constraint names have different meanings before and after creation. A desired name is a creation preference; an observed name is a physical catalog handle. Treating either as relational identity creates false drift and replacement work.

This PR makes desired_key == observed_key express the reconciliation question directly. The four lifecycle values are the complete constraint vocabulary; private functions hide their shared mechanics without introducing another constraint-like entity.

Behavior and compatibility

This intentionally changes name-only drift: a matching catalog definition is adopted regardless of its catalog name. Structural differences still produce drop-and-set actions.

Public declarations still generate the existing default desired names, and newly created constraint SQL remains named exactly as before. Optional names, Databricks-assigned naming, and the Set* to Add* action redesign remain in later PRs.

This is PR 1 of the constraint-lifecycle redesign and is stacked on feature/constraint-lifecycle-redesign-plan.

Validation

  • uv run pytest -q — 1,258 passed, 78 deselected; 97.14% coverage
  • uv run mypy src
  • uv run ruff check .
  • uv run ruff format --check .
  • uv run lint-imports
  • uv run --group docs sphinx-build -W -b html docs /tmp/delta-engine-pr355-docs
  • git diff --check

Comment thread src/delta_engine/adapters/databricks/sql/compile.py Outdated
Comment thread src/delta_engine/domain/model/constraints.py Outdated
Comment thread src/delta_engine/domain/plan/diff.py Outdated
@Tomoscorbin
Tomoscorbin marked this pull request as ready for review August 14, 2026 09:54
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