From 4064a7b984ca52402a76bb0b7e2ffb3018396638 Mon Sep 17 00:00:00 2001 From: SteveBash Date: Sat, 29 Oct 2016 13:38:19 -0500 Subject: [PATCH] Fix fatal error on postgres unsupported version, also fix #577 format of supported version --- CHANGELOG.md | 1 + main/Main.hs | 9 +++++---- src/PostgREST/Config.hs | 11 +++++++++-- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 90761ee97..1a3c05be7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/main/Main.hs b/main/Main.hs index 9140a33db..a72235efb 100644 --- a/main/Main.hs +++ b/main/Main.hs @@ -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 diff --git a/src/PostgREST/Config.hs b/src/PostgREST/Config.hs index c6beec133..26f3f2697 100644 --- a/src/PostgREST/Config.hs +++ b/src/PostgREST/Config.hs @@ -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"