Database Schema and User Management Utilities#

(For downstream apps and services with their own database schemas)#

UserRoleBase(new_class_name, /, names, *[, ...])

Base class for representing user types.

create_user(conn, username, password, role)

Create a new database user with the specified role.

drop_users(conn, usernames)

Drop a user or users if they exist.

ensure_role(conn, role)

Ensure that a role exists and applies the role hierarchy.

grant_role(conn, role, users)

Grant a UserRole to a user(s).

has_role(conn, role_name[, ...])

Check if a role exists.

has_role_membership(conn, group_role, role)

Check whether an extending role has been granted a base role.

has_roles(conn, roles[, with_create_role, ...])

Check if a group of roles exist - calls has_role for each role.

create_schema(conn, name[, if_exists, owner])

Create a schema.

drop_schema(connection, schema_name)

Drop a schema and all its contents (if it exists).

has_schema(engine, schema_name)

Check if a schema exists.

transfers_required(conn, new_owner, schema, ...)

Determine which objects in a schema need to be transferred to a new owner.

transfer_ownership(conn, schema, obj_name, ...)

Transfer ownership of a database object to a new owner.

as_role(conn, role)

Context manager to temporarily switch database roles.

ensure_extension(conn, extension_name)

Ensure the database has the given extension installed (e.g. the PostGIS extension).

escape_pg_identifier(conn, name)

Escape identifiers for inclusion in SQL statements.

get_connection_info(conn)

Return the database name and currently active role of an SQLAlchemy connection.