packages feed

tmp-postgres 1.24.0.0 → 1.25.0.0

raw patch · 6 files changed

+47/−40 lines, 6 files

Files

CHANGELOG.md view
@@ -1,5 +1,8 @@ Changelog for tmp-postgres +1.25.0.0+  #186 Rename CacheResources and cacheResourcesToConfig+ 1.24.0.0   #185 rename makeDataDirPermanent to makeDataDirectoryPermanent @@ -26,7 +29,7 @@  1.21.1.0   #135 Add defaultConfig_9_3_10-  #170 Expose cacheResourcesToConfig+  #170 Expose cacheConfig   #169 Documentation Reorg  1.21.0.0@@ -36,7 +39,7 @@   #164 Documentation fixes.  1.20.0.0-  #144 Make a CacheResources type.+  #144 Make a Cache type.   #162 Make a Snapshot alias.  1.19.0.1
benchmark/Main.hs view
@@ -42,19 +42,19 @@   bracket (PG.connectPostgreSQL theConnectionString) PG.close $     \conn -> void $ PG.execute_ conn "INSERT INTO foo1 (id) VALUES (1)" -setupCache :: IO CacheResources+setupCache :: IO Cache setupCache = do   cacheInfo <- setupInitDbCache defaultCacheConfig-  void (withConfig (defaultConfig <> cacheResourcesToConfig cacheInfo) (const $ pure ()))+  void (withConfig (defaultConfig <> cacheConfig cacheInfo) (const $ pure ()))   pure cacheInfo  setupWithCache :: (Config -> Benchmark) -> Benchmark-setupWithCache f = envWithCleanup setupCache cleanupInitDbCache $ f . (defaultConfig <>) . cacheResourcesToConfig+setupWithCache f = envWithCleanup setupCache cleanupInitDbCache $ f . (defaultConfig <>) . cacheConfig -setupCacheAndSP :: IO (CacheResources, Snapshot, Once Config)+setupCacheAndSP :: IO (Cache, Snapshot, Once Config) setupCacheAndSP = do   cacheInfo <- setupCache-  let cacheConfig = defaultConfig <> cacheResourcesToConfig cacheInfo+  let cacheConfig = defaultConfig <> cacheConfig cacheInfo   sp <- either throwIO pure <=< withConfig cacheConfig $ \db -> do     migrateDb db     either throwIO pure =<< takeSnapshot Temporary db@@ -64,7 +64,7 @@    pure (cacheInfo, sp, Once theConfig) -cleanupCacheAndSP :: (CacheResources, Snapshot, Once Config) -> IO ()+cleanupCacheAndSP :: (Cache, Snapshot, Once Config) -> IO () cleanupCacheAndSP (x, y, _) = cleanupSnapshot y >> cleanupInitDbCache x  setupWithCacheAndSP :: (Config -> Benchmark) -> Benchmark
src/Database/Postgres/Temp.hs view
@@ -66,7 +66,7 @@   , toConnectionOptions   , toDataDirectory   , toTemporaryDirectory-  , toPostgresqlConf+  , toPostgresqlConfigFile   -- *** 'DB' modifiers   , makeDataDirectoryPermanent   , reloadConfig@@ -89,8 +89,8 @@   , CacheConfig (..)   , defaultCacheConfig   -- *** @initdb@ cache handle.-  , CacheResources-  , cacheResourcesToConfig+  , Cache+  , cacheConfig   -- *** Separate start and stop interface.   , setupInitDbCache   , cleanupInitDbCache
src/Database/Postgres/Temp/Internal.hs view
@@ -97,10 +97,10 @@ {-| Get the final @postgresql.conf@ -@since 1.22.0.0+@since 1.25.0.0 -}-toPostgresqlConf :: DB -> String-toPostgresqlConf = completePlanConfig . resourcesPlan . dbResources+toPostgresqlConfigFile :: DB -> String+toPostgresqlConfigFile = completePlanConfig . resourcesPlan . dbResources ------------------------------------------------------------------------------- -- Life Cycle Management -------------------------------------------------------------------------------@@ -432,7 +432,7 @@ {-| Configuration for the @initdb@ data directory cache. -@since 1.20.0.0+@since 1.25.0.0 -} data CacheConfig = CacheConfig   { cacheTemporaryDirectory :: FilePath@@ -452,9 +452,9 @@ {-| A handle to cache temporary resources and configuration. -@since 1.20.0.0+@since 1.25.0.0 -}-data CacheResources = CacheResources+data Cache = Cache   { cacheResourcesCow :: Bool   , cacheResourcesDirectory :: CompleteDirectoryType   } deriving stock (Generic)@@ -487,7 +487,7 @@ 'cacheTemporaryDirectory' to @\/tmp@ (but this is not used when 'Permanent' is set). -@since 1.19.0.0+@since 1.25.0.0 -} defaultCacheConfig :: CacheConfig defaultCacheConfig = CacheConfig@@ -496,10 +496,14 @@   , cacheUseCopyOnWrite = cowCheck   } --- | Setup the @initdb@ cache folder.+{-|+Setup the @initdb@ cache folder.++@since 1.25.0.0+-} setupInitDbCache   :: CacheConfig-  -> IO CacheResources+  -> IO Cache setupInitDbCache CacheConfig {..} =   bracketOnError     (setupDirectoryType@@ -507,14 +511,14 @@       "tmp-postgres-cache"       cacheDirectoryType     )-    cleanupDirectoryType $ pure . CacheResources cacheUseCopyOnWrite+    cleanupDirectoryType $ pure . Cache cacheUseCopyOnWrite  {-| Cleanup the cache directory if it was 'Temporary'. -@since 1.20.0.0+@since 1.25.0.0 -}-cleanupInitDbCache :: CacheResources -> IO ()+cleanupInitDbCache :: Cache -> IO () cleanupInitDbCache = cleanupDirectoryType . cacheResourcesDirectory  {-|@@ -526,12 +530,12 @@    'withDbCacheConfig' = bracket ('setupInitDbCache' config) 'cleanupInitDbCache' @ -@since 1.20.0.0+@since 1.25.0.0 -} withDbCacheConfig   :: CacheConfig   -- ^ Configuration-  -> (CacheResources -> IO a)+  -> (Cache -> IO a)   -- ^ action for which caching is enabled   -> IO a withDbCacheConfig config =@@ -545,22 +549,22 @@  @  withDbCache $ \\cache -> do-  withCache (cacheResourcesToConfig cache) $ \\db -> ...-  withCache (cacheResourcesToConfig cache) $ \\db -> ...+  withCache (cacheConfig cache) $ \\db -> ...+  withCache (cacheConfig cache) $ \\db -> ... @ -@since 1.20.0.0+@since 1.25.0.0 -}-withDbCache :: (CacheResources -> IO a) -> IO a+withDbCache :: (Cache -> IO a) -> IO a withDbCache = withDbCacheConfig defaultCacheConfig  {-| Helper to make a 'Config' out of caching info. -@since 1.22.0.0+@since 1.25.0.0 -}-cacheResourcesToConfig :: CacheResources -> Config-cacheResourcesToConfig CacheResources {..} = mempty+cacheConfig :: Cache -> Config+cacheConfig Cache {..} = mempty   { initDbCache = pure $ pure       (cacheResourcesCow, toFilePath cacheResourcesDirectory)   }@@ -627,7 +631,7 @@ Here is an example with caching and snapshots:  @- withDbCache $ \\cache -> withConfig (cacheResourcesToConfig cache) $ \\db ->+ withDbCache $ \\cache -> withConfig (cacheConfig cache) $ \\db ->   migrate db   withSnapshot Temporary db $ \\snapshot -> do     withConfig (snapshotConfig db) $ \\migratedDb -> ...
test/Main.hs view
@@ -323,13 +323,13 @@   it "withDbCacheConfig actually caches the config and cleans up" $     withTempDirectory "/tmp" "tmp-postgres-cache-test" $ \dirPath -> do       let config = defaultConfig { temporaryDirectory = pure dirPath }-          cacheConfig = CacheConfig+          theCacheConfig = CacheConfig             { cacheTemporaryDirectory = dirPath             , cacheDirectoryType      = Temporary             , cacheUseCopyOnWrite     = True             }-      withDbCacheConfig cacheConfig $ \cacheInfo -> do-        withConfig' (config <> cacheResourcesToConfig cacheInfo) $ const $ pure ()+      withDbCacheConfig theCacheConfig $ \cacheInfo -> do+        withConfig' (config <> cacheConfig cacheInfo) $ const $ pure ()         -- see if there is a cache         tmpFiles <- listDirectory dirPath @@ -355,7 +355,7 @@           xs -> fail $ "expected a single version directory but got " <> show xs          -- add a file to look for later-        withConfig' (config <> cacheResourcesToConfig cacheInfo) $ \db -> do+        withConfig' (config <> cacheConfig cacheInfo) $ \db -> do           -- see if the file is in the data directory           let theDataDirectory = toDataDirectory db           xs <- listDirectory theDataDirectory@@ -372,11 +372,11 @@    it "withDbCache seems to work" $     withDbCache $ \cacheInfo ->-      either throwIO pure =<< withConfig (cacheResourcesToConfig cacheInfo) assertConnection+      either throwIO pure =<< withConfig (cacheConfig cacheInfo) assertConnection    it "postgresql.conf append last wins" $     withConfig' (defaultPostgresConf [("fsync", "on")]) $ \db -> do-      toPostgresqlConf db `shouldContain` "fsync=on"+      toPostgresqlConfigFile db `shouldContain` "fsync=on" -- -- 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.24.0.0+version:             1.25.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