-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Start and stop a temporary postgres -- -- tmp-postgres provides functions creating a temporary -- postgres instance. -- -- By default it will create a temporary directory for the data, a random -- port for listening and a temporary directory for a UNIX domain socket. -- -- 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)"
--   
-- -- MacOS and Linux are support. Windows is not. -- -- Requires PostgreSQL 9.3+ -- -- WARNING!! Ubuntu's PostgreSQL installation does not put -- initdb on the PATH. We need to add it manually. The -- necessary binaries are in the -- /usr/lib/postgresql/VERSION/bin/ directory, and should be -- added to the PATH -- --
--   echo "export PATH=$PATH:/usr/lib/postgresql/VERSION/bin/" >> /home/ubuntu/.bashrc
--   
@package tmp-postgres @version 1.0.1.0 -- | This module provides the low level functionality for running -- initdb, postgres and createdb to make a -- database. -- -- See initPlan for more details. module Database.Postgres.Temp.Internal.Core -- | Internal events for debugging data Event StartPostgres :: Event WaitForDB :: 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] -> 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 :: 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 -- | 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. [postgresPlanClientConfig] :: PostgresPlan -> Options -- | The output of calling startPostgresProcess. data PostgresProcess PostgresProcess :: Options -> ProcessHandle -> PostgresProcess -- | Connection options [postgresProcessClientConfig] :: PostgresProcess -> Options -- | postgres process handle [postgresProcessHandle] :: PostgresProcess -> ProcessHandle -- | Force all connections to the database to close. Can be useful in some -- testing situations. Called during shutdown as well. terminateConnections :: Options -> IO () -- | 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 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 -- | A simple helper to throw ExitCodes when they are -- ExitFailure. throwIfNotSuccess :: Exception e => (ExitCode -> e) -> ExitCode -> IO () -- | initPlan 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. initPlan :: Plan -> IO PostgresProcess -- | Stop the postgres process. See stopPostgresProcess for -- more details. shutdownPlan :: 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 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 three classes of types. Types like Lastoid that -- are generic and could live in a module like "base". -- -- 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 -- startWith and related functions. | module Database.Postgres.Temp.Internal.Partial -- | Lastoid is helper for overriding configuration values. It's -- Semigroup instance let's one either combine the a of -- two Lastoids using <> via the Mappend -- constructor or one can wholly replace the value with the last value -- using the Replace constructor. Roughly -- --
--   x <> Replace y = Replace y
--   Replace x <> Mappend y = Replace (x <> y)
--   Mappend x <> Mappend y = Mappend (x <> y)
--   
data Lastoid a Replace :: a -> Lastoid a Mappend :: a -> Lastoid a -- | Get the value of a Lastoid regardless if it is a Replace -- or a Mappend. getLastoid :: Lastoid a -> a -- | The monoidial version of ProcessConfig. Used to combine -- overrides with defaults when creating a ProcessConfig. data PartialProcessConfig PartialProcessConfig :: Lastoid [(String, String)] -> Lastoid [String] -> Last Handle -> Last Handle -> Last Handle -> PartialProcessConfig -- | A monoid for combine environment variables or replacing them [partialProcessConfigEnvVars] :: PartialProcessConfig -> Lastoid [(String, String)] -- | A monoid for combine command line arguments or replacing them [partialProcessConfigCmdLine] :: PartialProcessConfig -> Lastoid [String] -- | 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 :: IO PartialProcessConfig -- | A helper to add more info to all the error messages. addErrorContext :: String -> Either [String] a -> Either [String] a -- | A helper for creating an error if a Last is not defined. getOption :: String -> Last a -> Validation [String] a -- | Turn a PartialProcessConfig into a ProcessConfig. Fails -- if any values are missing. completeProcessConfig :: 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. initDirectoryType :: String -> PartialDirectoryType -> IO DirectoryType -- | Either create a temporary directory or do nothing rmDirIgnoreErrors :: FilePath -> IO () -- | Either remove a Temporary directory or do nothing to a -- Permanent one. shutdownDirectoryType :: 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] -- | 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. initPartialSocketClass :: PartialSocketClass -> IO SocketClass -- | Cleanup the UNIX socket temporary directory if one was created. shutdownSocketConfig :: SocketClass -> IO () -- | PartialPostgresPlan 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 :: PartialPostgresPlan -> Either [String] PostgresPlan -- | The monoidial version of Plan. Used to combine overrides with -- defaults when creating a plan. data PartialPlan PartialPlan :: Last Logger -> Lastoid (Maybe PartialProcessConfig) -> Lastoid (Maybe PartialProcessConfig) -> PartialPostgresPlan -> Lastoid [String] -> Last String -> PartialPlan [partialPlanLogger] :: PartialPlan -> Last Logger [partialPlanInitDb] :: PartialPlan -> Lastoid (Maybe PartialProcessConfig) [partialPlanCreateDb] :: PartialPlan -> Lastoid (Maybe PartialProcessConfig) [partialPlanPostgres] :: PartialPlan -> PartialPostgresPlan [partialPlanConfig] :: PartialPlan -> Lastoid [String] [partialPlanDataDirectory] :: PartialPlan -> Last String -- | Turn a PartialPlan into a Plan. Fails if any values are -- missing. completePlan :: 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 initPlan. See initConfig for an example of how to -- create a Resources. data Resources Resources :: Plan -> SocketClass -> DirectoryType -> Resources -- | Final Plan. See initPlan 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 -- | 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 :: Int -> SocketClass -> FilePath -> PartialPlan -- | Create all the temporary resources from a Config. This also -- combines the PartialPlan from toPlan with the -- extraConfig passed in. initConfig :: Config -> IO Resources -- | Free the temporary resources created by initConfig shutdownResources :: 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 optionsToPlan :: Options -> PartialPlan userToPlan :: Maybe String -> PartialPlan dbnameToPlan :: Maybe String -> PartialPlan hostToSocketClass :: Maybe String -> PartialSocketClass 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.Generics.Generic Database.Postgres.Temp.Internal.Partial.PartialProcessConfig instance GHC.Base.Functor Database.Postgres.Temp.Internal.Partial.Lastoid instance GHC.Classes.Eq a => GHC.Classes.Eq (Database.Postgres.Temp.Internal.Partial.Lastoid a) instance GHC.Show.Show a => GHC.Show.Show (Database.Postgres.Temp.Internal.Partial.Lastoid a) instance GHC.Base.Semigroup Database.Postgres.Temp.Internal.Partial.PartialSocketClass instance GHC.Base.Monoid Database.Postgres.Temp.Internal.Partial.PartialSocketClass instance GHC.Base.Semigroup Database.Postgres.Temp.Internal.Partial.PartialDirectoryType instance GHC.Base.Monoid Database.Postgres.Temp.Internal.Partial.PartialDirectoryType instance GHC.Base.Semigroup a => GHC.Base.Semigroup (Database.Postgres.Temp.Internal.Partial.Lastoid a) instance GHC.Base.Monoid a => GHC.Base.Monoid (Database.Postgres.Temp.Internal.Partial.Lastoid a) -- | 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. 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 postgresProcessClientConfig . -- dbPostgresProcess toConnectionString :: DB -> ByteString -- | Default postgres options defaultPostgresConfig :: [String] -- | The default configuration. This will create a database called "test" -- and create a temporary directory for the data and a temporary -- directory for a unix socket on a random port. If you would like to -- customize this behavior you can start with the defaultConfig -- and overwrite fields or combine the Config with another config -- using <> (mappend). If you would like complete -- control over the behavior of initdb, postgres and -- createdb you can call the internal function initPlan -- directly although this should not be necessary. defaultConfig :: Config -- | standardConfig makes a default config with -- standardProcessConfig. It is used by default but can be -- overriden by the extra config. standardConfig :: IO 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 startWith :: Config -> IO (Either StartError DB) -- | Default start behavior. Equivalent to calling startWith 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 postgresProcessClientConfig). All -- of the database resources are automatically cleaned up on completion -- even in the face of exceptions. withPlan :: Config -> (DB -> IO a) -> IO (Either StartError a) -- | Default expectation safe interface. Equivalent to withPlan 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. 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. This function works around a difficulty with appending options to -- the createdb plan by mappending to defaultConfig and -- optionally replacing the database name. optionsToDefaultConfig :: Options -> Config -- | This module provides functions creating a temporary postgres -- instance. By default it will create a temporary directory for the -- data, a random port for listening and a temporary directory for a UNIX -- domain socket. -- -- 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 withPlan (or -- startWith). -- -- tmp-postgres ultimately calls initdb, -- postgres and createdb. All of the command line, -- environment variables and configuration files that are generated by -- default for the respective executables can be extended or overrided. -- -- All tmp-postgres by default is most useful for creating tests -- by configuring "tmp-postgres" differently it can be used for other -- purposes. -- -- -- -- The level of custom configuration is extensive but with great power -- comes ability to screw everything up. `tmp-postgres` doesn't validate -- any custom configuration and one can easily create a Config -- that would not allow postgres to start. -- -- WARNING!! Ubuntu's PostgreSQL installation does not put -- initdb on the PATH. We need to add it manually. The -- necessary binaries are in the -- /usr/lib/postgresql/VERSION/bin/ directory, and should be -- added to the PATH -- --
--   echo "export PATH=$PATH:/usr/lib/postgresql/VERSION/bin/" >> /home/ubuntu/.bashrc
--   
module Database.Postgres.Temp -- | 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. 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 -- | Default expectation safe interface. Equivalent to withPlan 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 postgresProcessClientConfig). All -- of the database resources are automatically cleaned up on completion -- even in the face of exceptions. withPlan :: Config -> (DB -> IO a) -> IO (Either StartError a) -- | Default start behavior. Equivalent to calling startWith 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 startWith :: 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 "test" -- and create a temporary directory for the data and a temporary -- directory for a unix socket on a random port. If you would like to -- customize this behavior you can start with the defaultConfig -- and overwrite fields or combine the Config with another config -- using <> (mappend). If you would like complete -- control over the behavior of initdb, postgres and -- createdb you can call the internal function initPlan -- directly although this should not be necessary. defaultConfig :: 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 () -- | Convert a DB to a connection string. Alternatively one can -- access the Options using postgresProcessClientConfig . -- dbPostgresProcess toConnectionString :: DB -> ByteString -- | 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] -> StartError -- | 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) -- | Lastoid is helper for overriding configuration values. It's -- Semigroup instance let's one either combine the a of -- two Lastoids using <> via the Mappend -- constructor or one can wholly replace the value with the last value -- using the Replace constructor. Roughly -- --
--   x <> Replace y = Replace y
--   Replace x <> Mappend y = Replace (x <> y)
--   Mappend x <> Mappend y = Mappend (x <> y)
--   
data Lastoid a Replace :: a -> Lastoid a Mappend :: a -> Lastoid a -- | A type to track whether a file is temporary and needs to be cleaned -- up. data DirectoryType Permanent :: FilePath -> DirectoryType Temporary :: FilePath -> DirectoryType -- | 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 -- | 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 -- | 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 -- | The monoidial version of ProcessConfig. Used to combine -- overrides with defaults when creating a ProcessConfig. data PartialProcessConfig PartialProcessConfig :: Lastoid [(String, String)] -> Lastoid [String] -> Last Handle -> Last Handle -> Last Handle -> PartialProcessConfig -- | A monoid for combine environment variables or replacing them [partialProcessConfigEnvVars] :: PartialProcessConfig -> Lastoid [(String, String)] -- | A monoid for combine command line arguments or replacing them [partialProcessConfigCmdLine] :: PartialProcessConfig -> Lastoid [String] -- | 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 -- | 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 -- | PartialPostgresPlan data PartialPostgresPlan PartialPostgresPlan :: PartialProcessConfig -> Options -> PartialPostgresPlan -- | Monoid for the postgres ProcessConfig. [partialPostgresPlanProcessConfig] :: PartialPostgresPlan -> PartialProcessConfig -- | Monoid for the postgres client connection options. [partialPostgresPlanClientConfig] :: PartialPostgresPlan -> Options -- | 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. [postgresPlanClientConfig] :: PostgresPlan -> Options -- | The output of calling startPostgresProcess. data PostgresProcess PostgresProcess :: Options -> ProcessHandle -> PostgresProcess -- | Connection options [postgresProcessClientConfig] :: PostgresProcess -> Options -- | postgres process handle [postgresProcessHandle] :: PostgresProcess -> ProcessHandle -- | The monoidial version of Plan. Used to combine overrides with -- defaults when creating a plan. data PartialPlan PartialPlan :: Last Logger -> Lastoid (Maybe PartialProcessConfig) -> Lastoid (Maybe PartialProcessConfig) -> PartialPostgresPlan -> Lastoid [String] -> Last String -> PartialPlan [partialPlanLogger] :: PartialPlan -> Last Logger [partialPlanInitDb] :: PartialPlan -> Lastoid (Maybe PartialProcessConfig) [partialPlanCreateDb] :: PartialPlan -> Lastoid (Maybe PartialProcessConfig) [partialPlanPostgres] :: PartialPlan -> PartialPostgresPlan [partialPlanConfig] :: PartialPlan -> Lastoid [String] [partialPlanDataDirectory] :: PartialPlan -> Last String -- | 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 -- | 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. This function works around a difficulty with appending options to -- the createdb plan by mappending to defaultConfig and -- optionally replacing the database name. optionsToDefaultConfig :: Options -> Config