""" Reset position data to fix units (KM -> AU) """ import asyncio import os import sys # 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 import Position from app.services.redis_cache import redis_cache from sqlalchemy import text async def reset_data(): """Clear positions and cache to force re-fetch in AU""" print("๐Ÿงน Clearing old data (KM) to prepare for AU...") async for session in get_db(): try: # Clear positions table print(" Truncating positions table...") await session.execute(text("TRUNCATE TABLE positions RESTART IDENTITY CASCADE")) # Clear nasa_cache table (if it exists as a table, or if it's just redis?) # nasa_cache is in db models? # Let's check models/db directory... # It seems nasa_cache is a table based on `nasa_cache_service`. print(" Truncating nasa_cache table...") try: await session.execute(text("TRUNCATE TABLE nasa_cache RESTART IDENTITY CASCADE")) except Exception as e: print(f" (Note: nasa_cache might not exist or failed: {e})") await session.commit() print("โœ… Database tables cleared.") # Clear Redis await redis_cache.connect() await redis_cache.clear_pattern("positions:*") await redis_cache.clear_pattern("nasa:*") print("โœ… Redis cache cleared.") await redis_cache.disconnect() except Exception as e: print(f"โŒ Error: {e}") await session.rollback() finally: break if __name__ == "__main__": asyncio.run(reset_data())