feat: add entitlement plans and topic sessions
This commit is contained in:
55
ai_knowledge_base_v2/apps/backend/app/models/entitlement.py
Normal file
55
ai_knowledge_base_v2/apps/backend/app/models/entitlement.py
Normal file
@@ -0,0 +1,55 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
from sqlalchemy import BigInteger, DateTime, ForeignKey, Integer, String, Text
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
from app.models.base import Base, TimestampMixin
|
||||
|
||||
PRIMARY_KEY_TYPE = BigInteger().with_variant(Integer, "sqlite")
|
||||
|
||||
|
||||
class EntitlementPlan(Base, TimestampMixin):
|
||||
__tablename__ = "sys_entitlement_plan"
|
||||
|
||||
id: Mapped[int] = mapped_column(PRIMARY_KEY_TYPE, primary_key=True, autoincrement=True)
|
||||
name: Mapped[str] = mapped_column(String(80), nullable=False)
|
||||
plan_type: Mapped[str] = mapped_column(String(30), index=True, nullable=False)
|
||||
description: Mapped[str | None] = mapped_column(String(255), nullable=True)
|
||||
validity_days: Mapped[int | None] = mapped_column(Integer, nullable=True)
|
||||
monthly_topic_limit: Mapped[int | None] = mapped_column(Integer, nullable=True)
|
||||
enable_growth_profile: Mapped[int] = mapped_column(Integer, default=0, nullable=False)
|
||||
enable_periodic_reports: Mapped[int] = mapped_column(Integer, default=0, nullable=False)
|
||||
allow_help_card: Mapped[int] = mapped_column(Integer, default=1, nullable=False)
|
||||
allow_share_draft: Mapped[int] = mapped_column(Integer, default=1, nullable=False)
|
||||
deduct_quota: Mapped[int] = mapped_column(Integer, default=1, nullable=False)
|
||||
status: Mapped[int] = mapped_column(Integer, default=1, index=True, nullable=False)
|
||||
sort_order: Mapped[int] = mapped_column(Integer, default=0, nullable=False)
|
||||
|
||||
|
||||
class UserEntitlement(Base, TimestampMixin):
|
||||
__tablename__ = "sys_user_entitlement"
|
||||
|
||||
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)
|
||||
plan_id: Mapped[int] = mapped_column(ForeignKey("sys_entitlement_plan.id"), index=True, nullable=False)
|
||||
status: Mapped[str] = mapped_column(String(20), default="active", index=True, nullable=False)
|
||||
effective_at: Mapped[datetime | None] = mapped_column(DateTime, nullable=True)
|
||||
expired_at: Mapped[datetime | None] = mapped_column(DateTime, nullable=True)
|
||||
assigned_by: Mapped[int | None] = mapped_column(BigInteger, nullable=True)
|
||||
remark: Mapped[str | None] = mapped_column(String(255), nullable=True)
|
||||
|
||||
|
||||
class UserEntitlementLog(Base):
|
||||
__tablename__ = "sys_user_entitlement_log"
|
||||
|
||||
id: Mapped[int] = mapped_column(PRIMARY_KEY_TYPE, primary_key=True, autoincrement=True)
|
||||
user_id: Mapped[int] = mapped_column(BigInteger, index=True, nullable=False)
|
||||
entitlement_id: Mapped[int | None] = mapped_column(BigInteger, nullable=True)
|
||||
from_plan_id: Mapped[int | None] = mapped_column(BigInteger, nullable=True)
|
||||
to_plan_id: Mapped[int | None] = mapped_column(BigInteger, nullable=True)
|
||||
action: Mapped[str] = mapped_column(String(30), nullable=False)
|
||||
detail_json: Mapped[str | None] = mapped_column(Text, nullable=True)
|
||||
operated_by: Mapped[int | None] = mapped_column(BigInteger, nullable=True)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime, nullable=False)
|
||||
Reference in New Issue
Block a user