Skip to content

Preserve dialect-variant type-bound constraints when copying tables - #57

Open
nicoloesch wants to merge 5 commits into
mainfrom
56-variant-constraint-copy
Open

nicoloesch wants to merge 5 commits into
mainfrom
56-variant-constraint-copy

Conversation

@nicoloesch

Copy link
Copy Markdown
Collaborator

Summary

Fixes #56

without_cross_engine_foreign_keys() silently dropped a with_variant() column's CHECK constraint when copying a table whose FK crosses a boundary it strips (another database, or another physical schema on a dialect that cannot express cross-schema keys).

  • Table.to_metadata() regenerates each column's type, dropping with_variant() overrides, and skips re-copying type-bound constraints, expecting the regenerated type to recreate them, which it cannot once the variant is gone.
  • Restore each copied column's original type object after to_metadata(), and re-copy any type-bound constraint it skipped.

Checklist

  • Applied exactly one label (fix)
  • Tests pass locally (uv run pytest -q): 584 passed
  • Tests pass locally (uv run pytest -q -m postgresql): 109 passed
  • Lint passes (uv run ruff check .)

Table.to_metadata() regenerates each column's type via Column._copy(),
which drops with_variant() dialect overrides, and separately skips
type-bound constraints (e.g. Enum's create_constraint CHECK) outright,
expecting that regenerated type to recreate them on attach. A
variant-wrapped type's generic impl has no constraint to generate, so
without_cross_engine_foreign_keys() silently dropped CHECK constraints
for any copied table using with_variant() -- surfaced by omop-graph's
DuckDB-variant PredicateKind enum crossing a schema boundary.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@nicoloesch nicoloesch added the fix Bug fix, backwards-compatible. PATCH: x.y.z+1 label Nov 7, 2026
@nicoloesch
nicoloesch requested a review from gkennos November 8, 2026 14:43
@nicoloesch
nicoloesch requested a review from gkennos November 18, 2026 03:39

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix Bug fix, backwards-compatible. PATCH: x.y.z+1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

without_cross_engine_foreign_keys() drops a with_variant() column's CHECK constraint

2 participants