Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UNIQUE constraints not reflecting #234

Open
wpfl-dbt opened this issue Dec 18, 2024 · 0 comments
Open

UNIQUE constraints not reflecting #234

wpfl-dbt opened this issue Dec 18, 2024 · 0 comments

Comments

@wpfl-dbt
Copy link
Contributor

Currently, live tables are reflected, then checked column by column for identity based on several pieces of data, including Column.unique.

columns_target = tuple(
(col.name, repr(col.type), col.nullable, col.primary_key, col.unique) for col in target_table.columns.values()
)
columns_live = tuple(
(col.name, repr(col.type), col.nullable, col.primary_key, col.unique) for col in live_table.columns.values()
)
must_create_ingest_table = indexes_target_repr != indexes_live_repr or columns_target != columns_live

The problem is that reflected tables store the unique constraint under Table.constraints, not in the Table.column Column objects. When reflecting a table, Column.unique will always be None.

This means that this ingested table definition will trigger a swap:

sa.Table(
    "foo",
    sa.Column("bar", sa.VARCHAR(10), unique=True),
)

But this won't:

sa.Table(
    "foo",
    sa.Column("bar", sa.VARCHAR(10)),
    sa.UniqueConstraint("bar"),
)

Even though they're functionally identical.

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

No branches or pull requests

1 participant