init
This commit is contained in:
33
app/models.py
Normal file
33
app/models.py
Normal file
@@ -0,0 +1,33 @@
|
||||
from sqlalchemy import Column, Integer, String, ForeignKey, Text, DateTime, func
|
||||
from sqlalchemy.orm import relationship
|
||||
from app.database import Base
|
||||
|
||||
class User(Base):
|
||||
__tablename__ = "users"
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
telegram_id = Column(String, unique=True, index=True)
|
||||
username = Column(String, nullable=True)
|
||||
|
||||
chats = relationship("Chat", back_populates="owner")
|
||||
|
||||
|
||||
class Chat(Base):
|
||||
__tablename__ = "chats"
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
title = Column(String, default="Новый чат")
|
||||
|
||||
owner_id = Column(Integer, ForeignKey("users.id"))
|
||||
owner = relationship("User", back_populates="chats")
|
||||
|
||||
messages = relationship("Message", back_populates="chat", cascade="all, delete-orphan")
|
||||
|
||||
|
||||
class Message(Base):
|
||||
__tablename__ = "messages"
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
role = Column(String) # 'user' | 'assistant' | 'system'
|
||||
content = Column(Text)
|
||||
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
||||
|
||||
chat_id = Column(Integer, ForeignKey("chats.id"))
|
||||
chat = relationship("Chat", back_populates="messages")
|
||||
Reference in New Issue
Block a user