
shouldn't actually cause any issues currently since SQLAlchemy is (to my annoyance) import *ed everywhere but.
27 lines
875 B
Python
27 lines
875 B
Python
from sqlalchemy import *
|
|
from sqlalchemy.orm import relationship
|
|
from files.classes.base import Base
|
|
import time
|
|
|
|
class Notification(Base):
|
|
|
|
__tablename__ = "notifications"
|
|
|
|
user_id = Column(Integer, ForeignKey("users.id"), primary_key=True)
|
|
comment_id = Column(Integer, ForeignKey("comments.id"), primary_key=True)
|
|
read = Column(Boolean, default=False, nullable=False)
|
|
created_utc = Column(Integer, nullable=False)
|
|
|
|
Index('notification_read_idx', read)
|
|
Index('notifications_comment_idx', comment_id)
|
|
Index('notifs_user_read_idx', user_id, read)
|
|
|
|
comment = relationship("Comment", viewonly=True)
|
|
user = relationship("User", viewonly=True)
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time())
|
|
super().__init__(*args, **kwargs)
|
|
|
|
def __repr__(self):
|
|
return f"<{self.__class__.__name__}(id={self.id})>"
|