|
from sqlalchemy import Column, ForeignKey, Integer, String, DateTime |
|
from sqlalchemy.orm import relationship |
|
|
|
from app.database import Base |
|
|
|
class User(Base): |
|
__tablename__ = "users" |
|
|
|
id = Column(Integer, primary_key=True, index=True) |
|
username = Column(String, unique=True, index=True) |
|
messages = relationship("Message", back_populates="user") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Message(Base): |
|
__tablename__ = "messages" |
|
id = Column(Integer, primary_key=True, index=True) |
|
message = Column(String) |
|
type = Column(String) |
|
timestamp = Column(DateTime) |
|
user_id = Column(Integer, ForeignKey("users.id")) |
|
user = relationship("User", back_populates="messages") |