Initial monorepo structure
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
"""Email message model for conversation threads."""
|
||||
|
||||
from sqlalchemy import Column, Text, DateTime, ForeignKey, Integer, String, Boolean
|
||||
from sqlalchemy.orm import relationship
|
||||
from app.models.base import Base, TimestampMixin
|
||||
|
||||
|
||||
class EmailMessage(Base, TimestampMixin):
|
||||
"""Email message model for ticket conversation threads."""
|
||||
|
||||
__tablename__ = "email_messages"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
ticket_id = Column(Integer, ForeignKey("tickets.id", ondelete="CASCADE"), nullable=False)
|
||||
|
||||
# Email metadata
|
||||
direction = Column(String(10), nullable=False) # 'incoming' or 'outgoing'
|
||||
message_id = Column(String(500)) # RFC 2822 Message-ID for threading
|
||||
in_reply_to = Column(String(500)) # In-Reply-To for threading
|
||||
references = Column(Text) # References header for threading
|
||||
|
||||
# Email addresses
|
||||
from_address = Column(String(500), nullable=False)
|
||||
to_addresses = Column(Text, nullable=False) # Comma-separated
|
||||
cc_addresses = Column(Text)
|
||||
|
||||
# Content
|
||||
subject = Column(String(4000))
|
||||
body_text = Column(Text) # Plain text body
|
||||
body_html = Column(Text) # HTML body
|
||||
|
||||
# Status
|
||||
is_read = Column(Boolean, default=False)
|
||||
sent_at = Column(DateTime) # When the email was actually sent
|
||||
received_at = Column(DateTime) # When the email was received
|
||||
|
||||
# User who sent the reply (for outgoing)
|
||||
sent_by = Column(Integer, ForeignKey("users.id", ondelete="SET NULL"))
|
||||
|
||||
# Relationships
|
||||
ticket = relationship("Ticket", back_populates="email_messages")
|
||||
sender = relationship("User", foreign_keys=[sent_by])
|
||||
attachments = relationship("EmailAttachment", back_populates="email_message", cascade="all, delete-orphan")
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"<EmailMessage(id={self.id}, direction='{self.direction}', subject='{self.subject}')>"
|
||||
|
||||
|
||||
class EmailAttachment(Base, TimestampMixin):
|
||||
"""Email attachment model."""
|
||||
|
||||
__tablename__ = "email_attachments"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
email_message_id = Column(Integer, ForeignKey("email_messages.id", ondelete="CASCADE"), nullable=False)
|
||||
|
||||
# File info
|
||||
filename = Column(String(500), nullable=False)
|
||||
content_type = Column(String(255))
|
||||
file_size = Column(Integer) # Size in bytes
|
||||
file_path = Column(String(1000)) # Path to stored file
|
||||
|
||||
# Relationships
|
||||
email_message = relationship("EmailMessage", back_populates="attachments")
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"<EmailAttachment(id={self.id}, filename='{self.filename}')>"
|
||||
Reference in New Issue
Block a user