Skip to content

Commit

Permalink
fix: handle when referential_constraints_subquery.table_name is null (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
omjadas authored Feb 24, 2024
1 parent 3d46e85 commit f139abc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/postgres/discovery/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ impl SchemaDiscovery {
.executor
.fetch_all(
self.query
.query_table_constriants(schema.clone(), table.clone()),
.query_table_constraints(schema.clone(), table.clone()),
)
.await?;

Expand Down
12 changes: 8 additions & 4 deletions src/postgres/query/constraints/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub struct TableConstraintsQueryResult {
}

impl SchemaQueryBuilder {
pub fn query_table_constriants(
pub fn query_table_constraints(
&self,
schema: SeaRc<dyn Iden>,
table: SeaRc<dyn Iden>,
Expand Down Expand Up @@ -197,9 +197,13 @@ impl SchemaQueryBuilder {
Expr::col((Schema::TableConstraints, Tcf::TableSchema)).eq(schema.to_string()),
)
.and_where(Expr::col((Schema::TableConstraints, Tcf::TableName)).eq(table.to_string()))
.and_where(
Expr::col((rcsq.clone(), Kcuf::TableName))
.not_in_subquery(select_base_table_and_view()),
.cond_where(
Condition::any()
.add(Expr::col((rcsq.clone(), Kcuf::TableName)).is_null())
.add(
Expr::col((rcsq.clone(), Kcuf::TableName))
.not_in_subquery(select_base_table_and_view()),
),
)
.order_by((Schema::TableConstraints, Tcf::ConstraintName), Order::Asc)
.order_by((Schema::KeyColumnUsage, Kcuf::OrdinalPosition), Order::Asc)
Expand Down

0 comments on commit f139abc

Please sign in to comment.