35 lines
1.5 KiB
Python
35 lines
1.5 KiB
Python
from datetime import datetime
|
|
from sqlalchemy import Integer, String, Text, DateTime, Index
|
|
from sqlalchemy.dialects.postgresql import JSONB
|
|
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
|
|
from sqlalchemy.sql import func
|
|
|
|
|
|
class Base(DeclarativeBase):
|
|
pass
|
|
|
|
|
|
class Message(Base):
|
|
__tablename__ = "messages"
|
|
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
|
msg_id: Mapped[str] = mapped_column(String(128), unique=True, nullable=False)
|
|
open_kfid: Mapped[str] = mapped_column(String(128), nullable=False)
|
|
external_userid: Mapped[str] = mapped_column(String(128), nullable=False)
|
|
servicer_userid: Mapped[str | None] = mapped_column(String(128))
|
|
send_time: Mapped[datetime] = mapped_column(DateTime, nullable=False)
|
|
msgtype: Mapped[str] = mapped_column(String(32), nullable=False)
|
|
origin: Mapped[str] = mapped_column(String(16), nullable=False)
|
|
content: Mapped[str | None] = mapped_column(Text)
|
|
raw_data: Mapped[dict | None] = mapped_column(JSONB)
|
|
direction: Mapped[str] = mapped_column(String(16), default="inbound")
|
|
status: Mapped[str] = mapped_column(String(32), default="received")
|
|
created_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now())
|
|
updated_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now(), onupdate=func.now())
|
|
|
|
__table_args__ = (
|
|
Index("idx_messages_external_userid", "external_userid"),
|
|
Index("idx_messages_send_time", "send_time"),
|
|
Index("idx_messages_open_kfid", "open_kfid"),
|
|
)
|