diff --git a/backend/models.py b/backend/models.py index 4d2a925..a625b73 100644 --- a/backend/models.py +++ b/backend/models.py @@ -1,4 +1,5 @@ -from sqlalchemy import Column, Integer, String, Boolean, DateTime +from sqlalchemy import Column, Integer, String, Boolean, DateTime, ForeignKey, Text +from sqlalchemy.orm import relationship from datetime import datetime, timezone from .database import Base @@ -9,8 +10,35 @@ class User(Base): 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=True) # Secret pour Keepassium/Authenticator + totp_secret = Column(String, nullable=False) is_admin = Column(Boolean, default=False) - is_active = Column(Boolean, default=True) + + # 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)) - last_activity = Column(DateTime, nullable=True) # Servira pour la déconnexion après 60 min \ No newline at end of file + 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") \ No newline at end of file