notifier/orm/notification.py
Untone e22d5468ab
All checks were successful
deploy / deploy (push) Successful in 1m11s
0.1.0-fixes
2023-12-22 12:09:03 +03:00

42 lines
1.0 KiB
Python

from enum import Enum as Enumeration
from sqlalchemy import JSON as JSONType, func, cast
from sqlalchemy import Column, Enum, ForeignKey, Integer
from sqlalchemy.orm import relationship
from orm.author import Author
from services.db import Base
class NotificationEntity(Enumeration):
REACTION = 1
SHOUT = 2
FOLLOWER = 3
class NotificationAction(Enumeration):
CREATE = 1
UPDATE = 2
DELETE = 3
SEEN = 4
FOLLOW = 5
UNFOLLOW = 6
class NotificationSeen(Base):
__tablename__ = "notification_seen"
viewer = Column(ForeignKey("author.id"))
notification = Column(ForeignKey("notification.id"))
class Notification(Base):
__tablename__ = "notification"
created_at = Column(Integer, server_default=cast(func.current_timestamp(), Integer))
entity = Column(Enum(NotificationEntity), nullable=False)
action = Column(Enum(NotificationAction), nullable=False)
payload = Column(JSONType, nullable=True)
seen = relationship(lambda: Author, secondary="notification_seen")