""" Add Pluto to celestial bodies database """ import asyncio from sqlalchemy.dialects.postgresql import insert as pg_insert from app.database import get_db from app.models.db.celestial_body import CelestialBody from app.models.db.resource import Resource async def add_pluto(): """Add Pluto to the database""" async for session in get_db(): try: # Add Pluto as a celestial body print("šŸ“ Adding Pluto to celestial_bodies table...") stmt = pg_insert(CelestialBody).values( id="999", name="Pluto", name_zh="å†„ēŽ‹ę˜Ÿ", type="planet", description="å†„ēŽ‹ę˜Ÿļ¼Œę›¾ē»ēš„ē¬¬ä¹å¤§č”Œę˜Ÿļ¼ŒēŽ°äøŗēŸ®č”Œę˜Ÿ" ) stmt = stmt.on_conflict_do_update( index_elements=['id'], set_={ 'name': "Pluto", 'name_zh': "å†„ēŽ‹ę˜Ÿ", 'type': "planet", 'description': "å†„ēŽ‹ę˜Ÿļ¼Œę›¾ē»ēš„ē¬¬ä¹å¤§č”Œę˜Ÿļ¼ŒēŽ°äøŗēŸ®č”Œę˜Ÿ" } ) await session.execute(stmt) await session.commit() print("āœ… Pluto added successfully!") # Check if Pluto texture exists import os texture_path = "upload/texture/2k_pluto.jpg" if os.path.exists(texture_path): print(f"\nšŸ“ø Found Pluto texture: {texture_path}") file_size = os.path.getsize(texture_path) # Add texture resource print("šŸ“¦ Adding Pluto texture to resources table...") stmt = pg_insert(Resource).values( body_id="999", resource_type="texture", file_path="texture/2k_pluto.jpg", file_size=file_size, mime_type="image/jpeg", extra_data=None ) stmt = stmt.on_conflict_do_update( index_elements=['body_id', 'resource_type', 'file_path'], set_={ 'file_size': file_size, 'mime_type': "image/jpeg", } ) await session.execute(stmt) await session.commit() print(f"āœ… Pluto texture resource added ({file_size} bytes)") else: print(f"\nāš ļø Pluto texture not found at {texture_path}") print(" Please add a 2k_pluto.jpg file to upload/texture/ directory") except Exception as e: print(f"āŒ Error adding Pluto: {e}") await session.rollback() raise finally: break if __name__ == "__main__": asyncio.run(add_pluto())