| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Database.Postgres.Temp.Internal.Core
Description
This module provides the low level functionality for running initdb, postgres and createdb to make a database.
See startPlan for more details.
Synopsis
- data Event
- data StartError
- = StartPostgresFailed ExitCode
- | InitDbFailed { }
- | CreateDbFailed { }
- | PlanFailed String [String]
- | CompleteProcessConfigFailed String [String]
- | ConnectionTimedOut
- | DeleteDbError SqlError
- | EmptyDataDirectory
- | CopyCachedInitDbFailed String ExitCode
- | FailedToFindDataDirectory String
- | SnapshotCopyFailed String ExitCode
- type Logger = Event -> IO ()
- waitForDB :: Logger -> Options -> IO ()
- data CompleteProcessConfig = CompleteProcessConfig {}
- startProcess :: String -> CompleteProcessConfig -> IO ProcessHandle
- stopProcess :: ProcessHandle -> IO ExitCode
- executeProcess :: String -> CompleteProcessConfig -> IO ExitCode
- executeProcessAndTee :: String -> CompleteProcessConfig -> IO (ExitCode, String, String)
- data CompletePostgresPlan = CompletePostgresPlan {}
- data PostgresProcess = PostgresProcess {}
- stopPostgresProcess :: Bool -> PostgresProcess -> IO ExitCode
- startPostgresProcess :: Int -> Logger -> CompletePostgresPlan -> IO PostgresProcess
- executeCreateDb :: CompleteProcessConfig -> IO ()
- data Plan = Plan {
- completePlanLogger :: Logger
- completePlanInitDb :: Maybe (Either CompleteProcessConfig InitDbCachePlan)
- completePlanCopy :: Maybe CompleteCopyDirectoryCommand
- completePlanCreateDb :: Maybe CompleteProcessConfig
- completePlanPostgres :: CompletePostgresPlan
- completePlanConfig :: String
- completePlanDataDirectory :: FilePath
- completePlanConnectionTimeout :: Int
- startPlan :: Plan -> IO PostgresProcess
- stopPlan :: PostgresProcess -> IO ExitCode
Documentation
Internal events for debugging
Since: 1.12.0.0
Constructors
| StartPlan String | The first event. This useful for debugging
what is actual passed to the |
| StartPostgres | The second event. Postgres is about to get called |
| WaitForDB | The third event. Postgres started. We are now about to setup a reconnect loop (racing with a process checker) |
| TryToConnect | The fourth event and (possibly all subsequent events).
We are looping trying to successfully connect to the |
data StartError Source #
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.
Since: 1.29.0.0
Constructors
| StartPostgresFailed ExitCode |
|
| InitDbFailed |
|
Fields | |
| CreateDbFailed |
|
Fields | |
| PlanFailed String [String] | The |
| CompleteProcessConfigFailed String [String] | The |
| ConnectionTimedOut | Timed out waiting for |
| DeleteDbError SqlError | |
| EmptyDataDirectory | This will happen if a |
| CopyCachedInitDbFailed String ExitCode | This is called if copying a folder cache fails. |
| FailedToFindDataDirectory String | Failed to find a data directory when trying to get
a cached |
| SnapshotCopyFailed String ExitCode | We tried to copy a data directory to a snapshot folder and it failed |
Instances
| Eq StartError Source # | |
Defined in Database.Postgres.Temp.Internal.Core | |
| Show StartError Source # | |
Defined in Database.Postgres.Temp.Internal.Core Methods showsPrec :: Int -> StartError -> ShowS # show :: StartError -> String # showList :: [StartError] -> ShowS # | |
| Exception StartError Source # | |
Defined in Database.Postgres.Temp.Internal.Core Methods toException :: StartError -> SomeException # fromException :: SomeException -> Maybe StartError # displayException :: StartError -> String # | |
waitForDB :: Logger -> Options -> IO () Source #
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.
data CompleteProcessConfig Source #
CompleteProcessConfig contains the configuration necessary for starting a
process. It is essentially a stripped down CreateProcess.
Constructors
| CompleteProcessConfig | |
Fields
| |
Instances
| Pretty CompleteProcessConfig Source # | |
Defined in Database.Postgres.Temp.Internal.Core | |
Arguments
| :: String | Process name |
| -> CompleteProcessConfig | Process config |
| -> IO ProcessHandle |
Start a process interactively and return the ProcessHandle
stopProcess :: ProcessHandle -> IO ExitCode Source #
Stop a ProcessHandle. An alias for waitForProcess
Arguments
| :: String | Process name |
| -> CompleteProcessConfig | Process config |
| -> IO ExitCode |
Start a process and block until it finishes return the ExitCode.
Arguments
| :: String | Process name |
| -> CompleteProcessConfig | Process config |
| -> IO (ExitCode, String, String) |
Start a process and block until it finishes return the ExitCode and the
stderr output.
data CompletePostgresPlan Source #
CompletePostgresPlan is used be startPostgresProcess to start the
postgres and then attempt to connect to it.
Constructors
| CompletePostgresPlan | |
Fields
| |
Instances
| Pretty CompletePostgresPlan Source # | |
Defined in Database.Postgres.Temp.Internal.Core | |
data PostgresProcess Source #
The output of calling startPostgresProcess.
Constructors
| PostgresProcess | |
Fields
| |
Instances
| Pretty PostgresProcess Source # | |
Defined in Database.Postgres.Temp.Internal.Core | |
stopPostgresProcess :: Bool -> PostgresProcess -> IO ExitCode Source #
Stop the postgres process after attempting to terminate all the
connections.
startPostgresProcess :: Int -> Logger -> CompletePostgresPlan -> IO PostgresProcess Source #
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.
executeCreateDb :: CompleteProcessConfig -> IO () Source #
Call createdb and tee the output to return if there is an
an exception. Throws CreateDbFailed.
Plan is the low level configuration necessary for initializing
a database cluster
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.
Constructors
startPlan :: Plan -> IO PostgresProcess Source #
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.
stopPlan :: PostgresProcess -> IO ExitCode Source #
Stop the postgres process. See stopPostgresProcess for more details.