packages feed

tmp-postgres 1.21.0.0 → 1.21.1.0

raw patch · 8 files changed

+136/−105 lines, 8 files

Files

CHANGELOG.md view
@@ -1,5 +1,10 @@ Changelog for tmp-postgres +1.21.1.0+  #135 Add defaultConfig_9_3_10+  #170 Expose cacheResourcesToConfig+  #169 Documentation Reorg+ 1.21.0.0   #165 Make silent the default. 
benchmark/Main.hs view
@@ -46,16 +46,16 @@ setupCache :: IO CacheResources setupCache = do   cacheInfo <- setupInitDbCache defaultCacheConfig-  void (withConfig (defaultConfig <> toCacheConfig cacheInfo) (const $ pure ()))+  void (withConfig (defaultConfig <> cacheResourcesToConfig cacheInfo) (const $ pure ()))   pure cacheInfo  setupWithCache :: (Config -> Benchmark) -> Benchmark-setupWithCache f = envWithCleanup setupCache cleanupInitDbCache $ f . (defaultConfig <>) . toCacheConfig+setupWithCache f = envWithCleanup setupCache cleanupInitDbCache $ f . (defaultConfig <>) . cacheResourcesToConfig  setupCacheAndSP :: IO (CacheResources, Snapshot, Once Config) setupCacheAndSP = do   cacheInfo <- setupCache-  let cacheConfig = defaultConfig <> toCacheConfig cacheInfo+  let cacheConfig = defaultConfig <> cacheResourcesToConfig cacheInfo   sp <- either throwIO pure <=< withConfig cacheConfig $ \db -> do     migrateDb db     either throwIO pure =<< takeSnapshot Temporary db
src/Database/Postgres/Temp.hs view
@@ -46,61 +46,66 @@  module Database.Postgres.Temp   (-  -- * Exception safe interface+  -- * Start and Stop @postgres@+  -- ** Exception safe interface     with   , withConfig   , withRestart-  , withDbCache-  , withDbCacheConfig-  , withSnapshot-  -- * Separate start and stop interface.+  -- *** Configuration+  -- *** Defaults+  , defaultConfig+  , defaultConfig_9_3_10+  , defaultPostgresConf+  , verboseConfig+  -- *** Custom Config builder helpers+  , optionsToDefaultConfig+  -- *** General Configuration Types+  , module Database.Postgres.Temp.Config+  -- ** Main resource handle+  , DB+  -- *** 'DB' accessors+  , toConnectionString+  , toConnectionOptions+  , toDataDirectory+  , toTemporaryDirectory+  -- *** 'DB' modifiers+  , makeDataDirPermanent+  , reloadConfig+  -- *** 'DB' debugging+  , prettyPrintDB+  -- ** Separate start and stop interface.   , start   , startConfig   , stop   , restart   , stopPostgres   , stopPostgresGracefully+  -- * Making Starting Faster+  -- ** @initdb@ Data Directory Caching+  -- *** Exception safe interface+  , withDbCache+  , withDbCacheConfig+  -- *** @initdb@ cache configuration.+  , CacheConfig (..)+  , defaultCacheConfig+  -- *** @initdb@ cache handle.+  , CacheResources+  , cacheResourcesToConfig+  -- *** Separate start and stop interface.   , setupInitDbCache   , cleanupInitDbCache+  -- ** Data Directory Snapshots+  -- *** Exception safe interface+  , withSnapshot+  -- *** 'Snapshot' handle+  , Snapshot+  , snapshotConfig+  -- *** Separate start and stop interface.   , takeSnapshot   , cleanupSnapshot-  -- * Main resource handle-  , DB-  -- ** 'DB' accessors-  , toConnectionString-  , toConnectionOptions-  , toDataDirectory-  , toTemporaryDirectory-  -- ** 'DB' modifiers-  , makeDataDirPermanent-  , reloadConfig-  -- ** 'DB' debugging-  , prettyPrintDB-  -- ** 'Snapshot' handle-  , Snapshot-  -- ** @initdb@ cache handle-  , CacheResources   -- * Errors   , StartError (..)-  -- * Configuration-  -- ** Defaults-  , defaultConfig-  , defaultPostgresConf-  , standardProcessConfig-  , verboseConfig-  , silentProcessConfig-  , defaultCacheConfig-  , snapshotConfig-  -- ** Custom Config builder helpers-  , optionsToDefaultConfig-  -- ** Configuration Types-  -- *** 'CacheConfig'-  , CacheConfig (..)-  -- *** General Configuration Types-  , module Database.Postgres.Temp.Config   ) where import Database.Postgres.Temp.Internal import Database.Postgres.Temp.Internal.Core import Database.Postgres.Temp.Config-import Database.Postgres.Temp.Internal.Config-  (standardProcessConfig, silentProcessConfig)
src/Database/Postgres/Temp/Internal.hs view
@@ -96,19 +96,32 @@ ------------------------------------------------------------------------------- -- Life Cycle Management ---------------------------------------------------------------------------------- | Default postgres options------   @since 1.21.0.0-verbosePostgresConfig :: [String]-verbosePostgresConfig =+{-|+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+ @++@since 1.21.0.0+-}+fastPostgresConfig :: [String]+fastPostgresConfig =   [ "shared_buffers = 12MB"   , "fsync = off"   , "synchronous_commit = off"   , "full_page_writes = off"-  , "log_min_duration_statement = 0"-  , "log_connections = on"-  , "log_disconnections = on"-  , "client_min_messages = WARNING"+  , "log_min_messages = PANIC"+  , "log_min_error_statement = PANIC"+  , "log_statement = none"+  , "client_min_messages = ERROR"   ]  {-|@@ -193,6 +206,27 @@   }  {-|+Default configuration for PostgreSQL versions 9.3 and greater but less+than 10.++If you get an error that \"--no-sync\" is an invalid parameter then you+should use this config.++@since 1.21.1.0+-}+defaultConfig_9_3_10 :: Config+defaultConfig_9_3_10 = mempty+  { plan = mempty+    { postgresConfigFile = fastPostgresConfig+    , initDbConfig = pure mempty+      { commandLine = mempty+        { keyBased = Map.singleton "--nosync" Nothing+        }+      }+    }+  }++{-| 'mappend' the 'defaultConfig' with a 'Config' that provides additional    \"postgresql.conf\" lines. Equivalent to: @@ -219,33 +253,19 @@     }   } --{-|-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- @--@since 1.21.0.0--}-fastPostgresConfig :: [String]-fastPostgresConfig =+-- | Default postgres options+--+--   @since 1.21.0.0+verbosePostgresConfig :: [String]+verbosePostgresConfig =   [ "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"+  , "log_min_duration_statement = 0"+  , "log_connections = on"+  , "log_disconnections = on"+  , "client_min_messages = WARNING"   ]  {-|@@ -548,10 +568,10 @@ {-| Helper to make a 'Config' out of caching info. -@since 1.20.0.0+@since 1.22.0.0 -}-toCacheConfig :: CacheResources -> Config-toCacheConfig CacheResources {..} = mempty+cacheResourcesToConfig :: CacheResources -> Config+cacheResourcesToConfig CacheResources {..} = mempty   { initDbCache = pure $ pure       (cacheResourcesCow, toFilePath cacheResourcesDirectory)   }
src/Database/Postgres/Temp/Internal/Config.hs view
@@ -595,7 +595,7 @@     <> indent 2 (pretty destinationDirectory)     <> hardline     <> text "useCopyOnWrite:"-    <+> (pretty useCopyOnWrite)+    <+> pretty useCopyOnWrite  completeCopyDirectory   :: FilePath@@ -654,7 +654,7 @@         '-':'-':'p':'g':'d':'a':'t':'a':'=':theDir -> theDir         _ -> error "splitDataDirectory not possible" -      filteredEnvs = filter (not . ("PGDATA"==) . fst) $+      filteredEnvs = filter (("PGDATA" /=) . fst) $         completeProcessConfigEnvVars old        clearedConfig = old@@ -686,7 +686,7 @@       cachedDataDirectory = cachePath <> "/data"      theInitDbPlan <- doesDirectoryExist cachePath >>= \case-      True -> pure $ Nothing+      True -> pure Nothing       False -> do         createDirectoryIfMissing True cachePath         writeFile (cachePath <> "/commandLine.log") theCommandLine@@ -740,7 +740,7 @@   , createDbConfig = if makeCreateDb       then pure $ silentProcessConfig         { commandLine = mempty-            { keyBased = Map.fromList $+            { keyBased = Map.fromList                 [ ("-h", Just socketDirectory)                 , ("-p ", Just $ show port)                 ]@@ -1058,7 +1058,7 @@ -- --   @since 1.12.0.0 postgresConfigFileL :: Lens' Plan [String]-postgresConfigFileL f (plan@Plan{..})+postgresConfigFileL f plan@Plan{..}   = fmap (\x -> plan { postgresConfigFile = x })       (f postgresConfigFile) {-# INLINE postgresConfigFileL #-}@@ -1068,7 +1068,7 @@ --   @since 1.17.0.0 createDbConfigL ::   Lens' Plan (Accum ProcessConfig)-createDbConfigL f (plan@Plan{..})+createDbConfigL f plan@Plan{..}   = fmap (\x -> plan { createDbConfig = x })       (f createDbConfig) {-# INLINE createDbConfigL #-}@@ -1077,7 +1077,7 @@ -- --   @since 1.12.0.0 dataDirectoryStringL :: Lens' Plan (Last String)-dataDirectoryStringL f (plan@Plan{..})+dataDirectoryStringL f plan@Plan{..}   = fmap (\x -> plan { dataDirectoryString = x })       (f dataDirectoryString) {-# INLINE dataDirectoryStringL #-}@@ -1086,7 +1086,7 @@ -- --   @since 1.16.0.0 copyConfigL :: Lens' Plan (Last (Maybe CopyDirectoryCommand))-copyConfigL f (plan@Plan{..})+copyConfigL f plan@Plan{..}   = fmap (\x -> plan { copyConfig = x })       (f copyConfig) {-# INLINE copyConfigL #-}@@ -1095,7 +1095,7 @@ -- --   @since 1.12.0.0 initDbConfigL :: Lens' Plan (Accum ProcessConfig)-initDbConfigL f (plan@Plan{..})+initDbConfigL f plan@Plan{..}   = fmap (\x -> plan { initDbConfig = x })       (f initDbConfig) {-# INLINE initDbConfigL #-}@@ -1104,7 +1104,7 @@ -- --   @since 1.12.0.0 loggerL :: Lens' Plan (Last Logger)-loggerL f (plan@Plan{..})+loggerL f plan@Plan{..}   = fmap (\x -> plan { logger = x })       (f logger) {-# INLINE loggerL #-}@@ -1113,7 +1113,7 @@ -- --   @since 1.12.0.0 postgresPlanL :: Lens' Plan PostgresPlan-postgresPlanL f (plan@Plan{..})+postgresPlanL f plan@Plan{..}   = fmap (\x -> plan { postgresPlan = x })       (f postgresPlan) {-# INLINE postgresPlanL #-}@@ -1122,7 +1122,7 @@ -- --   @since 1.12.0.0 connectionTimeoutL :: Lens' Plan (Last Int)-connectionTimeoutL f (plan@Plan{..})+connectionTimeoutL f plan@Plan{..}   = fmap (\x -> plan { connectionTimeout = x })       (f connectionTimeout) {-# INLINE connectionTimeoutL #-}@@ -1131,7 +1131,7 @@ -- --   @since 1.12.0.0 resourcesDataDirL :: Lens' Resources CompleteDirectoryType-resourcesDataDirL f (resources@Resources {..})+resourcesDataDirL f resources@Resources {..}   = fmap (\x -> resources { resourcesDataDir = x })       (f resourcesDataDir) {-# INLINE resourcesDataDirL #-}@@ -1140,7 +1140,7 @@ -- --   @since 1.12.0.0 resourcesPlanL :: Lens' Resources CompletePlan-resourcesPlanL f (resources@Resources {..})+resourcesPlanL f resources@Resources {..}   = fmap (\x -> resources { resourcesPlan = x })       (f resourcesPlan) {-# INLINE resourcesPlanL #-}@@ -1149,7 +1149,7 @@ -- --   @since 1.15.0.0 resourcesSocketDirectoryL :: Lens' Resources CompleteDirectoryType-resourcesSocketDirectoryL f (resources@Resources {..})+resourcesSocketDirectoryL f resources@Resources {..}   = fmap (\x -> resources { resourcesSocketDirectory = x })       (f resourcesSocketDirectory) {-# INLINE resourcesSocketDirectoryL #-}@@ -1158,7 +1158,7 @@ -- --   @since 1.12.0.0 dataDirectoryL :: Lens' Config DirectoryType-dataDirectoryL f (config@Config{..})+dataDirectoryL f config@Config{..}   = fmap (\ x -> config { dataDirectory = x } )       (f dataDirectory) {-# INLINE dataDirectoryL #-}@@ -1167,7 +1167,7 @@ -- --   @since 1.12.0.0 planL :: Lens' Config Plan-planL f (config@Config{..})+planL f config@Config{..}   = fmap (\ x -> config { plan = x } )       (f plan) {-# INLINE planL #-}@@ -1176,7 +1176,7 @@ -- --   @since 1.12.0.0 portL :: Lens' Config (Last (Maybe Int))-portL f (config@Config{..})+portL f config@Config{..}   = fmap (\ x -> config { port = x } )       (f port) {-# INLINE portL #-}@@ -1185,7 +1185,7 @@ -- --   @since 1.12.0.0 socketDirectoryL :: Lens' Config DirectoryType-socketDirectoryL f (config@Config{..})+socketDirectoryL f config@Config{..}   = fmap (\ x -> config { socketDirectory = x } )       (f socketDirectory) {-# INLINE socketDirectoryL #-}@@ -1194,7 +1194,7 @@ -- --   @since 1.12.0.0 temporaryDirectoryL :: Lens' Config (Last FilePath)-temporaryDirectoryL f (config@Config{..})+temporaryDirectoryL f config@Config{..}   = fmap (\ x -> config { temporaryDirectory = x } )       (f temporaryDirectory) {-# INLINE temporaryDirectoryL #-}@@ -1227,7 +1227,7 @@ -- --   @since 1.16.0.0 sourceDirectoryL :: Lens' CopyDirectoryCommand FilePath-sourceDirectoryL f (cmd@CopyDirectoryCommand{..})+sourceDirectoryL f cmd@CopyDirectoryCommand{..}   = fmap (\x -> cmd { sourceDirectory = x })       (f sourceDirectory) {-# INLINE sourceDirectoryL #-}@@ -1236,7 +1236,7 @@ -- --   @since 1.16.0.0 destinationDirectoryL :: Lens' CopyDirectoryCommand (Maybe FilePath)-destinationDirectoryL f (cmd@CopyDirectoryCommand{..})+destinationDirectoryL f cmd@CopyDirectoryCommand{..}   = fmap (\x -> cmd { destinationDirectory = x })       (f destinationDirectory) {-# INLINE destinationDirectoryL #-}@@ -1245,7 +1245,7 @@ -- --   @since 1.16.0.0 useCopyOnWriteL :: Lens' CopyDirectoryCommand Bool-useCopyOnWriteL f (cmd@CopyDirectoryCommand{..})+useCopyOnWriteL f cmd@CopyDirectoryCommand{..}   = fmap (\x -> cmd { useCopyOnWrite = x })       (f useCopyOnWrite) {-# INLINE useCopyOnWriteL #-}
src/Database/Postgres/Temp/Internal/Core.hs view
@@ -324,7 +324,7 @@     <> indent 2 (text copyDirectoryCommandDst)     <> hardline     <> text "copyDirectoryCommandCow:"-    <+> (pretty copyDirectoryCommandCow)+    <+> pretty copyDirectoryCommandCow  executeCopyDirectoryCommand :: CompleteCopyDirectoryCommand -> IO () executeCopyDirectoryCommand CompleteCopyDirectoryCommand {..} = do@@ -426,3 +426,4 @@ -- | Stop the @postgres@ process. See 'stopPostgresProcess' for more details. stopPlan :: PostgresProcess -> IO ExitCode stopPlan = stopPostgresProcess False+
test/Main.hs view
@@ -339,7 +339,7 @@             , cacheUseCopyOnWrite     = True             }       withDbCacheConfig cacheConfig $ \cacheInfo -> do-        withConfig' (config <> toCacheConfig cacheInfo) $ const $ pure ()+        withConfig' (config <> cacheResourcesToConfig cacheInfo) $ const $ pure ()         -- see if there is a cache         tmpFiles <- listDirectory dirPath @@ -365,7 +365,7 @@           xs -> fail $ "expected a single version directory but got " <> show xs          -- add a file to look for later-        withConfig' (config <> toCacheConfig cacheInfo) $ \db -> do+        withConfig' (config <> cacheResourcesToConfig cacheInfo) $ \db -> do           -- see if the file is in the data directory           let theDataDirectory = toDataDirectory db           xs <- listDirectory theDataDirectory@@ -382,7 +382,7 @@    it "withDbCache seems to work" $     withDbCache $ \cacheInfo ->-      either throwIO pure =<< withConfig (defaultConfig <> toCacheConfig cacheInfo) assertConnection+      either throwIO pure =<< withConfig (defaultConfig <> cacheResourcesToConfig cacheInfo) assertConnection  -- -- Error Plans. Can't be combined. Just list them out inline since they can't be combined
tmp-postgres.cabal view
@@ -1,5 +1,5 @@ name:                tmp-postgres-version:             1.21.0.0+version:             1.21.1.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