-- 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.2.0.0 module Database.Postgres.Temp.Internal getFreePort :: IO Int waitForDB :: String -> IO () withLock :: MVar a -> IO b -> IO b data DB DB :: FilePath -> String -> [(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. [connectionString] :: DB -> String -- | 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 SocketClass Localhost :: SocketClass Unix :: SocketClass -- | start postgres and use the current processes stdout and stderr start :: [(String, String)] -> 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 :: [(String, String)] -> 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 -> [(String, String)] -> Handle -> Handle -> IO (Either StartError DB) startWithHandlesAndDir :: SocketClass -> [(String, String)] -> 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 -> [(String, String)] -> FilePath -> Handle -> Handle -> IO (Either StartError DB) -- | Start postgres and log it's all stdout to {mainDir}/output.txt -- and {mainDir}/error.txt startAndLogToTmp :: [(String, String)] -> 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) 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 -> String -> [(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. [connectionString] :: DB -> String -- | 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 :: [(String, String)] -> 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 :: [(String, String)] -> IO (Either StartError DB) -- | Start postgres and log it's all stdout to {mainDir}/output.txt -- and {mainDir}/error.txt startAndLogToTmp :: [(String, String)] -> IO (Either StartError DB) -- | Start postgres and pass in handles for stdout and stderr startWithHandles :: SocketClass -> [(String, String)] -> Handle -> Handle -> IO (Either StartError DB) -- | 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