Skip to content

Instantly share code, notes, and snippets.

@danielshtel
Created August 4, 2023 10:25
Show Gist options
  • Save danielshtel/c729cd0fb7f36a42c752deee0dabef07 to your computer and use it in GitHub Desktop.
Save danielshtel/c729cd0fb7f36a42c752deee0dabef07 to your computer and use it in GitHub Desktop.
from sqlalchemy import UUID, Column, String
from app.services.db import ModelBase
class Chat(ModelBase):
__tablename__ = 'chat'
id = Column(UUID, primary_key=True)
name = Column(String, nullable=False)
class ChatMember(ModelBase):
__tablename__ = 'chat_member'
id = Column(Integer, primary_key=True)
chat_id = Column(UUID, ForeignKey('chat.id', ondelete='CASCADE'), nullable=False)
user_id = Column(UUID, ForeignKey('user.id', ondelete='SET NULL'))
class ChatMessage(ModelBase):
__tablename__ = "chat_message"
id = Column(Integer, primary_key=True)
chat_id = Column(UUID, ForeignKey("chat.id"), nullable=False)
user_id = Column(UUID, ForeignKey("user.id"), nullable=False)
message = Column(String, nullable=False)
timestamp = Column(DateTime(timezone=True), server_default=func.now())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment