47 lines
1.8 KiB
Python
47 lines
1.8 KiB
Python
"""
|
|
CelestialBody ORM model
|
|
"""
|
|
from sqlalchemy import Column, String, Text, TIMESTAMP, Boolean, 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")
|
|
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
|
|
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"),
|
|
)
|
|
|
|
def __repr__(self):
|
|
return f"<CelestialBody(id='{self.id}', name='{self.name}', type='{self.type}')>"
|