Skip to content

Commit

Permalink
Fix Duplicate table constraints (#19502)
Browse files Browse the repository at this point in the history
  • Loading branch information
SumanMaharana authored Jan 24, 2025
1 parent 1e7377c commit 94ed7e3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ def _get_foreign_constraints(
foreign_constraint = self._prepare_foreign_constraints(
supports_database, column, table_name, schema_name, db_name, columns
)
if foreign_constraint:
if foreign_constraint and foreign_constraint not in foreign_constraints:
foreign_constraints.append(foreign_constraint)

return foreign_constraints
Expand All @@ -707,7 +707,11 @@ def update_table_constraints(
)
if foreign_table_constraints:
if table_constraints:
table_constraints.extend(foreign_table_constraints)
table_constraints.extend(
constraint
for constraint in foreign_table_constraints
if constraint not in table_constraints
)
else:
table_constraints = foreign_table_constraints
return table_constraints
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,12 +226,16 @@ def get_columns_and_constraints( # pylint: disable=too-many-locals
if len(col) == 1:
column_level_unique_constraints.add(col[0])
else:
table_constraints.append(
TableConstraint(
constraintType=ConstraintType.UNIQUE,
columns=col,
if not any(
tc.constraintType == ConstraintType.UNIQUE and tc.columns == col
for tc in table_constraints
):
table_constraints.append(
TableConstraint(
constraintType=ConstraintType.UNIQUE,
columns=col,
)
)
)
if len(pk_columns) > 1:
table_constraints.append(
TableConstraint(
Expand Down

0 comments on commit 94ed7e3

Please sign in to comment.