Moves minimum pg version to config, eliminates magic constant from main and improves docs.
This commit is contained in:
@@ -8,15 +8,17 @@ It also can be used to define other middleware configuration that may be delegat
|
|||||||
external configuration.
|
external configuration.
|
||||||
|
|
||||||
It currently includes a hardcoded CORS policy but this could easly be turned in configurable behaviour if needed.
|
It currently includes a hardcoded CORS policy but this could easly be turned in configurable behaviour if needed.
|
||||||
|
|
||||||
|
Other hardcoded options such as the minimum version number also belong here.
|
||||||
-}
|
-}
|
||||||
module PostgREST.Config ( prettyVersion
|
module PostgREST.Config ( prettyVersion
|
||||||
, readOptions
|
, readOptions
|
||||||
, corsPolicy
|
, corsPolicy
|
||||||
|
, minimumPgVersion
|
||||||
, AppConfig (..)
|
, AppConfig (..)
|
||||||
)
|
)
|
||||||
where
|
where
|
||||||
|
|
||||||
|
|
||||||
import Control.Applicative
|
import Control.Applicative
|
||||||
import qualified Data.ByteString.Char8 as BS
|
import qualified Data.ByteString.Char8 as BS
|
||||||
import qualified Data.CaseInsensitive as CI
|
import qualified Data.CaseInsensitive as CI
|
||||||
@@ -100,3 +102,7 @@ readOptions = customExecParser parserPrefs opts
|
|||||||
<> " / create a REST API to an existing Postgres database"
|
<> " / create a REST API to an existing Postgres database"
|
||||||
)
|
)
|
||||||
parserPrefs = prefs showHelpOnError
|
parserPrefs = prefs showHelpOnError
|
||||||
|
|
||||||
|
-- | Tells the minimum PostgreSQL version required by this version of PostgREST
|
||||||
|
minimumPgVersion :: Integer
|
||||||
|
minimumPgVersion = 90200
|
||||||
|
|||||||
@@ -26,12 +26,13 @@ import System.IO (BufferMode (..),
|
|||||||
|
|
||||||
import PostgREST.Config (AppConfig (..),
|
import PostgREST.Config (AppConfig (..),
|
||||||
prettyVersion,
|
prettyVersion,
|
||||||
readOptions)
|
readOptions,
|
||||||
|
minimumPgVersion)
|
||||||
|
|
||||||
isServerVersionSupported :: H.Session P.Postgres IO Bool
|
isServerVersionSupported :: H.Session P.Postgres IO Bool
|
||||||
isServerVersionSupported = do
|
isServerVersionSupported = do
|
||||||
Identity (row :: Text) <- H.tx Nothing $ H.singleEx $ [H.stmt|SHOW server_version_num|]
|
Identity (row :: Text) <- H.tx Nothing $ H.singleEx $ [H.stmt|SHOW server_version_num|]
|
||||||
return $ read (cs row) >= (90200::Integer)
|
return $ read (cs row) >= minimumPgVersion
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = do
|
main = do
|
||||||
|
|||||||
Reference in New Issue
Block a user