21 lines
573 B
Python
21 lines
573 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:
|
|
await conn.run_sync(Base.metadata.drop_all)
|
|
await conn.run_sync(Base.metadata.create_all)
|
|
finally:
|
|
await engine.dispose()
|
|
|
|
asyncio.run(_go())
|