78 lines
2.8 KiB
Python
78 lines
2.8 KiB
Python
"""
|
|
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())
|