Files
estimator/tests/helpers.py
T
2026-11-09 08:43:30 +03:00

23 lines
715 B
Python

import asyncio
from sqlalchemy.ext.asyncio import create_async_engine
from estimator.infra.db import Base, normalize_dsn
def create_schema(dsn: str) -> None:
"""Fresh tables for a test database (drops existing ones)."""
async def _go() -> None:
engine = create_async_engine(normalize_dsn(dsn))
try:
async with engine.begin() as conn:
if conn.dialect.name == "postgresql":
await conn.exec_driver_sql("CREATE EXTENSION IF NOT EXISTS vector")
await conn.run_sync(Base.metadata.drop_all)
await conn.run_sync(Base.metadata.create_all)
finally:
await engine.dispose()
asyncio.run(_go())