notifier/orm/author.py

46 lines
1.7 KiB
Python
Raw Permalink Normal View History

2023-11-23 22:58:55 +00:00
import time
2024-01-26 00:40:49 +00:00
from sqlalchemy import JSON, Boolean, Column, ForeignKey, Integer, String
2023-11-23 22:58:55 +00:00
from sqlalchemy.orm import relationship
from services.db import Base
class AuthorRating(Base):
2024-01-26 00:40:49 +00:00
__tablename__ = 'author_rating'
2023-11-23 22:58:55 +00:00
id = None # type: ignore
2024-01-26 00:40:49 +00:00
rater = Column(ForeignKey('author.id'), primary_key=True, index=True)
author = Column(ForeignKey('author.id'), primary_key=True, index=True)
2023-11-29 20:22:47 +00:00
plus = Column(Boolean)
2023-11-23 22:58:55 +00:00
class AuthorFollower(Base):
2024-01-26 00:40:49 +00:00
__tablename__ = 'author_follower'
2023-11-23 22:58:55 +00:00
id = None # type: ignore
2024-01-26 00:40:49 +00:00
follower = Column(ForeignKey('author.id'), primary_key=True, index=True)
author = Column(ForeignKey('author.id'), primary_key=True, index=True)
2023-11-23 22:58:55 +00:00
created_at = Column(Integer, nullable=False, default=lambda: int(time.time()))
auto = Column(Boolean, nullable=False, default=False)
class Author(Base):
2024-01-26 00:40:49 +00:00
__tablename__ = 'author'
2023-11-23 22:58:55 +00:00
user = Column(String, unique=True) # unbounded link with authorizer's User type
2024-01-26 00:40:49 +00:00
name = Column(String, nullable=True, comment='Display name')
2023-11-23 22:58:55 +00:00
slug = Column(String, unique=True, comment="Author's slug")
2024-01-26 00:40:49 +00:00
bio = Column(String, nullable=True, comment='Bio') # status description
about = Column(String, nullable=True, comment='About') # long and formatted
pic = Column(String, nullable=True, comment='Picture')
links = Column(JSON, nullable=True, comment='Links')
2023-11-23 22:58:55 +00:00
ratings = relationship(AuthorRating, foreign_keys=AuthorRating.author)
created_at = Column(Integer, nullable=False, default=lambda: int(time.time()))
last_seen = Column(Integer, nullable=False, default=lambda: int(time.time()))
updated_at = Column(Integer, nullable=False, default=lambda: int(time.time()))
2024-01-26 00:40:49 +00:00
deleted_at = Column(Integer, nullable=True, comment='Deleted at')