feat: Include partitioned tables into the schema cache

Allows embedding, UPSERT, INSERT with Location response, OPTIONS request and OpenAPI support for partitioned tables
This commit is contained in:
laurenceisla
2021-08-13 15:06:56 -05:00
committed by GitHub
parent b3899e7aa4
commit 4e4548d702
12 changed files with 351 additions and 49 deletions
+79 -2
View File
@@ -8,8 +8,9 @@ import Test.Hspec hiding (pendingWith)
import Test.Hspec.Wai
import Test.Hspec.Wai.JSON
import PostgREST.Config.PgVersion (PgVersion, pgVersion112,
pgVersion121, pgVersion96)
import PostgREST.Config.PgVersion (PgVersion, pgVersion110,
pgVersion112, pgVersion121,
pgVersion96)
import Protolude hiding (get)
import SpecHelper
@@ -395,6 +396,82 @@ spec actualPgVersion = do
[json|[{"id":1,"computed_overload":true}]|]
{ matchHeaders = [matchContentTypeJson] }
when (actualPgVersion >= pgVersion110) $ do
describe "partitioned tables embedding" $ do
it "can request a table as parent from a partitioned table" $
get "/partitioned_a?id=in.(1,2)&select=id,name,reference_from_partitioned(id)&order=id.asc" `shouldRespondWith`
[json|
[{"id":1,"name":"first","reference_from_partitioned":{"id":1}},
{"id":2,"name":"first","reference_from_partitioned":null}] |]
{ matchHeaders = [matchContentTypeJson] }
it "can request partitioned tables as children from a table" $
get "/reference_from_partitioned?select=id,partitioned_a(id,name)&order=id.asc" `shouldRespondWith`
[json|
[{"id":1,"partitioned_a":[{"id":1,"name":"first"}]},
{"id":2,"partitioned_a":[]}] |]
{ matchHeaders = [matchContentTypeJson] }
when (actualPgVersion >= pgVersion121) $ do
it "can request tables as children from a partitioned table" $
get "/partitioned_a?id=in.(1,2)&select=id,name,reference_to_partitioned(id)&order=id.asc" `shouldRespondWith`
[json|
[{"id":1,"name":"first","reference_to_partitioned":[]},
{"id":2,"name":"first","reference_to_partitioned":[{"id":2}]}] |]
{ matchHeaders = [matchContentTypeJson] }
it "can request a partitioned table as parent from a table" $
get "/reference_to_partitioned?select=id,partitioned_a(id,name)&order=id.asc" `shouldRespondWith`
[json|
[{"id":1,"partitioned_a":null},
{"id":2,"partitioned_a":{"id":2,"name":"first"}}] |]
{ matchHeaders = [matchContentTypeJson] }
it "can request partitioned tables as children from a partitioned table" $
get "/partitioned_a?id=in.(1,2,4)&select=id,name,partitioned_b(id,name)&order=id.asc" `shouldRespondWith`
[json|
[{"id":1,"name":"first","partitioned_b":[]},
{"id":2,"name":"first","partitioned_b":[{"id":2,"name":"first_b"}]},
{"id":4,"name":"second","partitioned_b":[{"id":4,"name":"second_b"}]}] |]
{ matchHeaders = [matchContentTypeJson] }
it "can request a partitioned table as parent from a partitioned table" $ do
get "/partitioned_b?id=in.(2,4)&select=id,name,partitioned_a(id,name)&order=id.asc" `shouldRespondWith`
[json|
[{"id":2,"name":"first_b","partitioned_a":{"id":2,"name":"first"}},
{"id":4,"name":"second_b","partitioned_a":{"id":4,"name":"second"}}] |]
{ matchHeaders = [matchContentTypeJson] }
it "can request partitions as children from a partitioned table" $
get "/partitioned_a?id=in.(1,2,4)&select=id,name,first_partition_b(id)&order=id.asc" `shouldRespondWith`
[json|
[{"id":1,"name":"first","first_partition_b":[]},
{"id":2,"name":"first","first_partition_b":[{"id":2}]},
{"id":4,"name":"second","first_partition_b":[]}] |]
{ matchHeaders = [matchContentTypeJson] }
it "can request a partitioned table as parent from a partition" $
get "/first_partition_b?select=id,name,partitioned_a(id,name)&order=id.asc" `shouldRespondWith`
[json|
[{"id":1,"name":"first_b","partitioned_a":null},
{"id":2,"name":"first_b","partitioned_a":{"id":2,"name":"first"}}] |]
{ matchHeaders = [matchContentTypeJson] }
it "can request a partition as parent from a partitioned table" $
get "/partitioned_b?id=in.(1,3,4)&select=id,name,second_partition_a(id,name)&order=id.asc" `shouldRespondWith`
[json|
[{"id":1,"name":"first_b","second_partition_a":null},
{"id":3,"name":"second_b","second_partition_a":null},
{"id":4,"name":"second_b","second_partition_a":{"id":4,"name":"second"}}] |]
{ matchHeaders = [matchContentTypeJson] }
it "can request partitioned tables as children from a partition" $
get "/second_partition_a?select=id,name,partitioned_b(id,name)&order=id.asc" `shouldRespondWith`
[json|
[{"id":3,"name":"second","partitioned_b":[]},
{"id":4,"name":"second","partitioned_b":[{"id":4,"name":"second_b"}]}] |]
{ matchHeaders = [matchContentTypeJson] }
describe "view embedding" $ do
it "can detect fk relations through views to tables in the public schema" $
get "/consumers_view?select=*,orders_view(*)" `shouldRespondWith` 200