packages feed

tmp-postgres 1.26.0.0 → 1.27.0.0

raw patch · 8 files changed

+66/−109 lines, 8 files

Files

CHANGELOG.md view
@@ -1,5 +1,10 @@ Changelog for tmp-postgres +1.27.0.0+  #191 Remove leading spaces in code examples+  #192 startConfig bullet points are out of date+  #189 Remove reloadConfig+ 1.26.0.0   #187 Remove stopPostgresGracefully from public interface 
README.md view
@@ -17,8 +17,8 @@  To extend or override the defaults use `withConfig` (or `startConfig`). -`tmp-postgres` ultimately calls (optionally) `initdb`, `postgres` and-(optionally) `createdb`.+`tmp-postgres` ultimately calls `initdb` (optionally) , `postgres` and+`createdb` (optionally).  All of the command line, environment variables and configuration files that are generated by default for the respective executables can be
src/Database/Postgres/Temp.hs view
@@ -15,8 +15,8 @@  To extend or override the defaults use `withConfig` (or `startConfig`). -@tmp-postgres@ ultimately calls (optionally) @initdb@, @postgres@ and-(optionally) @createdb@.+@tmp-postgres@ ultimately calls @initdb@ (optionally), @postgres@ and+≈@createdb@ (optionally).  All of the command line, environment variables and configuration files that are generated by default for the respective executables can be@@ -69,7 +69,6 @@   , toPostgresqlConfigFile   -- *** 'DB' modifiers   , makeDataDirectoryPermanent-  , reloadConfig   -- *** 'DB' debugging   , prettyPrintDB   -- ** Separate start and stop interface.
src/Database/Postgres/Temp/Internal.hs view
@@ -14,7 +14,6 @@ import           Control.Monad.Trans.Cont import           Data.ByteString (ByteString) import qualified Data.Map.Strict as Map-import qualified Database.PostgreSQL.Simple as PG import qualified Database.PostgreSQL.Simple.Options as Client import           GHC.Generics import           System.Exit (ExitCode(..))@@ -76,9 +75,9 @@ not modify the 'DB' that is passed for cleanup. You will need to setup your own bracket like - @-    bracket (fmap 'makeDataDirectoryPermanent' 'start') (either mempty 'stop')- @+@+bracket (fmap 'makeDataDirectoryPermanent' 'start') (either mempty 'stop')+@   @since 1.24.0.0@@ -107,16 +106,16 @@ {-| The fastest config we can make. - @-   shared_buffers = 12MB-   fsync = off-   synchronous_commit = off-   full_page_writes = off-   log_min_messages = PANIC-   log_min_error_statement = PANIC-   log_statement = none-   client_min_messages = ERROR- @+@+shared_buffers = 12MB+fsync = off+synchronous_commit = off+full_page_writes = off+log_min_messages = PANIC+log_min_error_statement = PANIC+log_statement = none+client_min_messages = ERROR+@  @since 1.21.0.0 -}@@ -140,16 +139,16 @@  Additionally it will use the following \"postgresql.conf\"  which is optimized for performance. - @-   shared_buffers = 12MB-   fsync = off-   synchronous_commit = off-   full_page_writes = off-   log_min_messages = PANIC-   log_min_error_statement = PANIC-   log_statement = none-   client_min_messages = ERROR @+shared_buffers = 12MB+fsync = off+synchronous_commit = off+full_page_writes = off+log_min_messages = PANIC+log_min_error_statement = PANIC+log_statement = none+client_min_messages = ERROR+@  'defaultConfig' also passes the @--no-sync@ flag to @initdb@. @@ -167,17 +166,17 @@ To append additional lines to \"postgresql.conf\" file create a custom 'Config' like the following. - @-  custom = defaultConfig <> mempty-    { 'postgresConfigFile' =-        [ ("wal_level, "replica")-        , ("archive_mode", on")-        , ("max_wal_senders", "2")-        , ("fsync", "on")-        , ("synchronous_commit", "on")-        ]-    }- @+@+custom = defaultConfig <> mempty+  { 'postgresConfigFile' =+      [ ("wal_level, "replica")+      , ("archive_mode", on")+      , ("max_wal_senders", "2")+      , ("fsync", "on")+      , ("synchronous_commit", "on")+      ]+  }+@    This is common enough there is `defaultPostgresConf` which@@ -273,34 +272,32 @@ The passed in config is inspected and a generated config is created. The final config is built by - @-   generated '<>' extra- @+@+generated '<>' extra+@  Based on the value of 'socketDirectory' a \"postgresql.conf\" is created with: - @-   listen_addresses = '127.0.0.1, ::1'-   unix_socket_directories = \'SOCKET_DIRECTORY\'- @+@+listen_addresses = '127.0.0.1, ::1'+unix_socket_directories = \'SOCKET_DIRECTORY\'+@ -Additionally the @generated@ `Config` also does the following:+Additionally the @generated@ `Config` also:  * Sets a `connectionTimeout` of one minute.-* Logs internal `Event`s.-* Sets the processes to use the standard input and output handles.-* Sets the 'dataDirectory' to file path generated from 'dataDirectory'.+* Redirects output to @\/dev\/null@.  All of these values can be overrided by the @extra@ config.  The returned 'DB' requires cleanup. `startConfig` should be used with a `bracket` and 'stop', e.g. - @-   `withConfig` :: `Config` -> (`DB` -> IO a) -> IO (Either `StartError` a)-   'withConfig' plan f = `bracket` (`startConfig` plan) (either mempty `stop`) $-      either (pure . Left) (fmap Right . f)- @+@+`withConfig` :: `Config` -> (`DB` -> IO a) -> IO (Either `StartError` a)+'withConfig' plan f = `bracket` (`startConfig` plan) (either mempty `stop`) $+  either (pure . Left) (fmap Right . f)+@  or just use 'withConfig'. If you are calling 'startConfig' you probably want 'withConfig' anyway.@@ -361,16 +358,6 @@         completePlanPostgres   bracketOnError startAction stopPlan $ \result ->     pure $ db { dbPostgresProcess = result }---- | Reload the configuration file without shutting down. Calls---   @pg_reload_conf()@.------   @since 1.12.0.0-reloadConfig :: DB -> IO ()-reloadConfig db =-  bracket (PG.connectPostgreSQL $ toConnectionString db) PG.close $ \conn ->-    (void :: IO [PG.Only Bool] -> IO ()) $-      PG.query_ conn "SELECT pg_reload_conf()" ------------------------------------------------------------------------------- -- Exception safe interface -------------------------------------------------------------------------------@@ -391,9 +378,9 @@  {-| Default expectation safe interface. Equivalent to - @-   'with' = 'withConfig' 'defaultConfig'- @+@+'with' = 'withConfig' 'defaultConfig'+@  @since 1.21.0.0 -}@@ -527,7 +514,7 @@ Exception safe version of 'setupInitDbCache'. Equivalent to  @-   'withDbCacheConfig' = bracket ('setupInitDbCache' config) 'cleanupInitDbCache'+'withDbCacheConfig' = bracket ('setupInitDbCache' config) 'cleanupInitDbCache' @  @since 1.25.0.0@@ -548,7 +535,7 @@ Here is an example using caching:  @- withDbCache $ \\cache -> do+withDbCache $ \\cache -> do   withCache (cacheConfig cache) $ \\db -> ...   withCache (cacheConfig cache) $ \\db -> ... @@@ -631,7 +618,7 @@ Here is an example with caching and snapshots:  @- withDbCache $ \\cache -> withConfig (cacheConfig cache) $ \\db ->+withDbCache $ \\cache -> withConfig (cacheConfig cache) $ \\db ->   migrate db   withSnapshot Temporary db $ \\snapshot -> do     withConfig (snapshotConfig db) $ \\migratedDb -> ...
src/Database/Postgres/Temp/Internal/Config.hs view
@@ -398,7 +398,6 @@   CPermanent _ -> pure ()   CTemporary filePath -> rmDirIgnoreErrors filePath - -- | Turn a 'Config' into a 'CompletePostgresPlan'. Fails if any --   values are missing. completePostgresPlan :: [(String, String)] -> Config -> Either [String] CompletePostgresPlan@@ -409,7 +408,6 @@       completeProcessConfig envs postgresConfig    pure CompletePostgresPlan {..}-  flattenConfig :: [(String, String)] -> String flattenConfig = unlines . map (\(x, y) -> x <> "=" <> y) .
src/Database/Postgres/Temp/Internal/Core.hs view
@@ -13,8 +13,6 @@ import qualified Data.ByteString.Char8 as BSC import           Data.Foldable (for_) import           Data.IORef-import           Data.Monoid-import           Data.String import           Data.Typeable import qualified Database.PostgreSQL.Simple as PG import qualified Database.PostgreSQL.Simple.Options as Client@@ -256,25 +254,6 @@   pretty PostgresProcess {..}     =   text "postgresProcessClientOptions:"     <+> prettyOptions postgresProcessClientOptions---- Force all connections to the database to close.--- Called during shutdown as well.-terminateConnections :: Client.Options-> IO ()-terminateConnections options = do-  let theConnectionString = Client.toConnectionString options-        { Client.dbname = pure "template1"-        }-      terminationQuery = fromString $ unlines-        [ "SELECT pg_terminate_backend(pid)"-        , "FROM pg_stat_activity"-        , "WHERE datname=?;"-        ]-  e <- try $ bracket (PG.connectPostgreSQL theConnectionString) PG.close $-    \conn -> PG.query conn terminationQuery-      [getLast $ Client.dbname options]-  case e of-    Left (_ :: IOError) -> pure ()-    Right (_ :: [PG.Only Bool]) -> pure ()  -- | Stop the @postgres@ process after attempting to terminate all the --   connections.
test/Main.hs view
@@ -570,19 +570,6 @@     PG.connectPostgreSQL (toConnectionString db) `shouldThrow`       (\(_ :: IOError) -> True) -  it "reloadConfig works" $ withConfig' defaultConfig $ \db -> do-    let-      dataDir = toDataDirectory db-      expectedDuration = "100ms"-      extraConfig = "log_min_duration_statement='" <> expectedDuration <> "'"-    appendFile (dataDir ++ "/postgresql.conf") $ extraConfig--    reloadConfig db--    withConn db $ \conn -> do-      [PG.Only actualDuration] <- PG.query_ conn "SHOW log_min_duration_statement"-      actualDuration `shouldBe` expectedDuration-   -- Not a great test but don't want to be too rigid   let createdbPlan = optionsToDefaultConfig mempty { Client.dbname = pure "newdb" }   it "prettyPrintConfig seems to work" $ do@@ -641,7 +628,9 @@        createDirectory walArchiveDir -      reloadConfig db+      bracket (PG.connectPostgreSQL $ toConnectionString db) PG.close $ \conn ->+        (void :: IO [PG.Only Bool] -> IO ()) $+          PG.query_ conn "SELECT pg_reload_conf()"        let Just port = getLast $ Client.port $ postgresProcessClientOptions dbPostgresProcess           Just host = getLast $ Client.host $ postgresProcessClientOptions dbPostgresProcess
tmp-postgres.cabal view
@@ -1,5 +1,5 @@ name:                tmp-postgres-version:             1.26.0.0+version:             1.27.0.0 synopsis: Start and stop a temporary postgres description: Start and stop a temporary postgres. See README.md homepage:            https://github.com/jfischoff/tmp-postgres#readme