69 lines
2.5 KiB
Python
69 lines
2.5 KiB
Python
"""
|
|
Check database status: bodies, positions, resources
|
|
"""
|
|
import asyncio
|
|
import os
|
|
import sys
|
|
from datetime import datetime
|
|
|
|
# Add backend directory to path
|
|
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
|
|
|
|
from app.database import get_db
|
|
from app.models.db.celestial_body import CelestialBody
|
|
from app.models.db.position import Position
|
|
from app.models.db.resource import Resource
|
|
from sqlalchemy import select, func
|
|
|
|
async def check_status():
|
|
"""Check database status"""
|
|
print("🔍 Checking database status...")
|
|
|
|
async for session in get_db():
|
|
try:
|
|
# 1. Check Celestial Bodies
|
|
stmt = select(func.count(CelestialBody.id))
|
|
result = await session.execute(stmt)
|
|
body_count = result.scalar()
|
|
print(f"✅ Celestial Bodies: {body_count}")
|
|
|
|
# 2. Check Positions
|
|
stmt = select(func.count(Position.id))
|
|
result = await session.execute(stmt)
|
|
position_count = result.scalar()
|
|
print(f"✅ Total Positions: {position_count}")
|
|
|
|
# Check positions for Sun (10) and Earth (399)
|
|
for body_id in ['10', '399']:
|
|
stmt = select(func.count(Position.id)).where(Position.body_id == body_id)
|
|
result = await session.execute(stmt)
|
|
count = result.scalar()
|
|
print(f" - Positions for {body_id}: {count}")
|
|
|
|
if count > 0:
|
|
# Get latest position date
|
|
stmt = select(func.max(Position.time)).where(Position.body_id == body_id)
|
|
result = await session.execute(stmt)
|
|
latest_date = result.scalar()
|
|
print(f" Latest date: {latest_date}")
|
|
|
|
# 3. Check Resources
|
|
stmt = select(func.count(Resource.id))
|
|
result = await session.execute(stmt)
|
|
resource_count = result.scalar()
|
|
print(f"✅ Total Resources: {resource_count}")
|
|
|
|
# Check resources for Sun (10)
|
|
stmt = select(Resource).where(Resource.body_id == '10')
|
|
result = await session.execute(stmt)
|
|
resources = result.scalars().all()
|
|
print(f" - Resources for Sun (10): {len(resources)}")
|
|
for r in resources:
|
|
print(f" - {r.resource_type}: {r.file_path}")
|
|
|
|
finally:
|
|
break
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(check_status())
|