-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Start and stop a temporary postgres -- -- See README.md @package tmp-postgres @version 1.7.1.0 -- | This module provides the low level functionality for running -- initdb, postgres and createdb to make a -- database. -- -- See startPlan for more details. module Database.Postgres.Temp.Internal.Core -- | Internal events for debugging data Event StartPostgres :: Event WaitForDB :: Event StartPlan :: String -> Event TryToConnect :: Event -- | A list of failures that can occur when starting. This is not and -- exhaustive list but covers the errors that the system catches for the -- user. data StartError -- | postgres failed before a connection succeeded. Most likely -- this is due to invalid configuration StartPostgresFailed :: ExitCode -> StartError -- | initdb failed. This can be from invalid configuration or -- using a non-empty data directory InitDbFailed :: ExitCode -> StartError -- | createdb failed. This can be from invalid configuration or -- the database might already exist. CreateDbFailed :: ExitCode -> StartError -- | The PartialPlan was missing info and a complete Plan -- could not be created. CompletePlanFailed :: String -> [String] -> StartError -- | A way to log internal Events type Logger = Event -> IO () -- | postgres is not ready until we are able to successfully -- connect. waitForDB attempts to connect over and over again and -- returns after the first successful connection. waitForDB :: Logger -> Options -> IO () -- | ProcessConfig contains the configuration necessary for starting -- a process. It is essentially a stripped down CreateProcess. data ProcessConfig ProcessConfig :: [(String, String)] -> [String] -> Handle -> Handle -> Handle -> ProcessConfig -- | Environment variables [processConfigEnvVars] :: ProcessConfig -> [(String, String)] -- | Command line arguements [processConfigCmdLine] :: ProcessConfig -> [String] -- | The Handle for standard input [processConfigStdIn] :: ProcessConfig -> Handle -- | The Handle for standard output [processConfigStdOut] :: ProcessConfig -> Handle -- | The Handle for standard error [processConfigStdErr] :: ProcessConfig -> Handle -- | Start a process interactively and return the ProcessHandle startProcess :: String -> ProcessConfig -> IO ProcessHandle -- | Stop a ProcessHandle. An alias for waitForProcess stopProcess :: ProcessHandle -> IO ExitCode -- | Start a process and block until it finishes return the -- ExitCode. executeProcess :: String -> ProcessConfig -> IO ExitCode -- | PostgresPlan is used be startPostgresProcess to start -- the postgres and then attempt to connect to it. data PostgresPlan PostgresPlan :: ProcessConfig -> Options -> PostgresPlan -- | The process config for postgres [postgresPlanProcessConfig] :: PostgresPlan -> ProcessConfig -- | Connection options. Used to verify that postgres is ready. [postgresPlanClientOptions] :: PostgresPlan -> Options -- | The output of calling startPostgresProcess. data PostgresProcess PostgresProcess :: Options -> ProcessHandle -> PostgresProcess -- | Connection options [postgresProcessClientOptions] :: PostgresProcess -> Options -- | postgres process handle [postgresProcessHandle] :: PostgresProcess -> ProcessHandle -- | Stop the postgres process after attempting to terminate all -- the connections. stopPostgresProcess :: PostgresProcess -> IO ExitCode -- | Start the postgres process and block until a successful -- connection occurs. A separate thread we continously check to see if -- the postgres process has crashed. startPostgresProcess :: Logger -> PostgresPlan -> IO PostgresProcess -- | Plan is the low level configuration necessary for creating a -- database starting postgres and creating a database. There is -- no validation done on the Plan. It is recommend that one use -- the higher level functions such as start which will generate -- plans that are valid. Plans are used internally but are exposed -- if the higher level plan generation is not sufficent. data Plan Plan :: Logger -> Maybe ProcessConfig -> Maybe ProcessConfig -> PostgresPlan -> String -> FilePath -> Plan [planLogger] :: Plan -> Logger [planInitDb] :: Plan -> Maybe ProcessConfig [planCreateDb] :: Plan -> Maybe ProcessConfig [planPostgres] :: Plan -> PostgresPlan [planConfig] :: Plan -> String [planDataDirectory] :: Plan -> FilePath -- | startPlan optionally calls initdb, optionally calls -- createdb and unconditionally calls postgres. -- Additionally it writes a "postgresql.conf" and does not return until -- the postgres process is ready. See -- startPostgresProcess for more details. startPlan :: Plan -> IO PostgresProcess -- | Stop the postgres process. See stopPostgresProcess for -- more details. stopPlan :: PostgresProcess -> IO ExitCode instance GHC.Classes.Ord Database.Postgres.Temp.Internal.Core.StartError instance GHC.Classes.Eq Database.Postgres.Temp.Internal.Core.StartError instance GHC.Show.Show Database.Postgres.Temp.Internal.Core.StartError instance GHC.Classes.Ord Database.Postgres.Temp.Internal.Core.Event instance GHC.Classes.Eq Database.Postgres.Temp.Internal.Core.Event instance GHC.Show.Show Database.Postgres.Temp.Internal.Core.Event instance Text.PrettyPrint.ANSI.Leijen.Internal.Pretty Database.Postgres.Temp.Internal.Core.Plan instance Text.PrettyPrint.ANSI.Leijen.Internal.Pretty Database.Postgres.Temp.Internal.Core.PostgresProcess instance Text.PrettyPrint.ANSI.Leijen.Internal.Pretty Database.Postgres.Temp.Internal.Core.PostgresPlan instance Text.PrettyPrint.ANSI.Leijen.Internal.Pretty Database.Postgres.Temp.Internal.Core.ProcessConfig instance GHC.Exception.Type.Exception Database.Postgres.Temp.Internal.Core.StartError -- | This module provides types and functions for combining partial configs -- into a complete configs to ultimately make a Plan. -- -- This module has two classes of types. -- -- Types like PartialProcessConfig that could be used by any -- library that needs to combine process options. -- -- Finally it has types and functions for creating Plans that use -- temporary resources. This is used to create the default behavior of -- startConfig and related functions. | module Database.Postgres.Temp.Internal.Partial -- | The environment variables can be declared to inherit from the running -- process or they can be specifically added. data PartialEnvVars PartialEnvVars :: Last Bool -> Map String String -> PartialEnvVars [partialEnvVarsInherit] :: PartialEnvVars -> Last Bool [partialEnvVarsSpecific] :: PartialEnvVars -> Map String String -- | Combine the current environment (if indicated by -- partialEnvVarsInherit) with partialEnvVarsSpecific completePartialEnvVars :: [(String, String)] -> PartialEnvVars -> Either [String] [(String, String)] -- | A type to help combine command line arguments. data PartialCommandLineArgs PartialCommandLineArgs :: Map String (Maybe String) -> Map Int String -> PartialCommandLineArgs -- | Arguments of the form -h foo, --host=foo and -- --switch. The key is mappended with value so the key -- should include the space or equals (as shown in the first two examples -- respectively). The Dual monoid is used so the last key wins. [partialCommandLineArgsKeyBased] :: PartialCommandLineArgs -> Map String (Maybe String) -- | Arguments that appear at the end of the key based arguments. The -- Dual monoid is used so the last key wins. [partialCommandLineArgsIndexBased] :: PartialCommandLineArgs -> Map Int String -- | This convert the PartialCommandLineArgs to ' completeCommandLineArgs :: PartialCommandLineArgs -> [String] -- | The monoidial version of ProcessConfig. Used to combine -- overrides with defaults when creating a ProcessConfig. data PartialProcessConfig PartialProcessConfig :: PartialEnvVars -> PartialCommandLineArgs -> Last Handle -> Last Handle -> Last Handle -> PartialProcessConfig -- | A monoid for combine environment variables or replacing them. for the -- maps the Dual monoid is used. So the last key wins. [partialProcessConfigEnvVars] :: PartialProcessConfig -> PartialEnvVars -- | A monoid for combine command line arguments or replacing them [partialProcessConfigCmdLine] :: PartialProcessConfig -> PartialCommandLineArgs -- | A monoid for configuring the standard input Handle [partialProcessConfigStdIn] :: PartialProcessConfig -> Last Handle -- | A monoid for configuring the standard output Handle [partialProcessConfigStdOut] :: PartialProcessConfig -> Last Handle -- | A monoid for configuring the standard error Handle [partialProcessConfigStdErr] :: PartialProcessConfig -> Last Handle -- | The standardProcessConfig sets the handles to stdin, -- stdout and stderr and inherits the environment variables -- from the calling process. standardProcessConfig :: PartialProcessConfig -- | Turn a PartialProcessConfig into a ProcessConfig. Fails -- if any values are missing. completeProcessConfig :: [(String, String)] -> PartialProcessConfig -> Either [String] ProcessConfig -- | A type to track whether a file is temporary and needs to be cleaned -- up. data DirectoryType Permanent :: FilePath -> DirectoryType Temporary :: FilePath -> DirectoryType -- | Get the file path of a DirectoryType, regardless if it is a -- Permanent or Temporary type. toFilePath :: DirectoryType -> FilePath -- | The monoidial version of DirectoryType. Used to combine -- overrides with defaults when creating a DirectoryType. The -- monoid instance treats PTemporary as mempty and takes -- the last PPermanent value. data PartialDirectoryType -- | A permanent file that should not be generated. PPermanent :: FilePath -> PartialDirectoryType -- | A temporary file that needs to generated. PTemporary :: PartialDirectoryType -- | Either create aTemporary directory or do nothing to a -- Permanent one. setupDirectoryType :: String -> PartialDirectoryType -> IO DirectoryType -- | Either remove a Temporary directory or do nothing to a -- Permanent one. cleanupDirectoryType :: DirectoryType -> IO () -- | A type for configuring the listening address of the postgres -- process. postgres can listen on several types of sockets -- simulatanously but we don't support that behavior. One can either -- listen on a IP based socket or a UNIX domain socket. data SocketClass -- | IP socket type. The String is either an IP address or a host -- that will resolve to an IP address. IpSocket :: String -> SocketClass -- | UNIX domain socket UnixSocket :: DirectoryType -> SocketClass -- | Create the extra config lines for listening based on the -- SocketClass socketClassToConfig :: SocketClass -> [String] -- | Many processes require a "host" flag. We can generate one from the -- SocketClass. socketClassToHostFlag :: SocketClass -> [(String, Maybe String)] -- | Get the IP address, host name or UNIX domain socket directory as a -- String socketClassToHost :: SocketClass -> String -- | The monoidial version of SocketClass. Used to combine overrides -- with defaults when creating a SocketClass. The monoid instance -- treats 'PUnixSocket mempty' as mempty and combines the data PartialSocketClass -- | The monoid for combining IP address configuration PIpSocket :: Last String -> PartialSocketClass -- | The monoid for combining UNIX socket configuration PUnixSocket :: PartialDirectoryType -> PartialSocketClass -- | Turn a PartialSocketClass to a SocketClass. If the -- PIpSocket is Nothing default to "127.0.0.1". If the is a -- PUnixSocket optionally create a temporary directory if -- configured to do so. setupPartialSocketClass :: PartialSocketClass -> IO SocketClass -- | Cleanup the UNIX socket temporary directory if one was created. cleanupSocketConfig :: SocketClass -> IO () -- | postgres process config and corresponding client connection -- Options. data PartialPostgresPlan PartialPostgresPlan :: PartialProcessConfig -> Options -> PartialPostgresPlan -- | Monoid for the postgres ProcessConfig. [partialPostgresPlanProcessConfig] :: PartialPostgresPlan -> PartialProcessConfig -- | Monoid for the postgres client connection options. [partialPostgresPlanClientConfig] :: PartialPostgresPlan -> Options -- | Turn a PartialPostgresPlan into a PostgresPlan. Fails if -- any values are missing. completePostgresPlan :: [(String, String)] -> PartialPostgresPlan -> Either [String] PostgresPlan -- | The monoidial version of Plan. Used to combine overrides with -- defaults when creating a plan. data PartialPlan PartialPlan :: Last Logger -> Maybe PartialProcessConfig -> Maybe PartialProcessConfig -> PartialPostgresPlan -> [String] -> Last String -> PartialPlan [partialPlanLogger] :: PartialPlan -> Last Logger [partialPlanInitDb] :: PartialPlan -> Maybe PartialProcessConfig [partialPlanCreateDb] :: PartialPlan -> Maybe PartialProcessConfig [partialPlanPostgres] :: PartialPlan -> PartialPostgresPlan [partialPlanConfig] :: PartialPlan -> [String] [partialPlanDataDirectory] :: PartialPlan -> Last String -- | Turn a PartialPlan into a Plan. Fails if any values are -- missing. completePlan :: [(String, String)] -> PartialPlan -> Either [String] Plan -- | Resources holds a description of the temporary folders (if -- there are any) and includes the final Plan that can be used -- with startPlan. See setupConfig for an example of how to -- create a Resources. data Resources Resources :: Plan -> SocketClass -> DirectoryType -> Resources -- | Final Plan. See startPlan for information on -- Plans [resourcesPlan] :: Resources -> Plan -- | The SocketClass. Used to track if a temporary directory was -- made as the socket location. [resourcesSocket] :: Resources -> SocketClass -- | The data directory. Used to track if a temporary directory was used. [resourcesDataDir] :: Resources -> DirectoryType -- | Make the resourcesDataDir Permanent so it will not get -- cleaned up. makeResourcesDataDirPermanent :: Resources -> Resources -- | The high level options for overriding default behavior. data Config Config :: PartialPlan -> PartialSocketClass -> PartialDirectoryType -> Last (Maybe Int) -> Config -- | Extend or replace any of the configuration used to create a final -- Plan [configPlan] :: Config -> PartialPlan -- | Override the default SocketClass by setting this. [configSocket] :: Config -> PartialSocketClass -- | Override the default temporary data directory by passing in 'Permanent -- DIRECTORY' [configDataDir] :: Config -> PartialDirectoryType -- | A monoid for using an existing port (via 'Just PORT_NUMBER') or -- requesting a free port (via a Nothing) [configPort] :: Config -> Last (Maybe Int) -- | Create a PartialPlan that sets the command line options of all -- processes (initdb, postgres and createdb) -- using a toPlan :: Bool -> Bool -> Int -> SocketClass -> FilePath -> PartialPlan -- | Create all the temporary resources from a Config. This also -- combines the PartialPlan from toPlan with the -- extraConfig passed in. setupConfig :: Config -> IO Resources -- | Free the temporary resources created by setupConfig cleanupConfig :: Resources -> IO () -- | Attempt to create a config from a Options. This is useful if -- want to create a database owned by a specific user you will also log -- in as among other use cases. It is possible some Options are -- not supported so don't hesitate to open an issue on github if you find -- one. optionsToConfig :: Options -> Config -- | Local Lens alias type Lens s t a b = forall f. Functor f => (a -> f b) -> s -> f t -- | Local Lens' alias type Lens' s a = Lens s s a a -- | Lens for partialEnvVarsInherit partialEnvVarsInheritL :: Lens' PartialEnvVars (Last Bool) -- | Lens for partialEnvVarsSpecific partialEnvVarsSpecificL :: Lens' PartialEnvVars (Map String String) -- | Lens for partialProcessConfigCmdLine partialProcessConfigCmdLineL :: Lens' PartialProcessConfig PartialCommandLineArgs -- | Lens for partialProcessConfigEnvVars partialProcessConfigEnvVarsL :: Lens' PartialProcessConfig PartialEnvVars -- | Lens for partialProcessConfigStdErr partialProcessConfigStdErrL :: Lens' PartialProcessConfig (Last Handle) -- | Lens for partialProcessConfigStdIn partialProcessConfigStdInL :: Lens' PartialProcessConfig (Last Handle) -- | Lens for partialProcessConfigStdOut partialProcessConfigStdOutL :: Lens' PartialProcessConfig (Last Handle) -- | Lens for partialPostgresPlanClientConfig partialPostgresPlanClientConfigL :: Lens' PartialPostgresPlan Options -- | Lens for partialPostgresPlanProcessConfig partialPostgresPlanProcessConfigL :: Lens' PartialPostgresPlan PartialProcessConfig -- | Lens for partialPlanConfig partialPlanConfigL :: Lens' PartialPlan [String] -- | Lens for partialPlanCreateDb partialPlanCreateDbL :: Lens' PartialPlan (Maybe PartialProcessConfig) -- | Lens for partialPlanDataDirectory partialPlanDataDirectoryL :: Lens' PartialPlan (Last String) -- | Lens for partialPlanInitDb partialPlanInitDbL :: Lens' PartialPlan (Maybe PartialProcessConfig) -- | Lens for partialPlanLogger partialPlanLoggerL :: Lens' PartialPlan (Last Logger) -- | Lens for partialPlanPostgres partialPlanPostgresL :: Lens' PartialPlan PartialPostgresPlan -- | Lens for resourcesDataDir resourcesDataDirL :: Lens' Resources DirectoryType -- | Lens for resourcesPlan resourcesPlanL :: Lens' Resources Plan -- | Lens for resourcesSocket resourcesSocketL :: Lens' Resources SocketClass -- | Lens for configDataDir configDataDirL :: Lens' Config PartialDirectoryType -- | Lens for configPlan configPlanL :: Lens' Config PartialPlan -- | Lens for configPort configPortL :: Lens' Config (Last (Maybe Int)) -- | Lens for configSocket configSocketL :: Lens' Config PartialSocketClass -- | Lens for partialCommandLineArgsIndexBased partialCommandLineArgsIndexBasedL :: Lens' PartialCommandLineArgs (Map Int String) -- | Lens for partialCommandLineArgsKeyBased partialCommandLineArgsKeyBasedL :: Lens' PartialCommandLineArgs (Map String (Maybe String)) instance GHC.Base.Monoid Database.Postgres.Temp.Internal.Partial.Config instance GHC.Base.Semigroup Database.Postgres.Temp.Internal.Partial.Config instance GHC.Generics.Generic Database.Postgres.Temp.Internal.Partial.Config instance GHC.Base.Monoid Database.Postgres.Temp.Internal.Partial.PartialPlan instance GHC.Base.Semigroup Database.Postgres.Temp.Internal.Partial.PartialPlan instance GHC.Generics.Generic Database.Postgres.Temp.Internal.Partial.PartialPlan instance GHC.Base.Monoid Database.Postgres.Temp.Internal.Partial.PartialPostgresPlan instance GHC.Base.Semigroup Database.Postgres.Temp.Internal.Partial.PartialPostgresPlan instance GHC.Generics.Generic Database.Postgres.Temp.Internal.Partial.PartialPostgresPlan instance GHC.Generics.Generic Database.Postgres.Temp.Internal.Partial.PartialSocketClass instance GHC.Classes.Ord Database.Postgres.Temp.Internal.Partial.PartialSocketClass instance GHC.Classes.Eq Database.Postgres.Temp.Internal.Partial.PartialSocketClass instance GHC.Show.Show Database.Postgres.Temp.Internal.Partial.PartialSocketClass instance GHC.Generics.Generic Database.Postgres.Temp.Internal.Partial.SocketClass instance GHC.Classes.Ord Database.Postgres.Temp.Internal.Partial.SocketClass instance GHC.Classes.Eq Database.Postgres.Temp.Internal.Partial.SocketClass instance GHC.Show.Show Database.Postgres.Temp.Internal.Partial.SocketClass instance GHC.Classes.Ord Database.Postgres.Temp.Internal.Partial.PartialDirectoryType instance GHC.Classes.Eq Database.Postgres.Temp.Internal.Partial.PartialDirectoryType instance GHC.Show.Show Database.Postgres.Temp.Internal.Partial.PartialDirectoryType instance GHC.Classes.Ord Database.Postgres.Temp.Internal.Partial.DirectoryType instance GHC.Classes.Eq Database.Postgres.Temp.Internal.Partial.DirectoryType instance GHC.Show.Show Database.Postgres.Temp.Internal.Partial.DirectoryType instance GHC.Base.Monoid Database.Postgres.Temp.Internal.Partial.PartialProcessConfig instance GHC.Base.Semigroup Database.Postgres.Temp.Internal.Partial.PartialProcessConfig instance GHC.Show.Show Database.Postgres.Temp.Internal.Partial.PartialProcessConfig instance GHC.Classes.Eq Database.Postgres.Temp.Internal.Partial.PartialProcessConfig instance GHC.Generics.Generic Database.Postgres.Temp.Internal.Partial.PartialProcessConfig instance GHC.Base.Monoid Database.Postgres.Temp.Internal.Partial.PartialCommandLineArgs instance GHC.Classes.Eq Database.Postgres.Temp.Internal.Partial.PartialCommandLineArgs instance GHC.Show.Show Database.Postgres.Temp.Internal.Partial.PartialCommandLineArgs instance GHC.Generics.Generic Database.Postgres.Temp.Internal.Partial.PartialCommandLineArgs instance GHC.Classes.Eq Database.Postgres.Temp.Internal.Partial.PartialEnvVars instance GHC.Show.Show Database.Postgres.Temp.Internal.Partial.PartialEnvVars instance GHC.Generics.Generic Database.Postgres.Temp.Internal.Partial.PartialEnvVars instance Text.PrettyPrint.ANSI.Leijen.Internal.Pretty Database.Postgres.Temp.Internal.Partial.Config instance Text.PrettyPrint.ANSI.Leijen.Internal.Pretty Database.Postgres.Temp.Internal.Partial.Resources instance Text.PrettyPrint.ANSI.Leijen.Internal.Pretty Database.Postgres.Temp.Internal.Partial.PartialPlan instance Text.PrettyPrint.ANSI.Leijen.Internal.Pretty Database.Postgres.Temp.Internal.Partial.PartialPostgresPlan instance Text.PrettyPrint.ANSI.Leijen.Internal.Pretty Database.Postgres.Temp.Internal.Partial.PartialSocketClass instance GHC.Base.Semigroup Database.Postgres.Temp.Internal.Partial.PartialSocketClass instance GHC.Base.Monoid Database.Postgres.Temp.Internal.Partial.PartialSocketClass instance Text.PrettyPrint.ANSI.Leijen.Internal.Pretty Database.Postgres.Temp.Internal.Partial.SocketClass instance Text.PrettyPrint.ANSI.Leijen.Internal.Pretty Database.Postgres.Temp.Internal.Partial.PartialDirectoryType instance GHC.Base.Semigroup Database.Postgres.Temp.Internal.Partial.PartialDirectoryType instance GHC.Base.Monoid Database.Postgres.Temp.Internal.Partial.PartialDirectoryType instance Text.PrettyPrint.ANSI.Leijen.Internal.Pretty Database.Postgres.Temp.Internal.Partial.DirectoryType instance Text.PrettyPrint.ANSI.Leijen.Internal.Pretty Database.Postgres.Temp.Internal.Partial.PartialProcessConfig instance GHC.Base.Semigroup Database.Postgres.Temp.Internal.Partial.PartialCommandLineArgs instance Text.PrettyPrint.ANSI.Leijen.Internal.Pretty Database.Postgres.Temp.Internal.Partial.PartialCommandLineArgs instance GHC.Base.Semigroup Database.Postgres.Temp.Internal.Partial.PartialEnvVars instance GHC.Base.Monoid Database.Postgres.Temp.Internal.Partial.PartialEnvVars instance Text.PrettyPrint.ANSI.Leijen.Internal.Pretty Database.Postgres.Temp.Internal.Partial.PartialEnvVars -- | This module provides the high level functions that are re-exported by -- Database.Postgres.Temp. Additionally it includes some -- identifiers that are used for testing but are not exported. module Database.Postgres.Temp.Internal -- | Handle for holding temporary resources, the postgres process -- handle and postgres connection information. The DB also -- includes the final Plan that was used to start initdb, -- createdb and postgres. See toConnectionString -- for converting a DB to postgresql connection string. data DB DB :: Resources -> PostgresProcess -> DB -- | Temporary resources and the final Plan. [dbResources] :: DB -> Resources -- | postgres process handle and the connection options. [dbPostgresProcess] :: DB -> PostgresProcess -- | Convert a DB to a connection string. Alternatively one can -- access the Options using toConnectionOptions toConnectionString :: DB -> ByteString -- | Convert a DB to a connection Options type. toConnectionOptions :: DB -> Options -- | Access the data directory. This was either generated or specified -- explicitly when creating the Config toDataDirectory :: DB -> FilePath -- | Make the data directory permanent. Useful for debugging. If you are -- using with or withConfig this function will not modify -- the DB that is passed for cleanup. You will need to setup your -- own bracket like -- --
-- bracket (fmap makeDataDirPermanent start) (either mempty stop) --makeDataDirPermanent :: DB -> DB -- | Default postgres options defaultPostgresConfig :: [String] -- | The default configuration. This will create a database called -- "postgres" 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" which is optimized for -- performance. -- --
-- 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 = ERROR ---- -- defaultConfig also passes the --no-sync flag to -- initdb. -- -- If you would like to customize this behavior you can start with the -- defaultConfig and overwrite fields or combine a -- defaultConfig with another Config using <> -- (mappend). -- -- Alternatively you can eschew defaultConfig altogether, however -- your postgres might start and run faster if you use -- defaultConfig. -- -- defaultConfig also sets the partialPlanInitDb to -- pure standardProcessConfig and -- partialPostgresPlanProcessConfig to -- standardProcessConfig. -- -- To append additional lines to "postgresql.conf" file create a custom -- Config like the following. -- --
-- custom = defaultConfig <> mempty
-- { configPlan = mempty
-- { partialPlanConfig =
-- [ "wal_level = replica"
-- , "archive_mode = on"
-- , "max_wal_senders = 2"
-- , "fsync = on"
-- , "synchronous_commit = on"
-- ]
-- }
-- }
--
--
-- Or using the provided lenses and your favorite lens library
--
-- -- custom = defaultConfig & configPlanL . partialPlanConfigL <>~ -- [ "wal_level = replica" -- , "archive_mode = on" -- , "max_wal_senders = 2" -- , "fsync = on" -- , "synchronous_commit = on" -- ] ---- -- This is common enough there is defaultPostgresConf which is a -- helper to do this. -- -- As an alternative to using defaultConfig one could create a -- config from connections parameters using optionsToDefaultConfig defaultConfig :: Config -- | mappend the defaultConfig with a Config that -- provides additional "postgresql.conf" lines. Equivalent to -- --
-- defaultPostgresConf extra = defaultConfig <> mempty
-- { configPlan = mempty
-- { partialPlanConfig = extra
-- }
-- }
--
defaultPostgresConf :: [String] -> Config
-- | Create temporary resources and use them to make a Config. The
-- generated Config is combined with the passed in
-- extraConfiguration to create a Plan that is used to
-- create a database. The output DB includes references to the
-- temporary resources for cleanup and the final plan that was used to
-- generate the database and processes
startConfig :: Config -> IO (Either StartError DB)
-- | Default start behavior. Equivalent to calling startConfig with
-- the defaultConfig
start :: IO (Either StartError DB)
-- | Stop the postgres process and cleanup any temporary
-- directories that might have been created.
stop :: DB -> IO ()
-- | Only stop the postgres process but leave any temporary
-- resources. Useful for testing backup strategies when used in
-- conjunction with restart or withRestart.
stopPostgres :: DB -> IO ExitCode
-- | Restart the postgres using the Plan from the DB
-- (e.g. resourcesPlan . dbResources)
restart :: DB -> IO (Either StartError DB)
-- | Reload the configuration file without shutting down. Calls
-- pg_reload_conf().
reloadConfig :: DB -> IO ()
-- | Exception safe default database create. Takes an action
-- continuation which is given a DB it can use to connect to (see
-- toConnectionString or postgresProcessClientOptions). All
-- of the database resources are automatically cleaned up on completion
-- even in the face of exceptions. Based on the value of
-- configSocket a "postgresql.conf" is created with
--
-- -- listen_addresses = 'IP_ADDRESS' ---- -- if it is IpSocket. If is UnixSocket then the lines -- --
-- listen_addresses = '' -- unix_socket_directories = SOCKET_DIRECTORY ---- -- are added. This occurs as a side effect of calling withConfig. withConfig :: Config -> (DB -> IO a) -> IO (Either StartError a) -- | Default expectation safe interface. Equivalent to withConfig -- the defaultConfig with :: (DB -> IO a) -> IO (Either StartError a) -- | Exception safe version of restart withRestart :: DB -> (DB -> IO a) -> IO (Either StartError a) -- | Attempt to create a Config from a Options. Useful if you -- want to create a database owned by a specific user you will also login -- with among other use cases. optionsToDefaultConfig :: Options -> Config -- | Display a Config. prettyPrintConfig :: Config -> String -- | Display a DB prettyPrintDB :: DB -> String instance Text.PrettyPrint.ANSI.Leijen.Internal.Pretty Database.Postgres.Temp.Internal.DB -- | This module provides functions for creating a temporary -- postgres instance. By default it will create a temporary data -- directory and a temporary directory for a UNIX domain socket for -- postgres to listen on. -- -- Here is an example using the expection safe with function: -- --
-- with $ \db -> bracket -- (connectPostgreSQL (toConnectionString db)) -- close $ -- \conn -> execute_ conn "CREATE TABLE foo (id int)" ---- -- To extend or override the defaults use withConfig (or -- startConfig). -- -- tmp-postgres ultimately calls (optionally) initdb, -- postgres and (optionally) createdb. -- -- All of the command line, environment variables and configuration files -- that are generated by default for the respective executables can be -- extended. -- -- In general tmp-postgres is useful if you want a clean -- temporary postgres and do not want to worry about clashing -- with an existing postgres instance (or needing to ensure -- postgres is already running). -- -- Here are some different use cases for tmp-postgres and their -- respective configurations: -- --
-- echo "export PATH=$PATH:/usr/lib/postgresql/VERSION/bin/" >> /home/ubuntu/.bashrc --module Database.Postgres.Temp -- | Default expectation safe interface. Equivalent to withConfig -- the defaultConfig with :: (DB -> IO a) -> IO (Either StartError a) -- | Exception safe default database create. Takes an action -- continuation which is given a DB it can use to connect to (see -- toConnectionString or postgresProcessClientOptions). All -- of the database resources are automatically cleaned up on completion -- even in the face of exceptions. Based on the value of -- configSocket a "postgresql.conf" is created with -- --
-- listen_addresses = 'IP_ADDRESS' ---- -- if it is IpSocket. If is UnixSocket then the lines -- --
-- listen_addresses = '' -- unix_socket_directories = SOCKET_DIRECTORY ---- -- are added. This occurs as a side effect of calling withConfig. withConfig :: Config -> (DB -> IO a) -> IO (Either StartError a) -- | Default start behavior. Equivalent to calling startConfig with -- the defaultConfig start :: IO (Either StartError DB) -- | Create temporary resources and use them to make a Config. The -- generated Config is combined with the passed in -- extraConfiguration to create a Plan that is used to -- create a database. The output DB includes references to the -- temporary resources for cleanup and the final plan that was used to -- generate the database and processes startConfig :: Config -> IO (Either StartError DB) -- | Stop the postgres process and cleanup any temporary -- directories that might have been created. stop :: DB -> IO () -- | The default configuration. This will create a database called -- "postgres" 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" which is optimized for -- performance. -- --
-- 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 = ERROR ---- -- defaultConfig also passes the --no-sync flag to -- initdb. -- -- If you would like to customize this behavior you can start with the -- defaultConfig and overwrite fields or combine a -- defaultConfig with another Config using <> -- (mappend). -- -- Alternatively you can eschew defaultConfig altogether, however -- your postgres might start and run faster if you use -- defaultConfig. -- -- defaultConfig also sets the partialPlanInitDb to -- pure standardProcessConfig and -- partialPostgresPlanProcessConfig to -- standardProcessConfig. -- -- To append additional lines to "postgresql.conf" file create a custom -- Config like the following. -- --
-- custom = defaultConfig <> mempty
-- { configPlan = mempty
-- { partialPlanConfig =
-- [ "wal_level = replica"
-- , "archive_mode = on"
-- , "max_wal_senders = 2"
-- , "fsync = on"
-- , "synchronous_commit = on"
-- ]
-- }
-- }
--
--
-- Or using the provided lenses and your favorite lens library
--
-- -- custom = defaultConfig & configPlanL . partialPlanConfigL <>~ -- [ "wal_level = replica" -- , "archive_mode = on" -- , "max_wal_senders = 2" -- , "fsync = on" -- , "synchronous_commit = on" -- ] ---- -- This is common enough there is defaultPostgresConf which is a -- helper to do this. -- -- As an alternative to using defaultConfig one could create a -- config from connections parameters using optionsToDefaultConfig defaultConfig :: Config -- | mappend the defaultConfig with a Config that -- provides additional "postgresql.conf" lines. Equivalent to -- --
-- defaultPostgresConf extra = defaultConfig <> mempty
-- { configPlan = mempty
-- { partialPlanConfig = extra
-- }
-- }
--
defaultPostgresConf :: [String] -> Config
-- | The standardProcessConfig sets the handles to stdin,
-- stdout and stderr and inherits the environment variables
-- from the calling process.
standardProcessConfig :: PartialProcessConfig
-- | Attempt to create a Config from a Options. Useful if you
-- want to create a database owned by a specific user you will also login
-- with among other use cases.
optionsToDefaultConfig :: Options -> Config
-- | Restart the postgres using the Plan from the DB
-- (e.g. resourcesPlan . dbResources)
restart :: DB -> IO (Either StartError DB)
-- | Only stop the postgres process but leave any temporary
-- resources. Useful for testing backup strategies when used in
-- conjunction with restart or withRestart.
stopPostgres :: DB -> IO ExitCode
-- | Exception safe version of restart
withRestart :: DB -> (DB -> IO a) -> IO (Either StartError a)
-- | Reload the configuration file without shutting down. Calls
-- pg_reload_conf().
reloadConfig :: DB -> IO ()
-- | Handle for holding temporary resources, the postgres process
-- handle and postgres connection information. The DB also
-- includes the final Plan that was used to start initdb,
-- createdb and postgres. See toConnectionString
-- for converting a DB to postgresql connection string.
data DB
-- | Display a DB
prettyPrintDB :: DB -> String
-- | Convert a DB to a connection string. Alternatively one can
-- access the Options using toConnectionOptions
toConnectionString :: DB -> ByteString
-- | Convert a DB to a connection Options type.
toConnectionOptions :: DB -> Options
-- | Access the data directory. This was either generated or specified
-- explicitly when creating the Config
toDataDirectory :: DB -> FilePath
-- | Make the data directory permanent. Useful for debugging. If you are
-- using with or withConfig this function will not modify
-- the DB that is passed for cleanup. You will need to setup your
-- own bracket like
--
-- -- bracket (fmap makeDataDirPermanent start) (either mempty stop) --makeDataDirPermanent :: DB -> DB -- | The high level options for overriding default behavior. data Config Config :: PartialPlan -> PartialSocketClass -> PartialDirectoryType -> Last (Maybe Int) -> Config -- | Extend or replace any of the configuration used to create a final -- Plan [configPlan] :: Config -> PartialPlan -- | Override the default SocketClass by setting this. [configSocket] :: Config -> PartialSocketClass -- | Override the default temporary data directory by passing in 'Permanent -- DIRECTORY' [configDataDir] :: Config -> PartialDirectoryType -- | A monoid for using an existing port (via 'Just PORT_NUMBER') or -- requesting a free port (via a Nothing) [configPort] :: Config -> Last (Maybe Int) -- | Display a Config. prettyPrintConfig :: Config -> String -- | Lens for configPlan configPlanL :: Lens' Config PartialPlan -- | Lens for configSocket configSocketL :: Lens' Config PartialSocketClass -- | Lens for configDataDir configDataDirL :: Lens' Config PartialDirectoryType -- | Lens for configPort configPortL :: Lens' Config (Last (Maybe Int)) -- | The monoidial version of Plan. Used to combine overrides with -- defaults when creating a plan. data PartialPlan PartialPlan :: Last Logger -> Maybe PartialProcessConfig -> Maybe PartialProcessConfig -> PartialPostgresPlan -> [String] -> Last String -> PartialPlan [partialPlanLogger] :: PartialPlan -> Last Logger [partialPlanInitDb] :: PartialPlan -> Maybe PartialProcessConfig [partialPlanCreateDb] :: PartialPlan -> Maybe PartialProcessConfig [partialPlanPostgres] :: PartialPlan -> PartialPostgresPlan [partialPlanConfig] :: PartialPlan -> [String] [partialPlanDataDirectory] :: PartialPlan -> Last String -- | Lens for partialPlanConfig partialPlanConfigL :: Lens' PartialPlan [String] -- | Lens for partialPlanCreateDb partialPlanCreateDbL :: Lens' PartialPlan (Maybe PartialProcessConfig) -- | Lens for partialPlanDataDirectory partialPlanDataDirectoryL :: Lens' PartialPlan (Last String) -- | Lens for partialPlanInitDb partialPlanInitDbL :: Lens' PartialPlan (Maybe PartialProcessConfig) -- | Lens for partialPlanLogger partialPlanLoggerL :: Lens' PartialPlan (Last Logger) -- | Lens for partialPlanPostgres partialPlanPostgresL :: Lens' PartialPlan PartialPostgresPlan -- | postgres process config and corresponding client connection -- Options. data PartialPostgresPlan PartialPostgresPlan :: PartialProcessConfig -> Options -> PartialPostgresPlan -- | Monoid for the postgres ProcessConfig. [partialPostgresPlanProcessConfig] :: PartialPostgresPlan -> PartialProcessConfig -- | Monoid for the postgres client connection options. [partialPostgresPlanClientConfig] :: PartialPostgresPlan -> Options -- | Lens for partialPostgresPlanClientConfig partialPostgresPlanClientConfigL :: Lens' PartialPostgresPlan Options -- | Lens for partialPostgresPlanProcessConfig partialPostgresPlanProcessConfigL :: Lens' PartialPostgresPlan PartialProcessConfig -- | The monoidial version of ProcessConfig. Used to combine -- overrides with defaults when creating a ProcessConfig. data PartialProcessConfig PartialProcessConfig :: PartialEnvVars -> PartialCommandLineArgs -> Last Handle -> Last Handle -> Last Handle -> PartialProcessConfig -- | A monoid for combine environment variables or replacing them. for the -- maps the Dual monoid is used. So the last key wins. [partialProcessConfigEnvVars] :: PartialProcessConfig -> PartialEnvVars -- | A monoid for combine command line arguments or replacing them [partialProcessConfigCmdLine] :: PartialProcessConfig -> PartialCommandLineArgs -- | A monoid for configuring the standard input Handle [partialProcessConfigStdIn] :: PartialProcessConfig -> Last Handle -- | A monoid for configuring the standard output Handle [partialProcessConfigStdOut] :: PartialProcessConfig -> Last Handle -- | A monoid for configuring the standard error Handle [partialProcessConfigStdErr] :: PartialProcessConfig -> Last Handle -- | Lens for partialProcessConfigCmdLine partialProcessConfigCmdLineL :: Lens' PartialProcessConfig PartialCommandLineArgs -- | Lens for partialProcessConfigEnvVars partialProcessConfigEnvVarsL :: Lens' PartialProcessConfig PartialEnvVars -- | Lens for partialProcessConfigStdErr partialProcessConfigStdErrL :: Lens' PartialProcessConfig (Last Handle) -- | Lens for partialProcessConfigStdIn partialProcessConfigStdInL :: Lens' PartialProcessConfig (Last Handle) -- | Lens for partialProcessConfigStdOut partialProcessConfigStdOutL :: Lens' PartialProcessConfig (Last Handle) -- | The environment variables can be declared to inherit from the running -- process or they can be specifically added. data PartialEnvVars PartialEnvVars :: Last Bool -> Map String String -> PartialEnvVars [partialEnvVarsInherit] :: PartialEnvVars -> Last Bool [partialEnvVarsSpecific] :: PartialEnvVars -> Map String String -- | Lens for partialEnvVarsInherit partialEnvVarsInheritL :: Lens' PartialEnvVars (Last Bool) -- | Lens for partialEnvVarsSpecific partialEnvVarsSpecificL :: Lens' PartialEnvVars (Map String String) -- | A type to help combine command line arguments. data PartialCommandLineArgs PartialCommandLineArgs :: Map String (Maybe String) -> Map Int String -> PartialCommandLineArgs -- | Arguments of the form -h foo, --host=foo and -- --switch. The key is mappended with value so the key -- should include the space or equals (as shown in the first two examples -- respectively). The Dual monoid is used so the last key wins. [partialCommandLineArgsKeyBased] :: PartialCommandLineArgs -> Map String (Maybe String) -- | Arguments that appear at the end of the key based arguments. The -- Dual monoid is used so the last key wins. [partialCommandLineArgsIndexBased] :: PartialCommandLineArgs -> Map Int String -- | Lens for partialCommandLineArgsIndexBased partialCommandLineArgsIndexBasedL :: Lens' PartialCommandLineArgs (Map Int String) -- | Lens for partialCommandLineArgsKeyBased partialCommandLineArgsKeyBasedL :: Lens' PartialCommandLineArgs (Map String (Maybe String)) -- | The monoidial version of DirectoryType. Used to combine -- overrides with defaults when creating a DirectoryType. The -- monoid instance treats PTemporary as mempty and takes -- the last PPermanent value. data PartialDirectoryType -- | A permanent file that should not be generated. PPermanent :: FilePath -> PartialDirectoryType -- | A temporary file that needs to generated. PTemporary :: PartialDirectoryType -- | The monoidial version of SocketClass. Used to combine overrides -- with defaults when creating a SocketClass. The monoid instance -- treats 'PUnixSocket mempty' as mempty and combines the data PartialSocketClass -- | The monoid for combining IP address configuration PIpSocket :: Last String -> PartialSocketClass -- | The monoid for combining UNIX socket configuration PUnixSocket :: PartialDirectoryType -> PartialSocketClass -- | A way to log internal Events type Logger = Event -> IO () -- | Internal events for debugging data Event StartPostgres :: Event WaitForDB :: Event StartPlan :: String -> Event TryToConnect :: Event -- | A list of failures that can occur when starting. This is not and -- exhaustive list but covers the errors that the system catches for the -- user. data StartError -- | postgres failed before a connection succeeded. Most likely -- this is due to invalid configuration StartPostgresFailed :: ExitCode -> StartError -- | initdb failed. This can be from invalid configuration or -- using a non-empty data directory InitDbFailed :: ExitCode -> StartError -- | createdb failed. This can be from invalid configuration or -- the database might already exist. CreateDbFailed :: ExitCode -> StartError -- | The PartialPlan was missing info and a complete Plan -- could not be created. CompletePlanFailed :: String -> [String] -> StartError