@hackage tmp-postgres1.0.1.0
Start and stop a temporary postgres
Categories
License
BSD-3-Clause
Maintainer
jonathangfischoff@gmail.com
Links
Versions
Installation
Tested Compilers
Dependencies (13)
- async
- base >=4.6 && <5
- bytestring
- directory
- either
- generic-monoid Show all…
Dependents (16)
@hackage/sydtest-persistent-postgresql, @hackage/trek-db, @hackage/hasql-interpolate, @hackage/pg-entity, @hackage/rel8, @hackage/pg-transact, Show all…
tmp-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)"
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.
- By disabling
initdbandcreatedbone could run a temporary postgres on a base backup to test a migration. - By using the
stopPostgresandwithRestartfunctions one can test backup strategies.
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.
Installation
macOS
$ brew install postgres
$ stack install tmp-postgres
Ubuntu
Ubuntu's PostgreSQL installation does not put initdb on the PATH. We need to add it manually.
$ sudo apt-get install postgresql-VERSION
$ echo "export PATH=$PATH:/usr/lib/postgresql/VERSION/bin/" >> /home/ubuntu/.bashrc
$ stack install tmp-postgres