Enable embedding through multiple layers of views recursively (#1625)

* Include hidden views from the search path. Hidden views are views in unexposed schemas that are part of a view dependency chain.

* Change allSourceColumns to only return pk and fk columns
This commit is contained in:
Wolfgang Walther
2020-11-15 14:58:57 -05:00
committed by GitHub
parent 65968b5320
commit 6e04fe7454
8 changed files with 85 additions and 34 deletions
+4 -1
View File
@@ -6,7 +6,7 @@ import Test.Hspec
import Test.Hspec.Wai
import Test.Hspec.Wai.JSON
import Protolude
import Protolude hiding (get)
import SpecHelper
spec :: SpecWith ((), Application)
@@ -34,3 +34,6 @@ spec = describe "extra search path" $ do
request methodGet "/rpc/is_valid_isbn?input=978-0-393-04002-9" [] ""
`shouldRespondWith` [json|true|]
{ matchHeaders = [matchContentTypeJson] }
it "can detect fk relations through multiple views recursively when middle views are in extra search path" $
get "/consumers_extra_view?select=*,orders_view(*)" `shouldRespondWith` 200
+3
View File
@@ -421,6 +421,9 @@ spec actualPgVersion = do
[json|[ { "title": "To Kill a Mockingbird", "author": { "name": "Harper Lee" } } ]|]
{ matchHeaders = [matchContentTypeJson] }
it "can detect fk relations through multiple views recursively when all views are in api schema" $ do
get "/consumers_view_view?select=*,orders_view(*)" `shouldRespondWith` 200
it "works with views that have subselects" $
get "/authors_books_number?select=*,books(title)&id=eq.1" `shouldRespondWith`
[json|[ {"id":1, "name":"George Orwell","num_in_forties":1,"num_in_fifties":0,"num_in_sixties":0,"num_in_all_decades":1,
+5 -5
View File
@@ -61,7 +61,7 @@ main = do
actualPgVersion <- either (panic.show) id <$> P.use pool getPgVersion
refDbStructure <- (newIORef . Just) =<< setupDbStructure pool (configSchemas $ testCfg testDbConn) actualPgVersion
refDbStructure <- (newIORef . Just) =<< setupDbStructure pool (configSchemas $ testCfg testDbConn) (configExtraSearchPath $ testCfg testDbConn) actualPgVersion
let
-- For tests that run with the same refDbStructure
@@ -71,7 +71,7 @@ main = do
-- For tests that run with a different DbStructure(depends on configSchemas)
appDbs cfg = do
dbs <- (newIORef . Just) =<< setupDbStructure pool (configSchemas $ cfg testDbConn) actualPgVersion
dbs <- (newIORef . Just) =<< setupDbStructure pool (configSchemas $ cfg testDbConn) (configExtraSearchPath $ cfg testDbConn) actualPgVersion
refConf <- newIORef $ cfg testDbConn
return ((), postgrest LogCrit refConf dbs pool getTime $ pure ())
@@ -83,11 +83,11 @@ main = do
audJwtApp = app testCfgAudienceJWT
asymJwkApp = app testCfgAsymJWK
asymJwkSetApp = app testCfgAsymJWKSet
extraSearchPathApp = app testCfgExtraSearchPath
rootSpecApp = app testCfgRootSpec
htmlRawOutputApp = app testCfgHtmlRawOutput
responseHeadersApp = app testCfgResponseHeaders
extraSearchPathApp = appDbs testCfgExtraSearchPath
unicodeApp = appDbs testUnicodeCfg
nonexistentSchemaApp = appDbs testNonexistentSchemaCfg
multipleSchemaApp = appDbs testMultipleSchemaCfg
@@ -186,5 +186,5 @@ main = do
describe "Feature.MultipleSchemaSpec" $ Feature.MultipleSchemaSpec.spec actualPgVersion
where
setupDbStructure pool schemas ver =
either (panic.show) id <$> P.use pool (HT.transaction HT.ReadCommitted HT.Read $ getDbStructure (toList schemas) ver)
setupDbStructure pool schemas extraSearchPath ver =
either (panic.show) id <$> P.use pool (HT.transaction HT.ReadCommitted HT.Read $ getDbStructure (toList schemas) extraSearchPath ver)
+2
View File
@@ -53,6 +53,8 @@ GRANT ALL ON TABLE
, public.public_consumers
, public.public_orders
, consumers_view
, consumers_view_view
, consumers_extra_view
, orders_view
, images
, images_base64
+8
View File
@@ -175,6 +175,14 @@ create view orders_view as
create view consumers_view as
select * from public.public_consumers;
create view consumers_view_view as
select * from consumers_view;
create view public.consumers_extra as
select * from consumers_view;
create view consumers_extra_view as
select * from public.consumers_extra;
--
-- Name: getitemrange(bigint, bigint); Type: FUNCTION; Schema: test; Owner: -