39 lines
1.5 KiB
Python
39 lines
1.5 KiB
Python
"""
|
|
StaticData ORM model - Static astronomical data
|
|
"""
|
|
from sqlalchemy import Column, String, Integer, TIMESTAMP, CheckConstraint, Index, UniqueConstraint
|
|
from sqlalchemy.dialects.postgresql import JSONB
|
|
from sqlalchemy.sql import func
|
|
from app.database import Base
|
|
|
|
|
|
class StaticData(Base):
|
|
"""Static astronomical data (constellations, galaxies, stars, etc.)"""
|
|
|
|
__tablename__ = "static_data"
|
|
|
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
|
category = Column(
|
|
String(50), nullable=False, comment="Data category"
|
|
)
|
|
name = Column(String(200), nullable=False, comment="Name")
|
|
name_zh = Column(String(200), nullable=True, comment="Chinese name")
|
|
data = Column(JSONB, nullable=False, comment="Complete data (JSON)")
|
|
created_at = Column(TIMESTAMP, server_default=func.now())
|
|
updated_at = Column(TIMESTAMP, server_default=func.now(), onupdate=func.now())
|
|
|
|
# Constraints and indexes
|
|
__table_args__ = (
|
|
CheckConstraint(
|
|
"category IN ('constellation', 'galaxy', 'star', 'nebula', 'cluster', 'asteroid_belt', 'kuiper_belt', 'interstellar')",
|
|
name="chk_category",
|
|
),
|
|
UniqueConstraint("category", "name", name="uq_category_name"),
|
|
Index("idx_static_data_category", "category"),
|
|
Index("idx_static_data_name", "name"),
|
|
Index("idx_static_data_data", "data", postgresql_using="gin"), # JSONB GIN index
|
|
)
|
|
|
|
def __repr__(self):
|
|
return f"<StaticData(id={self.id}, category='{self.category}', name='{self.name}')>"
|