From adfd980a6064b6a44b1435fbf5aa02c06d8380a9 Mon Sep 17 00:00:00 2001 From: Diogo Biazus Date: Tue, 6 Oct 2015 20:27:54 -0400 Subject: [PATCH] Moves minimum pg version to config, eliminates magic constant from main and improves docs. --- src/PostgREST/Config.hs | 8 +++++++- src/PostgREST/Main.hs | 5 +++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/PostgREST/Config.hs b/src/PostgREST/Config.hs index 8c762c4f3..a268f1626 100644 --- a/src/PostgREST/Config.hs +++ b/src/PostgREST/Config.hs @@ -8,15 +8,17 @@ It also can be used to define other middleware configuration that may be delegat external configuration. 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 , readOptions , corsPolicy + , minimumPgVersion , AppConfig (..) ) where - import Control.Applicative import qualified Data.ByteString.Char8 as BS import qualified Data.CaseInsensitive as CI @@ -100,3 +102,7 @@ readOptions = customExecParser parserPrefs opts <> " / create a REST API to an existing Postgres database" ) parserPrefs = prefs showHelpOnError + +-- | Tells the minimum PostgreSQL version required by this version of PostgREST +minimumPgVersion :: Integer +minimumPgVersion = 90200 diff --git a/src/PostgREST/Main.hs b/src/PostgREST/Main.hs index a2787f842..2c1567c51 100644 --- a/src/PostgREST/Main.hs +++ b/src/PostgREST/Main.hs @@ -26,12 +26,13 @@ import System.IO (BufferMode (..), import PostgREST.Config (AppConfig (..), prettyVersion, - readOptions) + readOptions, + minimumPgVersion) isServerVersionSupported :: H.Session P.Postgres IO Bool isServerVersionSupported = do 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 = do