feat: isolate external application conversations
This commit is contained in:
@@ -2,17 +2,32 @@ from __future__ import annotations
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
from sqlalchemy import BigInteger, DateTime, ForeignKey, Integer, String, Text, func
|
||||
from sqlalchemy import BigInteger, DateTime, ForeignKey, Index, Integer, String, Text, func
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
from app.models.base import Base, TimestampMixin
|
||||
|
||||
|
||||
PRIMARY_KEY_TYPE = BigInteger().with_variant(Integer, "sqlite")
|
||||
|
||||
|
||||
class ChatSession(Base, TimestampMixin):
|
||||
__tablename__ = "sys_chat_session"
|
||||
__table_args__ = (
|
||||
Index(
|
||||
"ix_chat_session_user_source_active_updated",
|
||||
"user_id",
|
||||
"source_type",
|
||||
"source_client_id",
|
||||
"is_deleted",
|
||||
"updated_at",
|
||||
),
|
||||
)
|
||||
|
||||
id: Mapped[int] = mapped_column(BigInteger, primary_key=True, autoincrement=True)
|
||||
id: Mapped[int] = mapped_column(PRIMARY_KEY_TYPE, primary_key=True, autoincrement=True)
|
||||
user_id: Mapped[int] = mapped_column(ForeignKey("sys_user.id"), index=True, nullable=False)
|
||||
source_type: Mapped[str] = mapped_column(String(20), default="direct", nullable=False)
|
||||
source_client_id: Mapped[int | None] = mapped_column(BigInteger, nullable=True)
|
||||
title: Mapped[str] = mapped_column(String(100), nullable=False)
|
||||
summary: Mapped[str | None] = mapped_column(Text, nullable=True)
|
||||
summary_up_to_message_id: Mapped[int | None] = mapped_column(BigInteger, nullable=True)
|
||||
|
||||
@@ -20,6 +20,8 @@ class SsoClient(Base):
|
||||
name: Mapped[str] = mapped_column(String(100), nullable=False)
|
||||
client_secret: Mapped[str] = mapped_column(Text, nullable=False)
|
||||
redirect_uris: Mapped[str] = mapped_column(Text, default="[]", nullable=False)
|
||||
allow_auto_register: Mapped[int] = mapped_column(Integer, default=0, nullable=False)
|
||||
default_entitlement_plan_id: Mapped[int | None] = mapped_column(BigInteger, nullable=True)
|
||||
status: Mapped[int] = mapped_column(Integer, default=1, nullable=False)
|
||||
created_by: Mapped[int | None] = mapped_column(BigInteger, nullable=True)
|
||||
last_used_at: Mapped[datetime | None] = mapped_column(DateTime, nullable=True)
|
||||
|
||||
@@ -8,13 +8,18 @@ from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
from app.models.base import Base, SoftDeleteMixin, TimestampMixin
|
||||
|
||||
|
||||
PRIMARY_KEY_TYPE = BigInteger().with_variant(Integer, "sqlite")
|
||||
|
||||
|
||||
class User(Base, TimestampMixin, SoftDeleteMixin):
|
||||
__tablename__ = "sys_user"
|
||||
|
||||
id: Mapped[int] = mapped_column(BigInteger, primary_key=True, autoincrement=True)
|
||||
id: Mapped[int] = mapped_column(PRIMARY_KEY_TYPE, primary_key=True, autoincrement=True)
|
||||
phone: Mapped[str] = mapped_column(String(20), unique=True, index=True, nullable=False)
|
||||
name: Mapped[str] = mapped_column(String(50), nullable=False)
|
||||
nickname: Mapped[str | None] = mapped_column(String(50), nullable=True)
|
||||
registration_source: Mapped[str] = mapped_column(String(30), default="direct", nullable=False)
|
||||
registration_client_id: Mapped[int | None] = mapped_column(BigInteger, nullable=True, index=True)
|
||||
status: Mapped[int] = mapped_column(default=1, nullable=False)
|
||||
daily_chat_limit: Mapped[int] = mapped_column(Integer, default=100, nullable=False)
|
||||
daily_chat_used: Mapped[int] = mapped_column(Integer, default=0, nullable=False)
|
||||
|
||||
Reference in New Issue
Block a user