seaworthy.containers.postgresql

PostgreSQL container definition.

class PostgreSQLContainer(name='postgresql', image='postgres:alpine', wait_patterns=('database system is ready to accept connections', 'database system is ready to accept connections'), database='database', user='user', password='password', **kwargs)[source]

PostgreSQL container definition.

Todo

Write more docs.

base_kwargs()[source]

Add a tmpfs entry for /var/lib/postgresql/data to avoid unnecessary disk I/O and environment entries for the configured db and user creds.

clean()[source]

Remove all data by dropping and recreating the configured database.

Note

Only the configured database is removed. Any other databases remain untouched.

database_url()[source]

Returns a “database URL” for use with DJ-Database-URL and similar libraries.

exec_pg_success(cmd)[source]

Execute a command inside a running container as the postgres user, asserting success.

exec_psql(command, psql_opts=['-qtA'])[source]

Execute a psql command inside a running container. By default the container’s database is connected to.

Parameters:
  • command – the command to run (passed to -c)
  • psql_opts – a list of extra options to pass to psql
Returns:

a tuple of the command exit code and output

list_databases()[source]

Runs the \list command and returns a list of column values with information about all databases.

list_tables()[source]

Runs the \dt command and returns a list of column values with information about all tables in the database.

list_users()[source]

Runs the \du command and returns a list of column values with information about all user roles.