CoolFace
Apppublic

creativesar/taskflow

sourceHugging Faceupdated 8mo agoView on Hugging Face
0likes
models.py67 linesDownload Raw Back to root
1"""2SQLModel database models for Todo application3"""4 5from sqlmodel import SQLModel, Field6from datetime import datetime7from typing import Optional8 9 10class User(SQLModel, table=True):11    """12    SQLModel representation of users table.13    Used for authentication and task ownership.14    """15    __tablename__ = "users"16 17    id: Optional[str] = Field(default=None, primary_key=True, max_length=36)18    email: str = Field(unique=True, max_length=255)19    name: Optional[str] = Field(default=None, max_length=100)20    hashed_password: str = Field(max_length=255)21    created_at: datetime = Field(default_factory=datetime.utcnow)22 23 24class Task(SQLModel, table=True):25    """26    SQLModel representation of tasks table.27    Also serves as Pydantic model for API validation.28    """29    __tablename__ = "tasks"30 31    id: Optional[int] = Field(default=None, primary_key=True)32    user_id: str = Field(foreign_key="users.id", index=True)33    title: str = Field(max_length=200, min_length=1)34    description: str = Field(max_length=1000, min_length=1)35    completed: bool = Field(default=False)36    created_at: datetime = Field(default_factory=datetime.utcnow)37    updated_at: datetime = Field(default_factory=datetime.utcnow)38 39 40class Conversation(SQLModel, table=True):41    """42    SQLModel representation of conversations table.43    Stores chat conversation metadata for Phase III AI Chatbot.44    """45    __tablename__ = "conversations"46 47    id: Optional[int] = Field(default=None, primary_key=True)48    user_id: str = Field(foreign_key="users.id", index=True)49    created_at: datetime = Field(default_factory=datetime.utcnow)50    updated_at: datetime = Field(default_factory=datetime.utcnow)51 52 53class Message(SQLModel, table=True):54    """55    SQLModel representation of messages table.56    Stores individual chat messages within conversations.57    """58    __tablename__ = "messages"59 60    id: Optional[int] = Field(default=None, primary_key=True)61    user_id: str = Field(foreign_key="users.id", index=True)62    conversation_id: int = Field(foreign_key="conversations.id", index=True)63    role: str = Field(max_length=20)  # "user" or "assistant"64    content: str65    tool_calls: Optional[str] = Field(default=None)  # JSON string of tool calls66    created_at: datetime = Field(default_factory=datetime.utcnow)67