notifier/orm/notification.py

43 lines
1.1 KiB
Python
Raw Normal View History

2023-12-17 22:20:13 +00:00
from enum import Enum as Enumeration
2023-12-22 09:09:03 +00:00
from sqlalchemy import JSON as JSONType, func, cast
2023-12-17 22:20:13 +00:00
from sqlalchemy import Column, Enum, ForeignKey, Integer
2023-11-26 18:21:14 +00:00
from sqlalchemy.orm import relationship
2024-01-23 07:56:31 +00:00
from sqlalchemy.orm.session import engine
2023-12-17 11:42:04 +00:00
2023-11-26 18:21:14 +00:00
from orm.author import Author
2023-11-23 22:58:55 +00:00
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
2023-11-26 18:21:14 +00:00
class NotificationSeen(Base):
__tablename__ = "notification_seen"
viewer = Column(ForeignKey("author.id"))
notification = Column(ForeignKey("notification.id"))
2023-11-23 22:58:55 +00:00
class Notification(Base):
__tablename__ = "notification"
2023-12-22 09:09:03 +00:00
created_at = Column(Integer, server_default=cast(func.current_timestamp(), Integer))
2023-11-23 22:58:55 +00:00
entity = Column(Enum(NotificationEntity), nullable=False)
action = Column(Enum(NotificationAction), nullable=False)
2023-11-26 18:21:14 +00:00
payload = Column(JSONType, nullable=True)
seen = relationship(lambda: Author, secondary="notification_seen")