57 lines
2.2 KiB
Python
57 lines
2.2 KiB
Python
from sqlalchemy import Column, Integer, String, Boolean, DateTime, ForeignKey, Text
|
|
from sqlalchemy.orm import relationship
|
|
from datetime import datetime, timezone
|
|
from .database import Base
|
|
|
|
class User(Base):
|
|
__tablename__ = "users"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
email = Column(String, unique=True, index=True, nullable=False)
|
|
username = Column(String, unique=True, index=True, nullable=False)
|
|
hashed_password = Column(String, nullable=False)
|
|
totp_secret = Column(String, nullable=False)
|
|
is_admin = Column(Boolean, default=False)
|
|
|
|
# Relation : Un utilisateur peut avoir plusieurs projets
|
|
projects = relationship("Project", back_populates="owner", cascade="all, delete-orphan")
|
|
|
|
|
|
class Project(Base):
|
|
__tablename__ = "projects"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
title = Column(String, nullable=False)
|
|
created_at = Column(DateTime, default=lambda: datetime.now(timezone.utc))
|
|
is_pinned = Column(Boolean, default=False)
|
|
user_id = Column(Integer, ForeignKey("users.id"), nullable=False)
|
|
|
|
# Relations
|
|
owner = relationship("User", back_populates="projects")
|
|
messages = relationship("Message", back_populates="project", cascade="all, delete-orphan")
|
|
|
|
|
|
class Message(Base):
|
|
__tablename__ = "messages"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
role = Column(String, nullable=False) # Ex: 'user', 'assistant', 'worker_1', 'system'
|
|
content = Column(Text, nullable=False)
|
|
created_at = Column(DateTime, default=lambda: datetime.now(timezone.utc))
|
|
project_id = Column(Integer, ForeignKey("projects.id"), nullable=False)
|
|
|
|
# Relation
|
|
project = relationship("Project", back_populates="messages")
|
|
|
|
class SystemSettings(Base):
|
|
__tablename__ = "system_settings"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
# Serveur Mail (Obligatoire)
|
|
smtp_host = Column(String, nullable=False)
|
|
smtp_port = Column(Integer, nullable=False)
|
|
smtp_user = Column(String, nullable=False)
|
|
smtp_password = Column(String, nullable=False)
|
|
# Clés API (Optionnelles)
|
|
gemini_api_key = Column(String, nullable=True)
|
|
openrouter_api_key = Column(String, nullable=True) |