28 lines
885 B
Python
28 lines
885 B
Python
from fastapi import APIRouter
|
|
|
|
from app.config import settings
|
|
from app.database import get_session
|
|
from app.models import DonationTier, Event, Program, StationConfig
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
@router.post("/reset")
|
|
async def reset_database():
|
|
"""Truncate all tables and re-seed. Dev-only — disabled in production."""
|
|
if settings.ENV == "production":
|
|
return {"error": "Admin reset is disabled in production"}
|
|
|
|
from app.database import async_session
|
|
from seed import seed as run_seed
|
|
|
|
async with async_session() as session:
|
|
await session.execute(Program.__table__.delete())
|
|
await session.execute(Event.__table__.delete())
|
|
await session.execute(DonationTier.__table__.delete())
|
|
await session.execute(StationConfig.__table__.delete())
|
|
await session.commit()
|
|
|
|
await run_seed()
|
|
return {"status": "reset complete"}
|