tmp-postgres 1.9.0.1 → 1.9.0.2
raw patch · 6 files changed
+43/−30 lines, 6 files
Files
- CHANGELOG.md +3/−0
- src/Database/Postgres/Temp.hs +13/−12
- src/Database/Postgres/Temp/Internal.hs +12/−6
- src/Database/Postgres/Temp/Internal/Config.hs +13/−10
- src/Database/Postgres/Temp/Internal/Core.hs +1/−1
- tmp-postgres.cabal +1/−1
CHANGELOG.md view
@@ -15,3 +15,6 @@ 1.9.0.1 Documentation fixes++1.9.0.2+ Documentation fixes
src/Database/Postgres/Temp.hs view
@@ -48,31 +48,32 @@ -- * Exception safe interface with , withConfig+ , withRestart -- * Separate start and stop interface. , start , startConfig , stop- , defaultConfig- , defaultPostgresConf- , standardProcessConfig- -- ** Custom Config builder helpers- , optionsToDefaultConfig- -- * Starting and Stopping postgres without removing the temporary directory , restart , stopPostgres- , withRestart- -- * Reloading the config- , reloadConfig -- * Main resource handle , DB- -- ** 'DB' manipulation- , prettyPrintDB+ -- ** 'DB' accessors , toConnectionString , toConnectionOptions , toDataDirectory , toTemporaryDirectory+ -- ** 'DB' mutators , makeDataDirPermanent- -- * Monoidial Configuration Types+ , reloadConfig+ -- ** 'DB' debugging+ , prettyPrintDB+ -- * Configuration+ -- ** Defaults+ , defaultConfig+ , defaultPostgresConf+ , standardProcessConfig+ -- ** Custom Config builder helpers+ , optionsToDefaultConfig -- ** 'Config' , Config (..) , prettyPrintConfig
src/Database/Postgres/Temp/Internal.hs view
@@ -21,8 +21,8 @@ -- | Handle for holding temporary resources, the @postgres@ process handle -- and postgres connection information. The 'DB' also includes the -- final plan used to start @initdb@, @createdb@ and--- @postgres@. See 'toConnectionString' for converting a 'DB' to--- postgresql connection string.+-- @postgres@. See 'toConnectionString' or 'toConnectionOptions'+-- for converting a 'DB' to postgresql connection string. data DB = DB { dbResources :: Resources -- ^ Temporary resources and the final 'CompletePlan'.@@ -98,7 +98,7 @@ via @initdb@ (it's default behavior). It will create a temporary directory for the data and a temporary directory for a unix socket on a random port.- Additionally it will use append the following onto the \"postgresql.conf\"+ Additionally it will use the following \"postgresql.conf\" which is optimized for performance. @@@ -190,6 +190,12 @@ } @ +or with lenses++@+defaultPostgresConf extra = defaultConfig & planL . postgresConfigFile <>~ extra+@+ -} defaultPostgresConf :: [String] -> Config defaultPostgresConf extra = defaultConfig <> mempty@@ -290,18 +296,18 @@ details. Calls 'stop' even in the face of exceptions. -} withConfig :: Config- -- ^ @extraConfiguration@. Combined with the generated 'Config'. See+ -- ^ @extra@. 'Config' combined with the generated 'Config'. See -- 'startConfig' for more info -> (DB -> IO a) -- ^ @action@ continuation -> IO (Either StartError a)-withConfig plan f = bracket (startConfig plan) (either mempty stop) $+withConfig extra f = bracket (startConfig extra) (either mempty stop) $ either (pure . Left) (fmap Right . f) {-| Default expectation safe interface. Equivalent to @- 'with' = withConfig' 'defaultConfig'+ 'with' = 'withConfig' 'defaultConfig' @ -}
src/Database/Postgres/Temp/Internal/Config.hs view
@@ -136,8 +136,7 @@ (Map.toList keyBased) <> takeWhileInSequence (Map.toList indexBased) --- | The monoidial version of 'ProcessConfig'. Used to combine overrides with--- defaults when creating a 'ProcessConfig'.+-- | Process configuration data ProcessConfig = ProcessConfig { environmentVariables :: EnvironmentVariables -- ^ A monoid for combine environment variables or replacing them.@@ -239,9 +238,9 @@ CTemporary x -> CPermanent x x -> x --- | The monoidial version of 'CompleteDirectoryType'. Used to combine overrides with--- defaults when creating a 'CompleteDirectoryType'. The monoid instance treats--- 'Temporary' as 'mempty' and takes the last 'Permanent' value.+-- | Used to specify a 'Temporary' folder that is automatically+-- cleaned up or a 'Permanent' folder which is not+-- automatically cleaned up. data DirectoryType = Permanent FilePath -- ^ A permanent file that should not be generated.@@ -254,11 +253,13 @@ Permanent x -> text "CPermanent" <+> pretty x Temporary -> text "CTemporary" +-- | Takes the last 'Permanent' value. instance Semigroup DirectoryType where x <> y = case (x, y) of (a, Temporary ) -> a (_, a@Permanent {}) -> a +-- | 'Temporary' as 'mempty' instance Monoid DirectoryType where mempty = Temporary @@ -275,7 +276,8 @@ Temporary -> CTemporary <$> createTempDirectory tempDir pat Permanent x -> pure $ CPermanent x --- Either create a temporary directory or do nothing+-- Remove a temporary directory and ignore errors+-- about it not being there. rmDirIgnoreErrors :: FilePath -> IO () rmDirIgnoreErrors mainDir = do let ignoreDirIsMissing e@@ -329,8 +331,7 @@ CUnixSocket dir -> toFilePath dir -- | The monoidial version of 'CompleteSocketClass'. Used to combine overrides with--- defaults when creating a 'CompleteSocketClass'. The monoid instance treats--- 'UnixSocket mempty' as 'mempty' and combines the+-- defaults when creating a 'CompleteSocketClass'. The monoid instance and combines the data SocketClass = IpSocket (Last String) -- ^ The monoid for combining IP address configuration@@ -343,6 +344,8 @@ IpSocket x -> "CIpSocket:" <+> pretty (getLast x) UnixSocket x -> "CUnixSocket" <+> pretty x +-- | Last 'IpSocket' wins. 'UnixSocket' 'DirectoryType' as+-- 'mappend'ed together. instance Semigroup SocketClass where x <> y = case (x, y) of (IpSocket a, IpSocket b) -> IpSocket $ a <> b@@ -350,6 +353,7 @@ (UnixSocket _, a@(IpSocket _)) -> a (UnixSocket a, UnixSocket b) -> UnixSocket $ a <> b +-- | Treats 'UnixSocket mempty' as 'mempty' instance Monoid SocketClass where mempty = UnixSocket mempty @@ -409,8 +413,7 @@ ------------------------------------------------------------------------------- -- Plan ---------------------------------------------------------------------------------- | The monoidial version of 'CompletePlan'. Used to combine overrides with defaults--- when creating a plan.+-- | Describe how to run @initdb@, @createdb@ and @postgres@ data Plan = Plan { logger :: Last Logger , initDbConfig :: Maybe ProcessConfig
src/Database/Postgres/Temp/Internal/Core.hs view
@@ -33,7 +33,7 @@ | StartPostgres -- ^ The second event. Postgres is about to get called | WaitForDB- -- ^ The third event. Postgres started. We are not about to+ -- ^ The third event. Postgres started. We are now about to -- setup a reconnect loop (racing with a process checker) | TryToConnect -- ^ The fourth event and (possibly all subsequent events).
tmp-postgres.cabal view
@@ -1,5 +1,5 @@ name: tmp-postgres-version: 1.9.0.1+version: 1.9.0.2 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