forked from linkong/planet
63 lines
3.0 KiB
Python
63 lines
3.0 KiB
Python
"""Versioned history table for curated compute comparison configurations."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from sqlalchemy import Boolean, Column, DateTime, Index, Integer, JSON, String, Text
|
|
from sqlalchemy.sql import func
|
|
|
|
from app.core.time import to_iso8601_utc
|
|
from app.db.session import Base
|
|
|
|
|
|
class ComputeConfigurationRevision(Base):
|
|
"""Immutable snapshot ledger of published compute comparison configurations."""
|
|
|
|
__tablename__ = "compute_configuration_revisions"
|
|
|
|
id = Column(Integer, primary_key=True, autoincrement=True, index=True)
|
|
publish_id = Column(String(64), unique=True, nullable=False, index=True)
|
|
parent_publish_id = Column(String(64), nullable=True, index=True)
|
|
action = Column(String(16), nullable=False, default="publish")
|
|
content_fingerprint = Column(String(64), nullable=False, index=True)
|
|
is_default_content = Column(Boolean, nullable=False, default=False)
|
|
config_payload = Column(JSON, nullable=False, default=dict)
|
|
diff_summary = Column(JSON, nullable=False, default=list)
|
|
source_candidate_ids = Column(JSON, nullable=False, default=list)
|
|
publish_note = Column(Text, nullable=False, default="")
|
|
published_by_id = Column(Integer, nullable=True)
|
|
published_by_name = Column(String(120), nullable=True)
|
|
published_by_role = Column(String(40), nullable=True)
|
|
published_at = Column(
|
|
DateTime(timezone=True), server_default=func.now(), nullable=False, index=True
|
|
)
|
|
presentation_status = Column(String(16), nullable=False, default="pending", index=True)
|
|
presentation_attempts = Column(Integer, nullable=False, default=0)
|
|
presentation_error = Column(Text, nullable=False, default="")
|
|
presentation_delivered_at = Column(DateTime(timezone=True), nullable=True)
|
|
|
|
__table_args__ = (
|
|
Index("idx_compute_config_revisions_published_at", "published_at"),
|
|
Index("idx_compute_config_revisions_pres_status", "presentation_status", "id"),
|
|
)
|
|
|
|
def to_dict(self) -> dict:
|
|
return {
|
|
"id": self.id,
|
|
"publish_id": self.publish_id,
|
|
"parent_publish_id": self.parent_publish_id,
|
|
"action": self.action,
|
|
"content_fingerprint": self.content_fingerprint,
|
|
"is_default_content": bool(self.is_default_content),
|
|
"diff_summary": list(self.diff_summary or []),
|
|
"source_candidate_ids": list(self.source_candidate_ids or []),
|
|
"publish_note": self.publish_note or "",
|
|
"published_by_id": self.published_by_id,
|
|
"published_by_name": self.published_by_name,
|
|
"published_by_role": self.published_by_role,
|
|
"published_at": to_iso8601_utc(self.published_at),
|
|
"presentation_status": self.presentation_status,
|
|
"presentation_attempts": int(self.presentation_attempts or 0),
|
|
"presentation_error": self.presentation_error or "",
|
|
"presentation_delivered_at": to_iso8601_utc(self.presentation_delivered_at),
|
|
}
|