Skip to content

feat: delegate constraint naming to Databricks - #350

Draft
Tomoscorbin wants to merge 4 commits into
mainfrom
feature/platform-assigned-constraint-names
Draft

feat: delegate constraint naming to Databricks#350
Tomoscorbin wants to merge 4 commits into
mainfrom
feature/platform-assigned-constraint-names

Conversation

@Tomoscorbin

@Tomoscorbin Tomoscorbin commented Aug 11, 2026

Copy link
Copy Markdown
Owner

Summary

  • stop synthesizing primary- and foreign-key constraint names when users omit them
  • let Databricks allocate physical names in both CREATE TABLE and ALTER TABLE ... ADD SQL
  • treat an explicit name as a creation preference, not ongoing managed state
  • match existing constraints by structural definition with ordinary equality
  • model catalog-observed constraints separately so their physical names are always available for drops
  • update tests and documentation around the final behavior

Behavior

Constraint names now have one narrow meaning:

  • no name: Databricks chooses the physical name when creating the constraint
  • explicit name: request that physical name when creating the constraint

Once a constraint exists, its name belongs to the catalog. A desired constraint is satisfied by an observed constraint with the same definition, regardless of either name. Changing only primary_key_name or ForeignKey(name=...) is therefore a no-op.

Structural drift still produces a drop and an add. The drop uses the concrete observed name; the add preserves the user's optional creation preference. Existing tables using the old engine-generated naming convention converge without DDL churn.

An explicit name collision during creation remains a Databricks execution error because constraint names share a schema-wide namespace.

Design

  • PrimaryKeyConstraint and ForeignKeyConstraint represent desired declarations and carry an optional name
  • ObservedPrimaryKeyConstraint and ObservedForeignKeyConstraint require the catalog name, making unnamed observed state unrepresentable
  • constraint equality and hashing use only the relational definition
  • primary-key reconciliation is a direct desired_key == observed_key comparison
  • foreign-key reconciliation pairs structural matches one-to-one, then drops unmatched observations before adding unmatched declarations
  • optional-name branching is confined to declaration validation, desired-model construction, reporting, and SQL rendering
  • drop actions carry only the physical name required by Databricks

Validation

  • uv run pytest -q: 1,244 passed, 79 deselected; 97.21% coverage
  • uv run mypy src: passed
  • uv run ruff check .: passed
  • uv run ruff format --check .: passed
  • uv run lint-imports: 7 contracts kept
  • uv run --group docs sphinx-build -W -b html docs docs/_build/html: passed
  • standalone MyST plan render: passed
  • live suite collection: 79 tests collected successfully; credentialed tests not executed locally
  • git diff --check: passed

@Tomoscorbin Tomoscorbin changed the title refactor: model platform-assigned constraint names feat: delegate constraint naming to Databricks Aug 11, 2026
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