This commit is contained in:
itqop 2025-12-30 23:23:33 +03:00
parent aaa02622e7
commit d4d26d35a1
1 changed files with 3 additions and 4 deletions

View File

@ -21,19 +21,18 @@ async def lifespan(app: FastAPI):
# TEMPORARY: Clean up old deleted assets (remove this after first run)
from app.infra.database import AsyncSessionLocal
from sqlalchemy import text
import logging
logger = logging.getLogger(__name__)
async with AsyncSessionLocal() as session:
# Check how many deleted assets exist
result = await session.execute(text("SELECT COUNT(*) FROM assets WHERE status = 'deleted'"))
count_before = result.scalar()
logger.info(f"Found {count_before} assets with status='deleted'")
print(f"[MIGRATION] Found {count_before} assets with status='deleted'")
# Delete them
result = await session.execute(text("DELETE FROM assets WHERE status = 'deleted'"))
await session.commit()
logger.info(f"Deleted {result.rowcount} assets with status='deleted'")
print(f"[MIGRATION] Deleted {result.rowcount} assets with status='deleted'")
print("[MIGRATION] Migration complete - you can now remove this code from main.py")
# END TEMPORARY
yield