Allow multiple schemas to be exposed in one instance (#1450)

The schema to use can be selected through the headers `Accept-Profile` for GET/HEAD and `Content-Profile` for POST/PATCH/PUT/DELETE.

This is based on the https://www.w3.org/TR/dx-prof-conneg/ttps://www.w3.org/TR/dx-prof-conneg/ spec.

Also increase all memory tests by 1M(otherwise CI fails).

Co-authored-by: Mahmoud Kassem <MKassem@gk-software.com>
Co-authored-by: Mahmoud Kassem <mahmoud_k@mail.com>
This commit is contained in:
Steve Chavez
2020-03-30 14:04:20 -05:00
committed by GitHub
co-authored by Mahmoud Kassem Mahmoud Kassem
parent a80eb2ff0e
commit 691bb5640d
21 changed files with 590 additions and 114 deletions
+10 -8
View File
@@ -45,7 +45,7 @@ import PostgREST.OpenAPI (isMalformedProxyUri)
import PostgREST.Types (ConnectionStatus (..), DbStructure,
PgVersion (..), Schema,
minimumPgVersion)
import Protolude hiding (hPutStrLn, replace)
import Protolude hiding (hPutStrLn, head, replace)
#ifndef mingw32_HOST_OS
@@ -73,11 +73,11 @@ import System.Posix.Signals
connectionWorker
:: ThreadId -- ^ This thread is killed if pg version is unsupported
-> P.Pool -- ^ The PostgreSQL connection pool
-> Schema -- ^ Schema PostgREST is serving up
-> [Schema] -- ^ Schemas PostgREST is serving up
-> IORef (Maybe DbStructure) -- ^ mutable reference to 'DbStructure'
-> IORef Bool -- ^ Used as a binary Semaphore
-> IO ()
connectionWorker mainTid pool schema refDbStructure refIsWorkerOn = do
connectionWorker mainTid pool schemas refDbStructure refIsWorkerOn = do
isWorkerOn <- readIORef refIsWorkerOn
unless isWorkerOn $ do
atomicWriteIORef refIsWorkerOn True
@@ -93,7 +93,7 @@ connectionWorker mainTid pool schema refDbStructure refIsWorkerOn = do
NotConnected -> return () -- Unreachable
Connected actualPgVersion -> do -- Procede with initialization
result <- P.use pool $ do
dbStructure <- HT.transaction HT.ReadCommitted HT.Read $ getDbStructure schema actualPgVersion
dbStructure <- HT.transaction HT.ReadCommitted HT.Read $ getDbStructure schemas actualPgVersion
liftIO $ atomicWriteIORef refDbStructure $ Just dbStructure
case result of
Left e -> do
@@ -162,7 +162,8 @@ main = do
-- readOptions builds the 'AppConfig' from the config file specified on the
-- command line
conf <- loadDbUriFile =<< loadSecretFile =<< readOptions
let host = configHost conf
let schemas = toList $ configSchemas conf
host = configHost conf
port = configPort conf
proxy = configOpenAPIProxyUri conf
maybeSocketAddr = configSocket conf
@@ -175,6 +176,7 @@ main = do
. setServerName (toS $ "postgrest/" <> prettyVersion) $
defaultSettings
whenLeft socketFileMode panic
-- Checks that the provided proxy uri is formated correctly
@@ -205,7 +207,7 @@ main = do
connectionWorker
mainTid
pool
(configSchema conf)
schemas
refDbStructure
refIsWorkerOn
--
@@ -227,7 +229,7 @@ main = do
Catch $ connectionWorker
mainTid
pool
(configSchema conf)
schemas
refDbStructure
refIsWorkerOn
) Nothing
@@ -246,7 +248,7 @@ main = do
(connectionWorker
mainTid
pool
(configSchema conf)
schemas
refDbStructure
refIsWorkerOn)
in case maybeSocketAddr of