From f139abc04eeb95fc29d21680a633bbf3154da22c Mon Sep 17 00:00:00 2001 From: omjadas Date: Sat, 24 Feb 2024 23:52:15 +1100 Subject: [PATCH] fix: handle when referential_constraints_subquery.table_name is null (#125) --- src/postgres/discovery/mod.rs | 2 +- src/postgres/query/constraints/mod.rs | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/postgres/discovery/mod.rs b/src/postgres/discovery/mod.rs index 9e191d70..69ee13c4 100644 --- a/src/postgres/discovery/mod.rs +++ b/src/postgres/discovery/mod.rs @@ -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?; diff --git a/src/postgres/query/constraints/mod.rs b/src/postgres/query/constraints/mod.rs index c609b604..fdc53ad7 100644 --- a/src/postgres/query/constraints/mod.rs +++ b/src/postgres/query/constraints/mod.rs @@ -44,7 +44,7 @@ pub struct TableConstraintsQueryResult { } impl SchemaQueryBuilder { - pub fn query_table_constriants( + pub fn query_table_constraints( &self, schema: SeaRc, table: SeaRc, @@ -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)