history_base.py 932 B

12345678910111213141516171819202122232425
  1. """
  2. 历史记录基类
  3. """
  4. from datetime import datetime
  5. from app.utils.timezone import beijing_now_naive
  6. from sqlalchemy import Column, Integer, String, DateTime
  7. from app.database import Base
  8. class HistoryBase(Base):
  9. """主表基类:提供 id、created_at、updated_at 等通用字段"""
  10. __abstract__ = True
  11. id = Column(Integer, primary_key=True, autoincrement=True, comment="主键ID")
  12. created_at = Column(DateTime, default=beijing_now_naive, comment="创建时间")
  13. updated_at = Column(DateTime, default=beijing_now_naive, onupdate=beijing_now_naive, comment="更新时间")
  14. class HistoryRecord(Base):
  15. """历史记录基类"""
  16. __abstract__ = True
  17. # 原表所有字段的副本
  18. his_created_at = Column(DateTime, default=beijing_now_naive, comment="历史记录创建时间")
  19. his_operation = Column(String(10), nullable=False, comment="操作类型: INSERT/UPDATE/DELETE/RENEW")