def clean_db(
    alias: str, **kwargs: Dict[str, Any]
) -> Iterator[sqlalchemy_db.SQLAlchemyDB]:
    """Yields a clean database instance for the given database type.

    Args:
        alias: Database type to use from the following: `sqlite_file`,
            `sqlite_memory`, `postgres`, `mysql`.

        kwargs: Additional keyword arguments to pass to the database
            constructor.
    """

    with TemporaryDirectory(ignore_cleanup_errors=True) as tmp:
        # NOTE: The parameters below come from the docker definition in the
        # `docker/test-database.yaml` file.
        url = {
            "sqlite_memory": "sqlite:///:memory:",
            # TODO: Test this one more.
            # NOTE: Sqlalchemy docs say this should be written
            # "sqlite://:memory:" but that gives an error on mac at least.
            "sqlite_file": f"sqlite:///{Path(tmp) / 'test.sqlite'}",
            "postgres": "postgresql+psycopg://pg-test-user:pg-test-pswd@localhost/pg-test-db",
            "mysql": "mysql+pymysql://mysql-test-user:mysql-test-pswd@localhost/mysql-test-db",
        }[alias]

        db = sqlalchemy_db.SQLAlchemyDB.from_db_url(url, **kwargs)

        # NOTE(piotrm): I couldn't figure out why these things were done here.
        # db_migrations.downgrade_db(
        #    db.engine, revision="base"
        # )  # drops all tables except `db.version_table`
        # with db.engine.connect() as conn:
        #    conn.execute(text(f"DROP TABLE {db.table_prefix}version_table"))

        yield db
Yields a clean database instance for the given database type.

    Args:
        alias: Database type to use from the following: `sqlite_file`,
            `sqlite_memory`, `postgres`, `mysql`.

        kwargs: Additional keyword arguments to pass to the database
            constructor.
    
tests/integration/test_database.py