Skip to content

Commit

Permalink
reorder fk constraint rendering preference
Browse files Browse the repository at this point in the history
  • Loading branch information
MichelleArk committed Jul 25, 2024
1 parent 0220d1e commit 5b27d24
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions dbt/adapters/base/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -1603,12 +1603,12 @@ def render_column_constraint(cls, constraint: ColumnLevelConstraint) -> Optional
elif constraint.type == ConstraintType.primary_key:
rendered_column_constraint = f"primary key {constraint_expression}"
elif constraint.type == ConstraintType.foreign_key:
if constraint_expression:
rendered_column_constraint = f"references {constraint_expression}"
elif constraint.to and constraint.to_columns:
if constraint.to and constraint.to_columns:
rendered_column_constraint = (
f"references {constraint.to} ({', '.join(constraint.to_columns)})"
)
elif constraint_expression:
rendered_column_constraint = f"references {constraint_expression}"
elif constraint.type == ConstraintType.custom and constraint_expression:
rendered_column_constraint = constraint_expression

Expand Down Expand Up @@ -1702,10 +1702,10 @@ def render_model_constraint(cls, constraint: ModelLevelConstraint) -> Optional[s
f"{constraint_prefix}primary key{constraint_expression} ({column_list})"
)
elif constraint.type == ConstraintType.foreign_key:
if constraint.expression:
rendered_model_constraint = f"{constraint_prefix}foreign key ({column_list}) references {constraint.expression}"
elif constraint.to and constraint.to_columns:
if constraint.to and constraint.to_columns:
rendered_model_constraint = f"{constraint_prefix}foreign key ({column_list}) references {constraint.to} ({', '.join(constraint.to_columns)})"
elif constraint.expression:
rendered_model_constraint = f"{constraint_prefix}foreign key ({column_list}) references {constraint.expression}"
elif constraint.type == ConstraintType.custom and constraint.expression:
rendered_model_constraint = f"{constraint_prefix}{constraint.expression}"

Expand Down

0 comments on commit 5b27d24

Please sign in to comment.