fix: Remove aggregates, procedures and window functions from schema cache and OpenAPI output
Aggregates and Window functions can't be called as RPCs in a useful way. Procedures are not supported right now, but might be added later. Resolves #2101 Signed-off-by: Wolfgang Walther <walther@technowledgy.de>
This commit is contained in:
committed by
Steve Chavez
parent
5a88161ff7
commit
7cc8502a64
@@ -19,6 +19,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|||||||
- #2120, Fix reading database configuration properly when `=` is present in value - @wolfgangwalther
|
- #2120, Fix reading database configuration properly when `=` is present in value - @wolfgangwalther
|
||||||
- #1771, Fix silently ignoring filter on a non-existent embedded resource - @steve-chavez
|
- #1771, Fix silently ignoring filter on a non-existent embedded resource - @steve-chavez
|
||||||
- #2135, Remove trigger functions from schema cache and OpenAPI output, because they can't be called directly anyway. - @wolfgangwalther
|
- #2135, Remove trigger functions from schema cache and OpenAPI output, because they can't be called directly anyway. - @wolfgangwalther
|
||||||
|
- #2101, Remove aggregates, procedures and window functions from the schema cache and OpenAPI output. - @wolfgangwalther
|
||||||
- #2145, Fix accessing json array fields with -> and ->> in ?select= and ?order=. - @wolfgangwalther
|
- #2145, Fix accessing json array fields with -> and ->> in ?select= and ?order=. - @wolfgangwalther
|
||||||
- #2153, Fix --dump-schema running with a wrong PG version. - @wolfgangwalther
|
- #2153, Fix --dump-schema running with a wrong PG version. - @wolfgangwalther
|
||||||
|
|
||||||
|
|||||||
@@ -469,7 +469,7 @@ handleOpenApi headersOnly tSchema (RequestContext conf@AppConfig{..} dbStructure
|
|||||||
OAFollowPriv ->
|
OAFollowPriv ->
|
||||||
OpenAPI.encode conf dbStructure
|
OpenAPI.encode conf dbStructure
|
||||||
<$> SQL.statement tSchema (DbStructure.accessibleTables ctxPgVersion configDbPreparedStatements)
|
<$> SQL.statement tSchema (DbStructure.accessibleTables ctxPgVersion configDbPreparedStatements)
|
||||||
<*> SQL.statement tSchema (DbStructure.accessibleProcs configDbPreparedStatements)
|
<*> SQL.statement tSchema (DbStructure.accessibleProcs ctxPgVersion configDbPreparedStatements)
|
||||||
<*> SQL.statement tSchema (DbStructure.schemaDescription configDbPreparedStatements)
|
<*> SQL.statement tSchema (DbStructure.schemaDescription configDbPreparedStatements)
|
||||||
OAIgnorePriv ->
|
OAIgnorePriv ->
|
||||||
OpenAPI.encode conf dbStructure
|
OpenAPI.encode conf dbStructure
|
||||||
|
|||||||
@@ -42,7 +42,8 @@ import Data.Text (split)
|
|||||||
import Text.InterpolatedString.Perl6 (q)
|
import Text.InterpolatedString.Perl6 (q)
|
||||||
|
|
||||||
import PostgREST.Config.Database (pgVersionStatement)
|
import PostgREST.Config.Database (pgVersionStatement)
|
||||||
import PostgREST.Config.PgVersion (PgVersion, pgVersion100)
|
import PostgREST.Config.PgVersion (PgVersion, pgVersion100,
|
||||||
|
pgVersion110)
|
||||||
import PostgREST.DbStructure.Identifiers (QualifiedIdentifier (..),
|
import PostgREST.DbStructure.Identifiers (QualifiedIdentifier (..),
|
||||||
Schema, TableName)
|
Schema, TableName)
|
||||||
import PostgREST.DbStructure.Proc (PgType (..),
|
import PostgREST.DbStructure.Proc (PgType (..),
|
||||||
@@ -93,7 +94,7 @@ queryDbStructure schemas extraSearchPath prepared = do
|
|||||||
srcCols <- SQL.statement (schemas, extraSearchPath) $ pfkSourceColumns cols prepared
|
srcCols <- SQL.statement (schemas, extraSearchPath) $ pfkSourceColumns cols prepared
|
||||||
m2oRels <- SQL.statement mempty $ allM2ORels tabs cols prepared
|
m2oRels <- SQL.statement mempty $ allM2ORels tabs cols prepared
|
||||||
keys <- SQL.statement mempty $ allPrimaryKeys tabs prepared
|
keys <- SQL.statement mempty $ allPrimaryKeys tabs prepared
|
||||||
procs <- SQL.statement schemas $ allProcs prepared
|
procs <- SQL.statement schemas $ allProcs pgVer prepared
|
||||||
|
|
||||||
let rels = addO2MRels . addM2MRels $ addViewM2ORels srcCols m2oRels
|
let rels = addO2MRels . addM2MRels $ addViewM2ORels srcCols m2oRels
|
||||||
keys' = addViewPrimaryKeys srcCols keys
|
keys' = addViewPrimaryKeys srcCols keys
|
||||||
@@ -226,18 +227,18 @@ decodeProcs =
|
|||||||
| v == 's' = Stable
|
| v == 's' = Stable
|
||||||
| otherwise = Volatile -- only 'v' can happen here
|
| otherwise = Volatile -- only 'v' can happen here
|
||||||
|
|
||||||
allProcs :: Bool -> SQL.Statement [Schema] ProcsMap
|
allProcs :: PgVersion -> Bool -> SQL.Statement [Schema] ProcsMap
|
||||||
allProcs = SQL.Statement sql (arrayParam HE.text) decodeProcs
|
allProcs pgVer = SQL.Statement sql (arrayParam HE.text) decodeProcs
|
||||||
where
|
where
|
||||||
sql = procsSqlQuery <> " AND pn.nspname = ANY($1)"
|
sql = procsSqlQuery pgVer <> " AND pn.nspname = ANY($1)"
|
||||||
|
|
||||||
accessibleProcs :: Bool -> SQL.Statement Schema ProcsMap
|
accessibleProcs :: PgVersion -> Bool -> SQL.Statement Schema ProcsMap
|
||||||
accessibleProcs = SQL.Statement sql (param HE.text) decodeProcs
|
accessibleProcs pgVer = SQL.Statement sql (param HE.text) decodeProcs
|
||||||
where
|
where
|
||||||
sql = procsSqlQuery <> " AND pn.nspname = $1 AND has_function_privilege(p.oid, 'execute')"
|
sql = procsSqlQuery pgVer <> " AND pn.nspname = $1 AND has_function_privilege(p.oid, 'execute')"
|
||||||
|
|
||||||
procsSqlQuery :: SqlQuery
|
procsSqlQuery :: PgVersion -> SqlQuery
|
||||||
procsSqlQuery = [q|
|
procsSqlQuery pgVer = [q|
|
||||||
-- Recursively get the base types of domains
|
-- Recursively get the base types of domains
|
||||||
WITH
|
WITH
|
||||||
base_types AS (
|
base_types AS (
|
||||||
@@ -300,7 +301,7 @@ procsSqlQuery = [q|
|
|||||||
LEFT JOIN pg_class comp ON comp.oid = t.typrelid
|
LEFT JOIN pg_class comp ON comp.oid = t.typrelid
|
||||||
LEFT JOIN pg_catalog.pg_description as d ON d.objoid = p.oid
|
LEFT JOIN pg_catalog.pg_description as d ON d.objoid = p.oid
|
||||||
WHERE t.oid <> 'pg_catalog.trigger'::regtype
|
WHERE t.oid <> 'pg_catalog.trigger'::regtype
|
||||||
|]
|
|] <> (if pgVer >= pgVersion110 then "AND prokind = 'f'" else "AND NOT (proisagg OR proiswindow)")
|
||||||
|
|
||||||
schemaDescription :: Bool -> SQL.Statement Schema (Maybe Text)
|
schemaDescription :: Bool -> SQL.Statement Schema (Maybe Text)
|
||||||
schemaDescription =
|
schemaDescription =
|
||||||
|
|||||||
Vendored
+18
@@ -2427,3 +2427,21 @@ BEGIN
|
|||||||
END IF;
|
END IF;
|
||||||
END
|
END
|
||||||
$do$;
|
$do$;
|
||||||
|
|
||||||
|
-- This procedure is to confirm that procedures don't show up in the OpenAPI output right now.
|
||||||
|
-- Procedures are not supported, yet.
|
||||||
|
do $do$begin
|
||||||
|
if (select current_setting('server_version_num')::int >= 110000) then
|
||||||
|
CREATE PROCEDURE test.unsupported_proc ()
|
||||||
|
LANGUAGE SQL AS '';
|
||||||
|
end if;
|
||||||
|
end $do$;
|
||||||
|
|
||||||
|
CREATE FUNCTION public.dummy(int) RETURNS int
|
||||||
|
LANGUAGE SQL AS $$ SELECT 1 $$;
|
||||||
|
|
||||||
|
-- This aggregate is to confirm that aggregates don't show up in the OpenAPI output.
|
||||||
|
CREATE AGGREGATE test.unsupported_agg (*) (
|
||||||
|
SFUNC = public.dummy,
|
||||||
|
STYPE = int
|
||||||
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user