WIP: converting dbstructure
This commit is contained in:
@@ -53,11 +53,11 @@ encodeQi =
|
||||
contramap qiSchema (HE.value HE.text) <>
|
||||
contramap qiName (HE.value HE.text)
|
||||
|
||||
decodeTable :: HD.Result Table
|
||||
decodeTable =
|
||||
HD.singleRow standardRow
|
||||
decodeTables :: HD.Result [Table]
|
||||
decodeTables =
|
||||
HD.rowsList tblRow
|
||||
where
|
||||
standardRow = Table <$> HD.value HD.text <*> HD.value HD.text
|
||||
tblRow = Table <$> HD.value HD.text <*> HD.value HD.text
|
||||
<*> HD.value HD.bool
|
||||
|
||||
doesProcExist :: H.Query QualifiedIdentifier Bool
|
||||
@@ -87,10 +87,11 @@ doesProcReturnJWT =
|
||||
AND pg_catalog.pg_get_function_result(p.oid) like '%jwt_claims'
|
||||
) |]
|
||||
|
||||
accessibleTables :: Schema -> H.Tx P.Postgres s [Table]
|
||||
accessibleTables schema = do
|
||||
rows <- H.listEx $
|
||||
[H.stmt|
|
||||
accessibleTables :: H.Query Schema [Table]
|
||||
accessibleTables =
|
||||
H.statement sql (HE.value HE.text) (HD.rowsList (HD.value HD.text)) True
|
||||
where
|
||||
sql = [q|
|
||||
select
|
||||
n.nspname as table_schema,
|
||||
relname as table_name,
|
||||
@@ -105,15 +106,14 @@ accessibleTables schema = do
|
||||
join pg_namespace n on n.oid = c.relnamespace
|
||||
where
|
||||
c.relkind in ('v', 'r', 'm')
|
||||
and n.nspname = ?
|
||||
and n.nspname = $1
|
||||
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 relname
|
||||
|] schema
|
||||
return $ map tableFromRow rows
|
||||
|]
|
||||
|
||||
synonymousColumns :: [(Column,Column)] -> [Column] -> [[Column]]
|
||||
synonymousColumns allSyns cols = synCols'
|
||||
@@ -187,9 +187,11 @@ synonymousPrimaryKeys syns (key:keys) = key : newKeys ++ synonymousPrimaryKeys s
|
||||
keySyns = filter ((\c -> colTable c == pkTable key && colName c == pkName key) . fst) syns
|
||||
newKeys = map ((\c -> PrimaryKey{pkTable=colTable c,pkName=colName c}) . snd) keySyns
|
||||
|
||||
allTables :: H.Session [Table]
|
||||
allTables = do
|
||||
rows <- H.listEx $ [H.stmt|
|
||||
allTables :: H.Query () [Table]
|
||||
allTables =
|
||||
H.statement sql HE.unit decodeTables True
|
||||
where
|
||||
sql = [q|
|
||||
SELECT
|
||||
n.nspname AS table_schema,
|
||||
c.relname AS table_name,
|
||||
@@ -205,9 +207,7 @@ allTables = do
|
||||
WHERE c.relkind IN ('v','r','m')
|
||||
AND n.nspname NOT IN ('pg_catalog', 'information_schema')
|
||||
GROUP BY table_schema, table_name, insertable
|
||||
ORDER BY table_schema, table_name
|
||||
|]
|
||||
return $ map tableFromRow rows
|
||||
ORDER BY table_schema, table_name |]
|
||||
|
||||
tableFromRow :: (Text, Text, Bool) -> Table
|
||||
tableFromRow (s, n, i) = Table s n i
|
||||
|
||||
Reference in New Issue
Block a user