cosmo/backend/app/models/db/rocket_event.py

57 lines
2.5 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

"""Rocket launch event ORM model."""
from sqlalchemy import (
Column, Double, ForeignKey, Integer, String, Text, TIMESTAMP, UniqueConstraint,
)
from sqlalchemy.sql import func
from sqlalchemy.orm import relationship
from app.database import Base
class RocketEvent(Base):
"""一次真实的火箭发射事件(来自外部持续更新的发射计划数据源)。
与 rocket_configs 的关系:rocket_config_id 指向本地建模的运载型号,
数据源里那些本地还没建模的型号该字段为空,型号原名仍保留在 rocket_name。
时间一律为无时区 UTC,和库里其它时间字段一致。
"""
__tablename__ = "rocket_events"
id = Column(Integer, primary_key=True, autoincrement=True)
source = Column(String(32), nullable=False, default="thespacedevs", comment="数据源标识")
source_id = Column(String(64), nullable=False, comment="数据源侧的发射 ID")
rocket_config_id = Column(
Integer, ForeignKey("rocket_configs.id", ondelete="SET NULL"), nullable=True, index=True,
)
name = Column(String(200), nullable=False, comment="发射任务标题")
mission_name = Column(String(200), nullable=True)
mission_description = Column(Text, nullable=True)
mission_type = Column(String(60), nullable=True)
rocket_name = Column(String(120), nullable=True, comment="数据源侧运载火箭型号名")
provider = Column(String(120), nullable=True, comment="发射服务商")
orbit = Column(String(60), nullable=True)
launch_site_name = Column(String(120), nullable=True, comment="发射工位")
location_name = Column(String(120), nullable=True, comment="发射场")
latitude = Column(Double, nullable=True)
longitude = Column(Double, nullable=True)
net = Column(TIMESTAMP, nullable=False, index=True, comment="发射时间 T-0(UTC)")
status = Column(String(40), nullable=False, default="", comment="发射状态")
image_url = Column(String(500), nullable=True)
source_url = Column(String(300), nullable=True)
created_at = Column(TIMESTAMP, server_default=func.now())
updated_at = Column(TIMESTAMP, server_default=func.now(), onupdate=func.now())
__table_args__ = (
UniqueConstraint("source", "source_id", name="uq_rocket_events_source_id"),
)
rocket = relationship("RocketConfig", foreign_keys=[rocket_config_id])
def __repr__(self):
return f"<RocketEvent(id={self.id}, name='{self.name}', net={self.net})>"