
- 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)
21 lines
986 B
Python
21 lines
986 B
Python
from sqlalchemy import Column, String, DateTime, func, ForeignKey, Boolean
|
|
from sqlalchemy.orm import relationship
|
|
|
|
from app.db.session import Base
|
|
|
|
class Message(Base):
|
|
__tablename__ = "messages"
|
|
|
|
id = Column(String, primary_key=True, index=True)
|
|
content = Column(String)
|
|
sender_id = Column(String, ForeignKey("users.id"))
|
|
recipient_id = Column(String, ForeignKey("users.id"), nullable=True) # For direct messages
|
|
conversation_id = Column(String, ForeignKey("conversations.id"))
|
|
is_read = Column(Boolean, default=False)
|
|
created_at = Column(DateTime, server_default=func.now())
|
|
updated_at = Column(DateTime, server_default=func.now(), onupdate=func.now())
|
|
|
|
# Relationships
|
|
sender = relationship("User", foreign_keys=[sender_id], back_populates="messages_sent")
|
|
recipient = relationship("User", foreign_keys=[recipient_id], back_populates="messages_received")
|
|
conversation = relationship("Conversation", back_populates="messages") |