tmp-postgres 1.10.0.0 → 1.11.0.0
raw patch · 6 files changed
+113/−79 lines, 6 files
Files
- CHANGELOG.md +4/−0
- src/Database/Postgres/Temp.hs +6/−51
- src/Database/Postgres/Temp/Config.hs +66/−0
- src/Database/Postgres/Temp/Internal.hs +21/−19
- src/Database/Postgres/Temp/Internal/Config.hs +14/−8
- tmp-postgres.cabal +2/−1
CHANGELOG.md view
@@ -25,3 +25,7 @@ Add temporaryDirectoryL #31 A silent defaults #20 Include stderr in errors++1.11.0.0+ #90 Extend generated config to provide default Handles and connection timeout.+ #81 Create public Config module for better documentation organization.
src/Database/Postgres/Temp.hs view
@@ -62,11 +62,13 @@ , toConnectionOptions , toDataDirectory , toTemporaryDirectory- -- ** 'DB' mutators+ -- ** 'DB' modifiers , makeDataDirPermanent , reloadConfig -- ** 'DB' debugging , prettyPrintDB+ -- * Errors+ , StartError (..) -- * Configuration -- ** Defaults , defaultConfig@@ -77,57 +79,10 @@ -- ** Custom Config builder helpers , optionsToDefaultConfig -- ** 'Config'- , Config (..)- , prettyPrintConfig- -- *** 'Config' Lenses- , planL- , socketClassL- , dataDirectoryL- , portL- , connectionTimeoutL- -- ** 'Plan'- , Plan (..)- -- *** 'Plan' lenses- , postgresConfigFileL- , createDbConfigL- , dataDirectoryStringL- , initDbConfigL- , loggerL- , postgresPlanL- -- ** 'PostgresPlan'- , PostgresPlan (..)- -- *** 'PostgresPlan' lenses- , connectionOptionsL- , postgresConfigL- -- ** 'ProcessConfig'- , ProcessConfig (..)- -- *** 'ProcessConfig' Lenses- , commandLineL- , environmentVariablesL- , stdErrL- , stdInL- , stdOutL- -- ** 'EnvironmentVariables'- , EnvironmentVariables (..)- -- *** 'EnvironmentVariables' Lenses- , inheritL- , specificL- -- ** 'CommandLineArgs'- , CommandLineArgs (..)- -- *** 'CommandLineArgs' Lenses- , indexBasedL- , keyBasedL- -- ** 'DirectoryType'- , DirectoryType (..)- -- ** 'SocketClass'- , SocketClass (..)- -- ** 'Logger'- , Logger- -- * Internal events passed to the 'logger' .- , Event (..)- -- * Errors- , StartError (..)+ , 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/Config.hs view
@@ -0,0 +1,66 @@+{-| This module provides types and functions for combining partial+ configs into a complete configs to ultimately make a 'CompletePlan'.++ This module has two classes of types.++ Types like 'ProcessConfig' that could be used by any+ library that needs to combine process options.++ Finally it has types and functions for creating 'CompletePlan's that+ use temporary resources. This is used to create the default+ behavior of 'Database.Postgres.Temp.startConfig' and related+ functions.+|-}+module Database.Postgres.Temp.Config+ ( Config (..)+ , prettyPrintConfig+ -- *** 'Config' Lenses+ , planL+ , socketClassL+ , dataDirectoryL+ , portL+ , connectionTimeoutL+ -- ** 'Plan'+ , Plan (..)+ -- *** 'Plan' lenses+ , postgresConfigFileL+ , createDbConfigL+ , dataDirectoryStringL+ , initDbConfigL+ , loggerL+ , postgresPlanL+ -- ** 'PostgresPlan'+ , PostgresPlan (..)+ -- *** 'PostgresPlan' lenses+ , connectionOptionsL+ , postgresConfigL+ -- ** 'ProcessConfig'+ , ProcessConfig (..)+ -- *** 'ProcessConfig' Lenses+ , commandLineL+ , environmentVariablesL+ , stdErrL+ , stdInL+ , stdOutL+ -- ** 'EnvironmentVariables'+ , EnvironmentVariables (..)+ -- *** 'EnvironmentVariables' Lenses+ , inheritL+ , specificL+ -- ** 'CommandLineArgs'+ , CommandLineArgs (..)+ -- *** 'CommandLineArgs' Lenses+ , indexBasedL+ , keyBasedL+ -- ** 'DirectoryType'+ , DirectoryType (..)+ -- ** 'SocketClass'+ , SocketClass (..)+ -- ** 'Logger'+ , Logger+ -- * Internal events passed to the 'logger' .+ , Event (..)+ ) where+import Database.Postgres.Temp.Internal.Config+import Database.Postgres.Temp.Internal.Core+import Database.Postgres.Temp.Internal
src/Database/Postgres/Temp/Internal.hs view
@@ -122,17 +122,15 @@ your @postgres@ might start and run faster if you use 'defaultConfig'. -'defaultConfig' also sets the 'initDbConfig' to-'pure' 'standardProcessConfig' and-'postgresConfig' to 'standardProcessConfig'.+The 'defaultConfig' also disables the logging of internal 'Event's. To append additional lines to \"postgresql.conf\" file create a custom 'Config' like the following. @ custom = defaultConfig <> mempty- { plan = mempty- { postgresConfigFile =+ { 'plan' = mempty+ { 'postgresConfigFile' = [ "wal_level = replica" , "archive_mode = on" , "max_wal_senders = 2"@@ -146,7 +144,7 @@ Or using the provided lenses and your favorite lens library @- custom = defaultConfig & 'planL' . 'postgresConfigFile' <>~+ custom = defaultConfig & 'planL' . 'postgresConfigFile' '<>~' [ "wal_level = replica" , "archive_mode = on" , "max_wal_senders = 2"@@ -164,18 +162,14 @@ defaultConfig :: Config defaultConfig = mempty { plan = mempty- { connectionTimeout = pure (60 * 1000000) -- 1 minute- , logger = pure mempty+ { logger = pure mempty , postgresConfigFile = defaultPostgresConfig , createDbConfig = Nothing- , initDbConfig = pure standardProcessConfig+ , initDbConfig = pure mempty { commandLine = mempty- { keyBased = Map.singleton "--no-sync" Nothing- }- }- , postgresPlan = mempty- { postgresConfig = standardProcessConfig+ { keyBased = Map.singleton "--no-sync" Nothing }+ } } } @@ -184,9 +178,9 @@ \"postgresql.conf\" lines. Equivalent to @-defaultPostgresConf extra = defaultConfig <> mempty- { plan = mempty- { postgresConfigFile = extra+'defaultPostgresConf' extra = 'defaultConfig' <> mempty+ { 'plan' = mempty+ { 'postgresConfigFile' = extra } } @@@ -194,7 +188,7 @@ or with lenses @-defaultPostgresConf extra = defaultConfig & planL . postgresConfigFile <>~ extra+'defaultPostgresConf' extra = 'defaultConfig' & 'planL' . 'postgresConfigFile' '<>~' extra @ -}@@ -205,7 +199,7 @@ } } --- | The same as 'defaultConfig' but all the handles are set to \"/dev/null\".+-- | The same as 'defaultConfig' but all the handles are set to \"\/dev\/null\". -- See 'silentProcessConfig' as well. silentConfig :: Config silentConfig = defaultConfig <> mempty@@ -254,6 +248,14 @@ @ are added.++Additionally the @generated@ `Config` also does the following:+* Sets a `connectionTimeout` of one minute.+* Logs internal `Event`s.+* Sets the processes to use the standard input and output handles.+* Sets the 'dataDirectoryString' to file path generated from 'dataDirectory'++All of these values can be overrided by the @extra@ config. -} startConfig :: Config
src/Database/Postgres/Temp/Internal/Config.hs view
@@ -195,7 +195,7 @@ devNull = unsafePerformIO (openFile "/dev/null" WriteMode) {-# NOINLINE devNull #-} --- | 'silentProcessConfig' sets the handles to \"/dev/null\" and+-- | 'silentProcessConfig' sets the handles to \"\/dev\/null\" and -- inherits the environment variables from the calling process silentProcessConfig :: ProcessConfig silentProcessConfig = mempty@@ -347,8 +347,12 @@ CIpSocket ip -> ip CUnixSocket dir -> toFilePath dir --- | The monoidial version of 'CompleteSocketClass'. Used to combine overrides with--- defaults when creating a 'CompleteSocketClass'. The monoid instance and combines the+-- | 'SocketClass' is used to specify how @postgres@ should listen for connections+-- The two main options are a `IpSocket` which takes a hostname or IP address.+-- if not is given the default it "127.0.0.1". Alternatively one can+-- specify 'UnixSocket' for a UNIX domain socket. If a directory is+-- specified the socket will live in that folder. Otherwise a+-- temporary folder will get created for the socket. data SocketClass = IpSocket (Last String) -- ^ The monoid for combining IP address configuration@@ -370,7 +374,7 @@ (UnixSocket _, a@(IpSocket _)) -> a (UnixSocket a, UnixSocket b) -> UnixSocket $ a <> b --- | Treats 'UnixSocket mempty' as 'mempty'+-- | Treats 'UnixSocket' 'mempty' as 'mempty' instance Monoid SocketClass where mempty = UnixSocket mempty @@ -505,7 +509,7 @@ -- ^ Override the default 'CompleteSocketClass' by setting this. , dataDirectory :: DirectoryType -- ^ Override the default temporary data directory by passing in- -- 'CPermanent DIRECTORY'+ -- 'Permanent' @DIRECTORY@ , port :: Last (Maybe Int) -- ^ A monoid for using an existing port (via 'Just' @PORT_NUMBER@) or -- requesting a free port (via a 'Nothing')@@ -554,8 +558,10 @@ toPlan makeInitDb makeCreateDb port socketClass dataDirectoryString = mempty { postgresConfigFile = socketClassToConfig socketClass , dataDirectoryString = pure dataDirectoryString+ , connectionTimeout = pure (60 * 1000000) -- 1 minute+ , logger = pure print , postgresPlan = mempty- { postgresConfig = mempty+ { postgresConfig = standardProcessConfig { commandLine = mempty { keyBased = Map.fromList [ ("-p", Just $ show port)@@ -570,7 +576,7 @@ } } , createDbConfig = if makeCreateDb- then pure $ mempty+ then pure $ standardProcessConfig { commandLine = mempty { keyBased = Map.fromList $ socketClassToHostFlag socketClass <>@@ -579,7 +585,7 @@ } else Nothing , initDbConfig = if makeInitDb- then pure $ mempty+ then pure $ standardProcessConfig { commandLine = mempty { keyBased = Map.fromList [("--pgdata=", Just dataDirectoryString)]
tmp-postgres.cabal view
@@ -1,5 +1,5 @@ name: tmp-postgres-version: 1.10.0.0+version: 1.11.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@@ -17,6 +17,7 @@ library hs-source-dirs: src exposed-modules: Database.Postgres.Temp+ , Database.Postgres.Temp.Config , Database.Postgres.Temp.Internal , Database.Postgres.Temp.Internal.Core , Database.Postgres.Temp.Internal.Config