Add tables back to DbStructure
This commit is contained in:
@@ -147,7 +147,7 @@ app db conf reqBody req =
|
|||||||
-- select * from public.proc(a := "foo"::undefined) where whereT limit limitT
|
-- select * from public.proc(a := "foo"::undefined) where whereT limit limitT
|
||||||
|
|
||||||
([], _) -> do
|
([], _) -> do
|
||||||
body <- encode <$> tables (cs schema)
|
body <- encode <$> accessibleTables (filter ((== cs schema) . tableSchema) allTabs)
|
||||||
return $ responseLBS status200 [jsonH] $ cs body
|
return $ responseLBS status200 [jsonH] $ cs body
|
||||||
|
|
||||||
([table], "OPTIONS") -> do
|
([table], "OPTIONS") -> do
|
||||||
@@ -160,6 +160,7 @@ app db conf reqBody req =
|
|||||||
return $ responseLBS status404 [] ""
|
return $ responseLBS status404 [] ""
|
||||||
|
|
||||||
where
|
where
|
||||||
|
allTabs = tables db
|
||||||
allRels = relations db
|
allRels = relations db
|
||||||
allCols = columns db
|
allCols = columns db
|
||||||
allPrKeys = primaryKeys db
|
allPrKeys = primaryKeys db
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
{-# LANGUAGE TypeSynonymInstances #-}
|
{-# LANGUAGE TypeSynonymInstances #-}
|
||||||
module PostgREST.DbStructure (
|
module PostgREST.DbStructure (
|
||||||
createDbStructure
|
createDbStructure
|
||||||
|
, accessibleTables
|
||||||
, doesProcExist
|
, doesProcExist
|
||||||
, doesProcReturnJWT
|
, doesProcReturnJWT
|
||||||
) where
|
) where
|
||||||
@@ -71,6 +72,26 @@ doesProcReturnJWT = doesProc [H.stmt|
|
|||||||
AND pg_catalog.pg_get_function_result(p.oid) like '%jwt_claims'
|
AND pg_catalog.pg_get_function_result(p.oid) like '%jwt_claims'
|
||||||
|]
|
|]
|
||||||
|
|
||||||
|
accessibleTables :: [Table] -> H.Tx P.Postgres s [Table]
|
||||||
|
accessibleTables allTabs = do
|
||||||
|
accessible <- H.listEx $ [H.stmt|
|
||||||
|
SELECT
|
||||||
|
n.nspname AS table_schema,
|
||||||
|
c.relname AS table_name
|
||||||
|
FROM pg_class c
|
||||||
|
JOIN pg_namespace n ON n.oid = c.relnamespace
|
||||||
|
WHERE
|
||||||
|
c.relkind IN ('v','r','m') AND
|
||||||
|
n.nspname NOT IN ('pg_catalog', 'information_schema') AND (
|
||||||
|
pg_has_role(c.relowner, 'USAGE'::text) OR
|
||||||
|
has_table_privilege(c.oid, 'SELECT, INSERT, UPDATE, DELETE, TRUNCATE, REFERENCES, TRIGGER'::text) OR
|
||||||
|
has_any_column_privilege(c.oid, 'SELECT, INSERT, UPDATE, REFERENCES'::text)
|
||||||
|
)
|
||||||
|
ORDER BY table_schema, table_name
|
||||||
|
|]
|
||||||
|
let isAccessible table = isJust $ find (\(s,n) -> tableSchema table == s && tableName table == n) accessible
|
||||||
|
return $ filter isAccessible allTabs
|
||||||
|
|
||||||
synonymousColumns :: [(Column,Column)] -> [Column] -> [[Column]]
|
synonymousColumns :: [(Column,Column)] -> [Column] -> [[Column]]
|
||||||
synonymousColumns allSyns cols = synCols'
|
synonymousColumns allSyns cols = synCols'
|
||||||
where
|
where
|
||||||
@@ -159,7 +180,7 @@ allTables = do
|
|||||||
WHERE c.relkind IN ('v','r','m')
|
WHERE c.relkind IN ('v','r','m')
|
||||||
AND n.nspname NOT IN ('pg_catalog', 'information_schema')
|
AND n.nspname NOT IN ('pg_catalog', 'information_schema')
|
||||||
GROUP BY table_schema, table_name, insertable
|
GROUP BY table_schema, table_name, insertable
|
||||||
ORDER BY table_schema, table_name;
|
ORDER BY table_schema, table_name
|
||||||
|]
|
|]
|
||||||
return $ map tableFromRow rows
|
return $ map tableFromRow rows
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,8 @@ import Data.Aeson
|
|||||||
import Data.Map
|
import Data.Map
|
||||||
|
|
||||||
data DbStructure = DbStructure {
|
data DbStructure = DbStructure {
|
||||||
columns :: [Column]
|
tables :: [Table]
|
||||||
|
, columns :: [Column]
|
||||||
, relations :: [Relation]
|
, relations :: [Relation]
|
||||||
, primaryKeys :: [PrimaryKey]
|
, primaryKeys :: [PrimaryKey]
|
||||||
} deriving (Show, Eq)
|
} deriving (Show, Eq)
|
||||||
|
|||||||
Reference in New Issue
Block a user