ticket_message.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. from sqlalchemy import (
  2. Column,
  3. Integer,
  4. ForeignKey,
  5. Enum,
  6. Text,
  7. DateTime,
  8. JSON,
  9. Index,
  10. String
  11. )
  12. from datetime import datetime
  13. from app.core.database import Base
  14. class VasTicketMessage(Base):
  15. __tablename__ = "vas_ticket_message"
  16. __ddl__ = """
  17. CREATE TABLE IF NOT EXISTS `vas_ticket_message` (
  18. `id` INT NOT NULL AUTO_INCREMENT,
  19. `ticket_id` INT NOT NULL,
  20. `sender_type` ENUM('user','admin','system') NOT NULL,
  21. `sender_id` VARCHAR(128) NULL,
  22. `content` TEXT NOT NULL,
  23. `attachments` JSON NULL,
  24. `created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  25. PRIMARY KEY (`id`),
  26. KEY `idx_vas_ticket_msg_ticket_id` (`ticket_id`)
  27. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='工单沟通对话消息表';
  28. """
  29. id = Column(Integer, primary_key=True, autoincrement=True)
  30. ticket_id = Column(Integer, nullable=False)
  31. sender_type = Column(
  32. Enum("user", "admin", "system", name="ticket_sender_enum"),
  33. nullable=False
  34. )
  35. sender_id = Column(String(128), nullable=True)
  36. content = Column(Text, nullable=False)
  37. attachments = Column(JSON) # 图片 / 文件
  38. created_at = Column(DateTime, default=datetime.utcnow)