
- Set up project structure with FastAPI and SQLite - Implement user authentication using JWT - Create database models for users, conversations, and messages - Implement API endpoints for user management and chat functionality - Set up WebSocket for real-time messaging - Add database migrations with Alembic - Create health check endpoint - Update README with comprehensive documentation generated with BackendIM... (backend.im)
25 lines
1.1 KiB
Python
25 lines
1.1 KiB
Python
from sqlalchemy import Column, String, DateTime, func, ForeignKey, Table
|
|
from sqlalchemy.orm import relationship
|
|
|
|
from app.db.session import Base
|
|
|
|
# Association table for many-to-many relationship between users and conversations
|
|
conversation_participants = Table(
|
|
"conversation_participants",
|
|
Base.metadata,
|
|
Column("conversation_id", String, ForeignKey("conversations.id"), primary_key=True),
|
|
Column("user_id", String, ForeignKey("users.id"), primary_key=True)
|
|
)
|
|
|
|
class Conversation(Base):
|
|
__tablename__ = "conversations"
|
|
|
|
id = Column(String, primary_key=True, index=True)
|
|
name = Column(String, nullable=True) # Optional name for group chats
|
|
is_group = Column(String, default=False)
|
|
created_at = Column(DateTime, server_default=func.now())
|
|
updated_at = Column(DateTime, server_default=func.now(), onupdate=func.now())
|
|
|
|
# Relationships
|
|
participants = relationship("User", secondary=conversation_participants, back_populates="conversations")
|
|
messages = relationship("Message", back_populates="conversation", cascade="all, delete-orphan") |