""" CelestialBody ORM model """ from sqlalchemy import Column, String, Text, TIMESTAMP, Boolean, Integer, ForeignKey, CheckConstraint, Index from sqlalchemy.dialects.postgresql import JSONB from sqlalchemy.sql import func from sqlalchemy.orm import relationship from app.database import Base class CelestialBody(Base): """Celestial body (star, planet, probe, etc.)""" __tablename__ = "celestial_bodies" id = Column(String(50), primary_key=True, comment="JPL Horizons ID or custom ID") name = Column(String(200), nullable=False, comment="English name") name_zh = Column(String(200), nullable=True, comment="Chinese name") type = Column(String(50), nullable=False, comment="Body type") system_id = Column(Integer, ForeignKey('star_systems.id', ondelete='CASCADE'), nullable=True, comment="所属恒星系ID") description = Column(Text, nullable=True, comment="Description") details = Column(Text, nullable=True, comment="Detailed description (Markdown)") is_active = Column(Boolean, nullable=True, comment="Active status for probes (True=active, False=inactive)") extra_data = Column(JSONB, nullable=True, comment="Extended metadata (JSON)") created_at = Column(TIMESTAMP, server_default=func.now()) updated_at = Column(TIMESTAMP, server_default=func.now(), onupdate=func.now()) # Relationships star_system = relationship("StarSystem", back_populates="celestial_bodies") positions = relationship( "Position", back_populates="body", cascade="all, delete-orphan" ) resources = relationship( "Resource", back_populates="body", cascade="all, delete-orphan" ) # Constraints __table_args__ = ( CheckConstraint( "type IN ('star', 'planet', 'moon', 'probe', 'comet', 'asteroid', 'dwarf_planet', 'satellite')", name="chk_type", ), Index("idx_celestial_bodies_type", "type"), Index("idx_celestial_bodies_name", "name"), Index("idx_celestial_bodies_system", "system_id"), ) def __repr__(self): return f""