From 74b87a3b27d642b205234f254b391e4eeaf2b6e5 Mon Sep 17 00:00:00 2001 From: Xavier Date: Wed, 7 Oct 2026 07:42:24 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20cr=C3=A9ation=20des=20mod=C3=A8les=20de?= =?UTF-8?q?=20base=20de=20donn=C3=A9es=20Project=20et=20Message?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/models.py | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) 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