221 lines
7.5 KiB
Python
221 lines
7.5 KiB
Python
from sqlalchemy import Column, String, Text, DateTime, ForeignKey, Boolean, Integer
|
|
from sqlalchemy.orm import declarative_base, relationship
|
|
from datetime import datetime
|
|
|
|
#Base = declarative_base()
|
|
from db import Base
|
|
|
|
class Conversation(Base):
|
|
__tablename__ = "conversations"
|
|
id = Column(String, primary_key=True)
|
|
user_email = Column(String, index=True) # filter by user
|
|
title = Column(String)
|
|
messages = relationship("Message", back_populates="conversation")
|
|
attachments = relationship("Attachment", back_populates="conversation")
|
|
tags = Column(String) # comma-separated tags
|
|
shared = Column(String) # null or email of recipient
|
|
|
|
class Message(Base):
|
|
__tablename__ = "messages"
|
|
id = Column(String, primary_key=True)
|
|
conversation_id = Column(String, ForeignKey("conversations.id"))
|
|
role = Column(String)
|
|
content = Column(Text)
|
|
created_at = Column(DateTime, default=datetime.utcnow)
|
|
conversation = relationship("Conversation", back_populates="messages")
|
|
|
|
class Attachment(Base):
|
|
__tablename__ = "attachments"
|
|
id = Column(String, primary_key=True)
|
|
conversation_id = Column(String, ForeignKey("conversations.id"))
|
|
filename = Column(String)
|
|
mime_type = Column(String)
|
|
path = Column(String) # /data/<uuid>
|
|
conversation = relationship("Conversation", back_populates="attachments")
|
|
|
|
|
|
class File(Base):
|
|
__tablename__ = "files"
|
|
id = Column(String, primary_key=True)
|
|
user_email = Column(String, ForeignKey("users.email"))
|
|
path = Column(String)
|
|
original_name = Column(String)
|
|
created_at = Column(DateTime, default=datetime.utcnow)
|
|
|
|
|
|
|
|
|
|
# ***
|
|
|
|
class User(Base):
|
|
__tablename__ = "users"
|
|
#id = Column(String, primary_key=True)
|
|
#email = Column(String, unique=True)
|
|
email = Column(String, primary_key=True)
|
|
name = Column(String)
|
|
password = Column(String)
|
|
totp_secret = Column(String, nullable=True)
|
|
twofa_enabled = Column(Boolean, default=False)
|
|
twofa_method = Column(String, default="totp")
|
|
twofa_secret = Column(String)
|
|
twofa_sensitive_actions = Column(Boolean, default=False)
|
|
|
|
role = Column(String, default="user") # "user", "admin"
|
|
|
|
# Legal
|
|
consent_training = Column(Boolean, default=False)
|
|
terms_accepted_at = Column(DateTime, nullable=True)
|
|
privacy_accepted_at = Column(DateTime, nullable=True)
|
|
dpa_accepted_at = Column(DateTime, nullable=True)
|
|
cookies_accepted_at = Column(DateTime, nullable=True)
|
|
security_accepted_at = Column(DateTime, nullable=True)
|
|
|
|
# Billing
|
|
plan_id = Column(String, ForeignKey("plans.id"), default="free")
|
|
company_id = Column(String)
|
|
|
|
# priority layer
|
|
priority = Column(String, default="user")
|
|
# system_admin, corp_admin, user
|
|
# values: system_admin, corp_admin, user
|
|
|
|
# ACL Default False
|
|
can_use_audio = Column(Boolean, default=False)
|
|
can_use_vision = Column(Boolean, default=False)
|
|
can_export_pdf = Column(Boolean, default=False)
|
|
|
|
# ACL Default True
|
|
can_share = Column(Boolean, default=True)
|
|
can_export_md = Column(Boolean, default=True)
|
|
can_import_docs = Column(Boolean, default=True)
|
|
can_import_excel = Column(Boolean, default=True)
|
|
|
|
|
|
class Cache(Base):
|
|
__tablename__ = "cache"
|
|
key = Column(String, primary_key=True)
|
|
model = Column(String)
|
|
response = Column(Text)
|
|
created_at = Column(DateTime, default=datetime.utcnow)
|
|
|
|
class Plan(Base):
|
|
__tablename__ = "plans"
|
|
id = Column(String, primary_key=True)
|
|
name = Column(String)
|
|
price_monthly = Column(Float)
|
|
price_yearly = Column(Float)
|
|
description = Column(Text)
|
|
|
|
# ACL / capabilities
|
|
can_use_audio = Column(Boolean, default=False)
|
|
can_use_vision = Column(Boolean, default=False)
|
|
can_import_docs = Column(Boolean, default=True)
|
|
can_import_excel = Column(Boolean, default=True)
|
|
can_export_pdf = Column(Boolean, default=False)
|
|
can_export_md = Column(Boolean, default=True)
|
|
priority_queue = Column(String, default="default") # default, premium, admin
|
|
max_conversations = Column(Integer, default=50)
|
|
max_attachment_size_mb = Column(Integer, default=10)
|
|
allowed_models = Column(Text) # JSON list of models
|
|
|
|
|
|
class Subscription(Base):
|
|
__tablename__ = "subscriptions"
|
|
id = Column(String, primary_key=True)
|
|
user_email = Column(String, ForeignKey("users.email"))
|
|
plan_id = Column(String, ForeignKey("plans.id"))
|
|
status = Column(String) # active, expired, canceled, pending
|
|
renew_at = Column(DateTime)
|
|
created_at = Column(DateTime, default=datetime.utcnow)
|
|
updated_at = Column(DateTime, default=datetime.utcnow)
|
|
|
|
|
|
|
|
class Preferences(Base):
|
|
__tablename__ = "preferences"
|
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
|
user_id = Column(String)
|
|
preferred_mode = Column(String, default="conversar")
|
|
auto_search = Column(Boolean, default=True)
|
|
auto_monitoring = Column(Boolean, default=False)
|
|
preferred_export = Column(String, default="pdfa")
|
|
likes_suggestions = Column(Boolean, default=True)
|
|
likes_quick_actions = Column(Boolean, default=True)
|
|
|
|
class Conversation(Base):
|
|
__tablename__ = "conversations"
|
|
id = Column(String, primary_key=True)
|
|
user_id = Column(String)
|
|
created_at = Column(DateTime, default=datetime.utcnow)
|
|
mode = Column(String)
|
|
context_summary = Column(Text)
|
|
|
|
class Message(Base):
|
|
__tablename__ = "messages"
|
|
id = Column(String, primary_key=True)
|
|
conversation_id = Column(String)
|
|
role = Column(String)
|
|
content = Column(Text)
|
|
metadata = Column(Text)
|
|
created_at = Column(DateTime, default=datetime.utcnow)
|
|
|
|
class MonitoringTopic(Base):
|
|
__tablename__ = "monitoring_topics"
|
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
|
user_id = Column(String)
|
|
label = Column(String)
|
|
sources = Column(Text)
|
|
created_at = Column(DateTime, default=datetime.utcnow)
|
|
active = Column(Boolean, default=True)
|
|
|
|
class Alert(Base):
|
|
__tablename__ = "alerts"
|
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
|
user_id = Column(String)
|
|
monitoring_topic_id = Column(Integer)
|
|
title = Column(String)
|
|
description = Column(Text)
|
|
source = Column(String)
|
|
created_at = Column(DateTime, default=datetime.utcnow)
|
|
|
|
class AuditTrail(Base):
|
|
__tablename__ = "audit_trail"
|
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
|
user_email = Column(String)
|
|
action = Column(String)
|
|
details = Column(Text)
|
|
timestamp = Column(DateTime, default=datetime.utcnow)
|
|
|
|
# ***
|
|
|
|
# All comments are in English.
|
|
|
|
from sqlalchemy import Column, String, Text, DateTime, ForeignKey
|
|
from sqlalchemy.orm import declarative_base, relationship
|
|
from datetime import datetime
|
|
|
|
Base = declarative_base()
|
|
|
|
class Conversation(Base):
|
|
__tablename__ = "conversations"
|
|
id = Column(String, primary_key=True)
|
|
title = Column(String)
|
|
messages = relationship("Message", back_populates="conversation")
|
|
|
|
class Message(Base):
|
|
__tablename__ = "messages"
|
|
id = Column(String, primary_key=True)
|
|
conversation_id = Column(String, ForeignKey("conversations.id"))
|
|
role = Column(String) # "user" or "assistant"
|
|
content = Column(Text)
|
|
created_at = Column(DateTime, default=datetime.utcnow)
|
|
conversation = relationship("Conversation", back_populates="messages")
|
|
|
|
class Attachment(Base):
|
|
__tablename__ = "attachments"
|
|
id = Column(String, primary_key=True)
|
|
conversation_id = Column(String, ForeignKey("conversations.id"))
|
|
filename = Column(String)
|
|
mime_type = Column(String)
|
|
data = Column(Text) # base64 or small text payload
|