Merge pull request #728 from steve-chavez/master

Fix fatal error on postgres unsupported version, also fix #577 format…
This commit is contained in:
Joe Nelson
2016-10-31 23:06:02 -07:00
committed by GitHub
3 changed files with 15 additions and 6 deletions
+1
View File
@@ -22,6 +22,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- Fix bug in relation detection when selecting parents two levels up by using the name of the FK - @ruslantalpa
- Customize content negotiation per route - @begriffs
- Allow using nulls order without explicit order direction - @steve-chavez
- Fatal error on postgres unsupported version, format supported version in error message - @steve-chavez
### Changed
- Use HTTP 400 for raise\_exception - @begriffs
+5 -4
View File
@@ -5,6 +5,7 @@ module Main where
import Protolude
import PostgREST.App
import PostgREST.Config (AppConfig (..),
PgVersion (..),
minimumPgVersion,
prettyVersion,
readOptions)
@@ -34,11 +35,11 @@ import System.Posix.Signals
isServerVersionSupported :: H.Session Bool
isServerVersionSupported = do
ver <- H.query () pgVersion
return $ toInteger ver >= minimumPgVersion
return $ ver >= pgvNum minimumPgVersion
where
pgVersion =
H.statement "SHOW server_version_num"
HE.unit (HD.singleRow $ HD.value HD.int4) True
H.statement "SELECT current_setting('server_version_num')::integer"
HE.unit (HD.singleRow $ HD.value HD.int4) False
main :: IO ()
main = do
@@ -67,7 +68,7 @@ main = do
supported <- isServerVersionSupported
unless supported $ panic (
"Cannot run in this PostgreSQL version, PostgREST needs at least "
<> show minimumPgVersion)
<> pgvName minimumPgVersion)
getDbStructure (toS $ configSchema conf)
forM_ (lefts [result]) $ \e -> do
+9 -2
View File
@@ -16,6 +16,7 @@ module PostgREST.Config ( prettyVersion
, readOptions
, corsPolicy
, minimumPgVersion
, PgVersion (..)
, AppConfig (..)
)
where
@@ -171,6 +172,12 @@ argParser = CmdArgs <$>
help "Path to configuration file")) <*>
switch (long "example-config" <> help "output an example config file")
data PgVersion = PgVersion {
pgvNum :: Int32
, pgvName :: Text
}
-- | Tells the minimum PostgreSQL version required by this version of PostgREST
minimumPgVersion :: Integer
minimumPgVersion = 90300
minimumPgVersion :: PgVersion
minimumPgVersion = PgVersion 90300 "9.3"