#!/usr/bin/env python3 """Direct update celestial_type_configs using SQL""" import asyncio import sys import os import json sys.path.append(os.path.join(os.getcwd(), "backend")) from app.database import AsyncSessionLocal from sqlalchemy import select, update from app.models.db.system_settings import SystemSettings # Unified ratio for all types UNIFIED_RATIO = 0.00008 async def direct_update(): """Direct SQL update of celestial_type_configs""" async with AsyncSessionLocal() as session: # Get the setting record stmt = select(SystemSettings).where(SystemSettings.key == 'celestial_type_configs') result = await session.execute(stmt) setting = result.scalar_one_or_none() if not setting: print("āŒ Setting 'celestial_type_configs' not found!") return # Parse the JSON value current_value = json.loads(setting.value) if isinstance(setting.value, str) else setting.value print("BEFORE UPDATE:") print(json.dumps(current_value, indent=2)) # Update all ratios updated_config = {} for body_type, config in current_value.items(): updated_config[body_type] = { 'ratio': UNIFIED_RATIO, 'default': config.get('default', 0.5) } # Update the raw_value (stored as JSON string) setting.raw_value = json.dumps(updated_config) await session.commit() print("\nAFTER UPDATE:") print(json.dumps(updated_config, indent=2)) print(f"\nāœ… Successfully updated all ratios to {UNIFIED_RATIO}") if __name__ == "__main__": asyncio.run(direct_update())