Skip to content

Commit

Permalink
refactor: ignore partitions in allM2ORels
Browse files Browse the repository at this point in the history
Also clarify foreign key filter
  • Loading branch information
steve-chavez committed Apr 19, 2022
1 parent 7f1507b commit f4e171a
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/PostgREST/DbStructure.hs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ queryDbStructure schemas extraSearchPath prepared = do
tabs <- SQL.statement mempty $ allTables pgVer prepared
cols <- SQL.statement schemas $ allColumns tabs prepared
srcCols <- SQL.statement (schemas, extraSearchPath) $ pfkSourceColumns cols prepared
m2oRels <- SQL.statement mempty $ allM2ORels cols prepared
m2oRels <- SQL.statement mempty $ allM2ORels pgVer cols prepared
keys <- SQL.statement mempty $ allPrimaryKeys tabs prepared
procs <- SQL.statement schemas $ allProcs pgVer prepared

Expand Down Expand Up @@ -613,8 +613,8 @@ columnFromRow tabs (s, t, n, desc, nul, typ, l, d, e) = buildColumn <$> table
parseEnum :: Maybe Text -> [Text]
parseEnum = maybe [] (split (==','))

allM2ORels :: [Column] -> Bool -> SQL.Statement () [Relationship]
allM2ORels allCols =
allM2ORels :: PgVersion -> [Column] -> Bool -> SQL.Statement () [Relationship]
allM2ORels pgVer allCols =
SQL.Statement sql HE.noParams (decodeRels allCols)
where
sql = [q|
Expand All @@ -637,8 +637,11 @@ allM2ORels allCols =
LATERAL (SELECT * FROM pg_class WHERE pg_class.oid = conrelid) AS tab,
LATERAL (SELECT * FROM pg_class WHERE pg_class.oid = confrelid) AS other,
LATERAL (SELECT * FROM pg_namespace WHERE pg_namespace.oid = other.relnamespace) AS ns2
WHERE confrelid != 0
ORDER BY (conrelid, column_info.nums) |]
WHERE contype = 'f'|] <>
(if pgVer >= pgVersion110
then " and conparentid = 0 "
else mempty) <>
"ORDER BY (conrelid, column_info.nums)"

relFromRow :: [Column] -> (Text, Text, Text, [Text], Text, Text, [Text]) -> Maybe Relationship
relFromRow allCols (rs, rt, cn, rcs, frs, frt, frcs) =
Expand Down

0 comments on commit f4e171a

Please sign in to comment.