-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Start and stop a temporary postgres for testing -- -- This module provides functions creating a temporary postgres instance -- on a random port for testing. -- --
-- result <- start [] -- case result of -- Left err -> print err -- Right tempDB -> do -- -- Do stuff -- stop tempDB ---- -- The are few different methods for starting postgres which -- provide different methods of dealing with stdout and -- stderr. -- -- The start methods use a config based on the one used by pg_tmp -- (http:/ephemeralpg.org), but can be overriden by different -- values to the first argument of the start functions. -- -- 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 0.3.0.0 module Database.Postgres.Temp.Internal getFreePort :: IO Int waitForDB :: Options -> IO () withLock :: MVar a -> IO b -> IO b data DB DB :: FilePath -> Options -> [(String, String)] -> Handle -> Handle -> MVar () -> Int -> SocketClass -> IORef (Maybe ProcessHandle) -> DB -- | Temporary directory where the unix socket, logs and data directory -- live. [mainDir] :: DB -> FilePath -- | PostgreSQL connection string. [options] :: DB -> Options -- | Additionally options passed to the postgres command line [extraOptions] :: DB -> [(String, String)] -- | The Handle used to standard error [stdErr] :: DB -> Handle -- | The Handle used to standard output [stdOut] :: DB -> Handle -- | A lock used internally to makes sure access to pid is -- serialized [pidLock] :: DB -> MVar () -- | The port postgres is listening on [port] :: DB -> Int -- | The SocketClass used for starting postgres [socketClass] :: DB -> SocketClass -- | The process handle for the postgres process. [pid] :: DB -> IORef (Maybe ProcessHandle) connectionString :: DB -> String data SocketClass Localhost :: SocketClass Unix :: SocketClass data Options Options :: String -> InitDbOptions -> [(String, String)] -> Options -- | The database name to use. Defaults to test [tmpDbName] :: Options -> String -- | Options to pass to initdb [tmpInitDbOptions] :: Options -> InitDbOptions -- | Extra options which override the defaults [tmpCmdLineOptions] :: Options -> [(String, String)] defaultOptions :: Options -- | start postgres and use the current processes stdout and stderr start :: Options -> IO (Either StartError DB) -- | start postgres and use the current processes stdout and stderr but use -- TCP on localhost instead of a unix socket. startLocalhost :: Options -> IO (Either StartError DB) fourth :: (a, b, c, d) -> d procWith :: Handle -> Handle -> String -> [String] -> CreateProcess config :: Maybe FilePath -> String data StartError InitDBFailed :: ExitCode -> StartError CreateDBFailed :: [String] -> ExitCode -> StartError StartPostgresFailed :: [String] -> ExitCode -> StartError StartPostgresDisappeared :: [String] -> StartError throwIfError :: (ExitCode -> StartError) -> ExitCode -> IO () pidString :: ProcessHandle -> IO String runProcessWith :: Handle -> Handle -> String -> String -> [String] -> IO ExitCode -- | Start postgres and pass in handles for stdout and stderr startWithHandles :: SocketClass -> Options -> Handle -> Handle -> IO (Either StartError DB) startWithHandlesAndDir :: SocketClass -> Options -> FilePath -> Handle -> Handle -> IO (Either StartError DB) -- | This error is thrown is startPostgres is called twice without -- calling stopPostgres first. data AnotherPostgresProcessActive AnotherPostgresProcessActive :: AnotherPostgresProcessActive waitOnPostgres :: DB -> IO () -- | Send the SIGHUP signal to the postgres process to start a config -- reload reloadConfig :: DB -> IO () -- | This throws AnotherPostgresProcessActive if the postgres has -- not been stopped using stopPostgres. This function attempts to -- the pidLock before running. If postgres process fails this -- throws StartPostgresFailed. If the postgres process becomes -- Nothing while starting this function throws -- StartPostgresDisappeared. startPostgres :: DB -> IO () -- | Stop the postgres process. This function attempts to the -- pidLock before running. stopPostgres will terminate all -- connections before shutting down postgres. stopPostgres is -- useful for testing backup strategies. stopPostgres :: DB -> IO (Maybe ExitCode) makePostgresOptions :: [(String, String)] -> FilePath -> Int -> [String] runPostgres :: Handle -> Handle -> [String] -> IO ProcessHandle data Event InitDB :: Event WriteConfig :: Event FreePort :: Event StartPostgres :: Event WaitForDB :: Event CreateDB :: Event Finished :: Event rmDirIgnoreErrors :: FilePath -> IO () startWithLogger :: (Event -> IO ()) -> SocketClass -> Options -> FilePath -> Handle -> Handle -> IO (Either StartError DB) -- | Start postgres and log it's all stdout to {mainDir}/output.txt -- and {mainDir}/error.txt startAndLogToTmp :: Options -> IO (Either StartError DB) -- | Force all connections to the database to close. Can be useful in some -- testing situations. Called during shutdown as well. terminateConnections :: DB -> IO () -- | Stop postgres and clean up the temporary database folder. stop :: DB -> IO (Maybe ExitCode) data InitDbOptions InitDbOptions :: Maybe String -> Maybe String -> Maybe String -> Maybe String -> Bool -> Bool -> [String] -> InitDbOptions [initDbUser] :: InitDbOptions -> Maybe String [initDbEncoding] :: InitDbOptions -> Maybe String [initDbAuth] :: InitDbOptions -> Maybe String [initDbPgData] :: InitDbOptions -> Maybe String [initDbNoSync] :: InitDbOptions -> Bool [initDbDebug] :: InitDbOptions -> Bool [initDbExtraOptions] :: InitDbOptions -> [String] defaultInitDbOptions :: InitDbOptions initDbToCommandLingArgs :: InitDbOptions -> [String] instance GHC.Generics.Generic Database.Postgres.Temp.Internal.InitDbOptions instance GHC.Classes.Ord Database.Postgres.Temp.Internal.InitDbOptions instance GHC.Read.Read Database.Postgres.Temp.Internal.InitDbOptions instance GHC.Classes.Eq Database.Postgres.Temp.Internal.InitDbOptions instance GHC.Show.Show Database.Postgres.Temp.Internal.InitDbOptions instance GHC.Classes.Ord Database.Postgres.Temp.Internal.Event instance GHC.Enum.Bounded Database.Postgres.Temp.Internal.Event instance GHC.Enum.Enum Database.Postgres.Temp.Internal.Event instance GHC.Classes.Eq Database.Postgres.Temp.Internal.Event instance GHC.Show.Show Database.Postgres.Temp.Internal.Event instance GHC.Classes.Eq Database.Postgres.Temp.Internal.AnotherPostgresProcessActive instance GHC.Show.Show Database.Postgres.Temp.Internal.AnotherPostgresProcessActive instance GHC.Classes.Eq Database.Postgres.Temp.Internal.StartError instance GHC.Show.Show Database.Postgres.Temp.Internal.StartError instance GHC.Generics.Generic Database.Postgres.Temp.Internal.SocketClass instance GHC.Enum.Bounded Database.Postgres.Temp.Internal.SocketClass instance GHC.Enum.Enum Database.Postgres.Temp.Internal.SocketClass instance GHC.Classes.Ord Database.Postgres.Temp.Internal.SocketClass instance GHC.Read.Read Database.Postgres.Temp.Internal.SocketClass instance GHC.Classes.Eq Database.Postgres.Temp.Internal.SocketClass instance GHC.Show.Show Database.Postgres.Temp.Internal.SocketClass instance GHC.Exception.Type.Exception Database.Postgres.Temp.Internal.AnotherPostgresProcessActive instance GHC.Exception.Type.Exception Database.Postgres.Temp.Internal.StartError -- | This module provides functions greating a temporary postgres instance -- on a random port for testing. -- --
-- result <- start [] -- case result of -- Left err -> print err -- Right tempDB -> do -- -- Do stuff -- stop tempDB ---- -- The are few different methods for starting postgres which -- provide different methods of dealing with stdout and -- stderr. -- -- The start methods use a config based on the one used by pg_tmp, -- but can be overriden by in different values to the first argument of -- the start functions. -- -- 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 data DB DB :: FilePath -> Options -> [(String, String)] -> Handle -> Handle -> MVar () -> Int -> SocketClass -> IORef (Maybe ProcessHandle) -> DB -- | Temporary directory where the unix socket, logs and data directory -- live. [mainDir] :: DB -> FilePath -- | PostgreSQL connection string. [options] :: DB -> Options -- | Additionally options passed to the postgres command line [extraOptions] :: DB -> [(String, String)] -- | The Handle used to standard error [stdErr] :: DB -> Handle -- | The Handle used to standard output [stdOut] :: DB -> Handle -- | A lock used internally to makes sure access to pid is -- serialized [pidLock] :: DB -> MVar () -- | The port postgres is listening on [port] :: DB -> Int -- | The SocketClass used for starting postgres [socketClass] :: DB -> SocketClass -- | The process handle for the postgres process. [pid] :: DB -> IORef (Maybe ProcessHandle) data StartError InitDBFailed :: ExitCode -> StartError CreateDBFailed :: [String] -> ExitCode -> StartError StartPostgresFailed :: [String] -> ExitCode -> StartError StartPostgresDisappeared :: [String] -> StartError -- | start postgres and use the current processes stdout and stderr start :: Options -> IO (Either StartError DB) -- | start postgres and use the current processes stdout and stderr but use -- TCP on localhost instead of a unix socket. startLocalhost :: Options -> IO (Either StartError DB) -- | Start postgres and log it's all stdout to {mainDir}/output.txt -- and {mainDir}/error.txt startAndLogToTmp :: Options -> IO (Either StartError DB) -- | Start postgres and pass in handles for stdout and stderr startWithHandles :: SocketClass -> Options -> Handle -> Handle -> IO (Either StartError DB) data Options Options :: String -> InitDbOptions -> [(String, String)] -> Options -- | The database name to use. Defaults to test [tmpDbName] :: Options -> String -- | Options to pass to initdb [tmpInitDbOptions] :: Options -> InitDbOptions -- | Extra options which override the defaults [tmpCmdLineOptions] :: Options -> [(String, String)] defaultOptions :: Options data InitDbOptions InitDbOptions :: Maybe String -> Maybe String -> Maybe String -> Maybe String -> Bool -> Bool -> [String] -> InitDbOptions [initDbUser] :: InitDbOptions -> Maybe String [initDbEncoding] :: InitDbOptions -> Maybe String [initDbAuth] :: InitDbOptions -> Maybe String [initDbPgData] :: InitDbOptions -> Maybe String [initDbNoSync] :: InitDbOptions -> Bool [initDbDebug] :: InitDbOptions -> Bool [initDbExtraOptions] :: InitDbOptions -> [String] defaultInitDbOptions :: InitDbOptions -- | Stop postgres and clean up the temporary database folder. stop :: DB -> IO (Maybe ExitCode) -- | This throws AnotherPostgresProcessActive if the postgres has -- not been stopped using stopPostgres. This function attempts to -- the pidLock before running. If postgres process fails this -- throws StartPostgresFailed. If the postgres process becomes -- Nothing while starting this function throws -- StartPostgresDisappeared. startPostgres :: DB -> IO () -- | Stop the postgres process. This function attempts to the -- pidLock before running. stopPostgres will terminate all -- connections before shutting down postgres. stopPostgres is -- useful for testing backup strategies. stopPostgres :: DB -> IO (Maybe ExitCode) -- | Send the SIGHUP signal to the postgres process to start a config -- reload reloadConfig :: DB -> IO () data SocketClass Localhost :: SocketClass Unix :: SocketClass