core/orm/author.py

47 lines
1.8 KiB
Python
Raw Normal View History

2023-11-03 10:10:22 +00:00
import time
2023-11-22 16:38:39 +00:00
2023-10-23 14:47:11 +00:00
from sqlalchemy import JSON as JSONType
2023-11-03 10:10:22 +00:00
from sqlalchemy import Boolean, Column, ForeignKey, Integer, String
2023-10-23 14:47:11 +00:00
from sqlalchemy.orm import relationship
2023-11-22 16:38:39 +00:00
2023-10-25 16:55:30 +00:00
from services.db import Base
2023-10-23 14:47:11 +00:00
class AuthorRating(Base):
__tablename__ = "author_rating"
id = None # type: ignore
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:39 +00:00
plus = Column(Boolean)
2023-10-23 14:47:11 +00:00
class AuthorFollower(Base):
__tablename__ = "author_follower"
id = None # type: ignore
follower = Column(ForeignKey("author.id"), primary_key=True, index=True)
author = Column(ForeignKey("author.id"), primary_key=True, index=True)
2023-11-03 10:10:22 +00:00
created_at = Column(Integer, nullable=False, default=lambda: int(time.time()))
2023-10-23 14:47:11 +00:00
auto = Column(Boolean, nullable=False, default=False)
class Author(Base):
__tablename__ = "author"
2023-11-03 10:10:22 +00:00
user = Column(String, unique=True) # unbounded link with authorizer's User type
2023-10-23 14:47:11 +00:00
name = Column(String, nullable=True, comment="Display name")
slug = Column(String, unique=True, comment="Author's slug")
2023-11-03 10:10:22 +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")
2023-10-23 14:47:11 +00:00
links = Column(JSONType, nullable=True, comment="Links")
2023-11-03 10:10:22 +00:00
2023-10-23 14:47:11 +00:00
ratings = relationship(AuthorRating, foreign_keys=AuthorRating.author)
2023-11-03 10:10:22 +00:00
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()))
deleted_at = Column(Integer, nullable=True, comment="Deleted at")