initialize_database¶
- async safir.database.initialize_database(engine: sqlalchemy.ext.asyncio.engine.AsyncEngine, logger: structlog.stdlib.BoundLogger, *, schema: sqlalchemy.sql.schema.MetaData, reset: bool = False) None ¶
Create and initialize a new database.
- Parameters
engine (
sqlalchemy.ext.asyncio.AsyncEngine
) – Database engine to use. Create withcreate_database_engine
.logger (
structlog.stdlib.BoundLogger
) – Logger used to report problemsschema (
sqlalchemy.sql.schema.MetaData
) – Metadata for the database schema. Generally this will beBase.metadata
whereBase
is the declarative base used as the base class for all ORM table definitions. The caller must ensure that all table definitions have been imported by Python before calling this function, or parts of the schema will be missing.reset (
bool
, optional) – If set toTrue
, drop all tables and reprovision the database. Useful when running tests with an external database. Default isFalse
.
- Raises
DatabaseInitializationError – After five attempts, the database still could not be initialized. This is normally due to some connectivity issue to the database.