fix: Take PG version into account in --dump-schema
The PG version is only read by the Connection Worker, which is not used in the case dump-schema. Now, the pg version is read in the schema cache queries directly, avoiding this problem in all cases. Signed-off-by: Wolfgang Walther <walther@technowledgy.de>
This commit is contained in:
committed by
Wolfgang Walther
parent
52d628f1ed
commit
ded8981368
@@ -32,6 +32,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|||||||
- #1771, Fix silently ignoring filter on a non-existent embedded resource - @steve-chavez
|
- #1771, Fix silently ignoring filter on a non-existent embedded resource - @steve-chavez
|
||||||
- #2135, Remove trigger functions from schema cache and OpenAPI output, because they can't be called directly anyway. - @wolfgangwalther
|
- #2135, Remove trigger functions from schema cache and OpenAPI output, because they can't be called directly anyway. - @wolfgangwalther
|
||||||
- #2145, Fix accessing json array fields with -> and ->> in ?select= and ?order=. - @wolfgangwalther
|
- #2145, Fix accessing json array fields with -> and ->> in ?select= and ?order=. - @wolfgangwalther
|
||||||
|
- #2153, Fix --dump-schema running with a wrong PG version. - @wolfgangwalther
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
|
|||||||
@@ -53,7 +53,6 @@ main installSignalHandlers runAppWithSocket CLI{cliCommand, cliPath} = do
|
|||||||
dumpSchema :: AppState -> IO LBS.ByteString
|
dumpSchema :: AppState -> IO LBS.ByteString
|
||||||
dumpSchema appState = do
|
dumpSchema appState = do
|
||||||
AppConfig{..} <- AppState.getConfig appState
|
AppConfig{..} <- AppState.getConfig appState
|
||||||
actualPgVersion <- AppState.getPgVersion appState
|
|
||||||
result <-
|
result <-
|
||||||
let transaction = if configDbPreparedStatements then SQL.transaction else SQL.unpreparedTransaction in
|
let transaction = if configDbPreparedStatements then SQL.transaction else SQL.unpreparedTransaction in
|
||||||
SQL.use (AppState.getPool appState) $
|
SQL.use (AppState.getPool appState) $
|
||||||
@@ -61,7 +60,6 @@ dumpSchema appState = do
|
|||||||
queryDbStructure
|
queryDbStructure
|
||||||
(toList configDbSchemas)
|
(toList configDbSchemas)
|
||||||
configDbExtraSearchPath
|
configDbExtraSearchPath
|
||||||
actualPgVersion
|
|
||||||
configDbPreparedStatements
|
configDbPreparedStatements
|
||||||
SQL.release $ AppState.getPool appState
|
SQL.release $ AppState.getPool appState
|
||||||
case result of
|
case result of
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
{-# LANGUAGE QuasiQuotes #-}
|
{-# LANGUAGE QuasiQuotes #-}
|
||||||
|
|
||||||
module PostgREST.Config.Database
|
module PostgREST.Config.Database
|
||||||
( queryDbSettings
|
( pgVersionStatement
|
||||||
|
, queryDbSettings
|
||||||
, queryPgVersion
|
, queryPgVersion
|
||||||
) where
|
) where
|
||||||
|
|
||||||
@@ -20,7 +21,10 @@ import Text.InterpolatedString.Perl6 (q)
|
|||||||
import Protolude
|
import Protolude
|
||||||
|
|
||||||
queryPgVersion :: Session PgVersion
|
queryPgVersion :: Session PgVersion
|
||||||
queryPgVersion = statement mempty $ SQL.Statement sql HE.noParams versionRow False
|
queryPgVersion = statement mempty pgVersionStatement
|
||||||
|
|
||||||
|
pgVersionStatement :: SQL.Statement () PgVersion
|
||||||
|
pgVersionStatement = SQL.Statement sql HE.noParams versionRow False
|
||||||
where
|
where
|
||||||
sql = "SELECT current_setting('server_version_num')::integer, current_setting('server_version')"
|
sql = "SELECT current_setting('server_version_num')::integer, current_setting('server_version')"
|
||||||
versionRow = HD.singleRow $ PgVersion <$> column HD.int4 <*> column HD.text
|
versionRow = HD.singleRow $ PgVersion <$> column HD.int4 <*> column HD.text
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ import Data.Set as S (fromList)
|
|||||||
import Data.Text (split)
|
import Data.Text (split)
|
||||||
import Text.InterpolatedString.Perl6 (q)
|
import Text.InterpolatedString.Perl6 (q)
|
||||||
|
|
||||||
|
import PostgREST.Config.Database (pgVersionStatement)
|
||||||
import PostgREST.Config.PgVersion (PgVersion, pgVersion100)
|
import PostgREST.Config.PgVersion (PgVersion, pgVersion100)
|
||||||
import PostgREST.DbStructure.Identifiers (QualifiedIdentifier (..),
|
import PostgREST.DbStructure.Identifiers (QualifiedIdentifier (..),
|
||||||
Schema, TableName)
|
Schema, TableName)
|
||||||
@@ -83,9 +84,10 @@ type ViewColumn = Column
|
|||||||
-- | A SQL query that can be executed independently
|
-- | A SQL query that can be executed independently
|
||||||
type SqlQuery = ByteString
|
type SqlQuery = ByteString
|
||||||
|
|
||||||
queryDbStructure :: [Schema] -> [Schema] -> PgVersion -> Bool -> SQL.Transaction DbStructure
|
queryDbStructure :: [Schema] -> [Schema] -> Bool -> SQL.Transaction DbStructure
|
||||||
queryDbStructure schemas extraSearchPath pgVer prepared = do
|
queryDbStructure schemas extraSearchPath prepared = do
|
||||||
SQL.sql "set local schema ''" -- This voids the search path. The following queries need this for getting the fully qualified name(schema.name) of every db object
|
SQL.sql "set local schema ''" -- This voids the search path. The following queries need this for getting the fully qualified name(schema.name) of every db object
|
||||||
|
pgVer <- SQL.statement mempty pgVersionStatement
|
||||||
tabs <- SQL.statement mempty $ allTables pgVer prepared
|
tabs <- SQL.statement mempty $ allTables pgVer prepared
|
||||||
cols <- SQL.statement schemas $ allColumns tabs prepared
|
cols <- SQL.statement schemas $ allColumns tabs prepared
|
||||||
srcCols <- SQL.statement (schemas, extraSearchPath) $ pfkSourceColumns cols prepared
|
srcCols <- SQL.statement (schemas, extraSearchPath) $ pfkSourceColumns cols prepared
|
||||||
|
|||||||
@@ -153,11 +153,10 @@ connectionStatus appState =
|
|||||||
loadSchemaCache :: AppState -> IO SCacheStatus
|
loadSchemaCache :: AppState -> IO SCacheStatus
|
||||||
loadSchemaCache appState = do
|
loadSchemaCache appState = do
|
||||||
AppConfig{..} <- AppState.getConfig appState
|
AppConfig{..} <- AppState.getConfig appState
|
||||||
actualPgVersion <- AppState.getPgVersion appState
|
|
||||||
result <-
|
result <-
|
||||||
let transaction = if configDbPreparedStatements then SQL.transaction else SQL.unpreparedTransaction in
|
let transaction = if configDbPreparedStatements then SQL.transaction else SQL.unpreparedTransaction in
|
||||||
SQL.use (AppState.getPool appState) . transaction SQL.ReadCommitted SQL.Read $
|
SQL.use (AppState.getPool appState) . transaction SQL.ReadCommitted SQL.Read $
|
||||||
queryDbStructure (toList configDbSchemas) configDbExtraSearchPath actualPgVersion configDbPreparedStatements
|
queryDbStructure (toList configDbSchemas) configDbExtraSearchPath configDbPreparedStatements
|
||||||
case result of
|
case result of
|
||||||
Left e -> do
|
Left e -> do
|
||||||
let
|
let
|
||||||
|
|||||||
+2
-4
@@ -67,7 +67,6 @@ main = do
|
|||||||
loadDbStructure pool
|
loadDbStructure pool
|
||||||
(configDbSchemas testCfg)
|
(configDbSchemas testCfg)
|
||||||
(configDbExtraSearchPath testCfg)
|
(configDbExtraSearchPath testCfg)
|
||||||
actualPgVersion
|
|
||||||
|
|
||||||
let
|
let
|
||||||
-- For tests that run with the same refDbStructure
|
-- For tests that run with the same refDbStructure
|
||||||
@@ -85,7 +84,6 @@ main = do
|
|||||||
loadDbStructure pool
|
loadDbStructure pool
|
||||||
(configDbSchemas config)
|
(configDbSchemas config)
|
||||||
(configDbExtraSearchPath config)
|
(configDbExtraSearchPath config)
|
||||||
actualPgVersion
|
|
||||||
appState <- AppState.initWithPool pool config
|
appState <- AppState.initWithPool pool config
|
||||||
AppState.putPgVersion appState actualPgVersion
|
AppState.putPgVersion appState actualPgVersion
|
||||||
AppState.putDbStructure appState (Just customDbStructure)
|
AppState.putDbStructure appState (Just customDbStructure)
|
||||||
@@ -236,5 +234,5 @@ main = do
|
|||||||
describe "Feature.RollbackForcedSpec" Feature.RollbackSpec.forced
|
describe "Feature.RollbackForcedSpec" Feature.RollbackSpec.forced
|
||||||
|
|
||||||
where
|
where
|
||||||
loadDbStructure pool schemas extraSearchPath actualPgVersion =
|
loadDbStructure pool schemas extraSearchPath =
|
||||||
either (panic.show) id <$> P.use pool (HT.transaction HT.ReadCommitted HT.Read $ queryDbStructure (toList schemas) extraSearchPath actualPgVersion True)
|
either (panic.show) id <$> P.use pool (HT.transaction HT.ReadCommitted HT.Read $ queryDbStructure (toList schemas) extraSearchPath True)
|
||||||
|
|||||||
Reference in New Issue
Block a user