tmp-postgres-1.27.0.4: Start and stop a temporary postgres

Safe HaskellNone
LanguageHaskell2010

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

Documentation

data Event Source #

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 initdb, createdb and postgres.

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 postgres process.

Instances
Eq Event Source # 
Instance details

Defined in Database.Postgres.Temp.Internal.Core

Methods

(==) :: Event -> Event -> Bool #

(/=) :: Event -> Event -> Bool #

Ord Event Source # 
Instance details

Defined in Database.Postgres.Temp.Internal.Core

Methods

compare :: Event -> Event -> Ordering #

(<) :: Event -> Event -> Bool #

(<=) :: Event -> Event -> Bool #

(>) :: Event -> Event -> Bool #

(>=) :: Event -> Event -> Bool #

max :: Event -> Event -> Event #

min :: Event -> Event -> Event #

Show Event Source # 
Instance details

Defined in Database.Postgres.Temp.Internal.Core

Methods

showsPrec :: Int -> Event -> ShowS #

show :: Event -> String #

showList :: [Event] -> ShowS #

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.12.0.0

Constructors

StartPostgresFailed ExitCode

postgres failed before a connection succeeded. Most likely this is due to invalid configuration

InitDbFailed

initdb failed. This can be from invalid configuration or using a non-empty data directory

CreateDbFailed

createdb failed. This can be from invalid configuration or the database might already exist.

PlanFailed String [String]

The Plan was missing info and a complete Plan could not be created.

CompleteProcessConfigFailed String [String]

The ProcessConfig was missing info and a CompleteProcessConfig could not be created.

ConnectionTimedOut

Timed out waiting for postgres to accept a connection

DeleteDbError SqlError 
EmptyDataDirectory

This will happen if a Plan is missing a initDbConfig.

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 initdb folder.

SnapshotCopyFailed String ExitCode

We tried to copy a data directory to a snapshot folder and it failed

type Logger = Event -> IO () Source #

A way to log internal Events

Since: 1.12.0.0

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

startProcess Source #

Arguments

:: String

Process name

-> CompleteProcessConfig

Process config

-> IO ProcessHandle 

Start a process interactively and return the ProcessHandle

executeProcess Source #

Arguments

:: String

Process name

-> CompleteProcessConfig

Process config

-> IO ExitCode 

Start a process and block until it finishes return the ExitCode.

executeProcessAndTee Source #

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

data PostgresProcess Source #

The output of calling startPostgresProcess.

Constructors

PostgresProcess 

Fields

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.

data Plan Source #

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.

Instances
Pretty Plan Source # 
Instance details

Defined in Database.Postgres.Temp.Internal.Core

Methods

pretty :: Plan -> Doc #

prettyList :: [Plan] -> Doc #

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.