granian+precommit

This commit is contained in:
2024-01-25 22:41:27 +03:00
parent ad3fd32a6e
commit 4a5f1d634a
35 changed files with 835 additions and 764 deletions

View File

@@ -1,46 +1,45 @@
import time
from sqlalchemy import JSON as JSONType
from sqlalchemy import Boolean, Column, ForeignKey, Integer, String
from sqlalchemy import JSON, Boolean, Column, ForeignKey, Integer, String
from sqlalchemy.orm import relationship
from services.db import Base
class AuthorRating(Base):
__tablename__ = "author_rating"
__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)
rater = Column(ForeignKey('author.id'), primary_key=True, index=True)
author = Column(ForeignKey('author.id'), primary_key=True, index=True)
plus = Column(Boolean)
class AuthorFollower(Base):
__tablename__ = "author_follower"
__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)
follower = Column(ForeignKey('author.id'), primary_key=True, index=True)
author = Column(ForeignKey('author.id'), primary_key=True, index=True)
created_at = Column(Integer, nullable=False, default=lambda: int(time.time()))
auto = Column(Boolean, nullable=False, default=False)
class Author(Base):
__tablename__ = "author"
__tablename__ = 'author'
user = Column(String, unique=True) # unbounded link with authorizer's User type
name = Column(String, nullable=True, comment="Display name")
name = Column(String, nullable=True, comment='Display name')
slug = Column(String, unique=True, comment="Author's slug")
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(JSONType, nullable=True, comment="Links")
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')
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()))
deleted_at = Column(Integer, nullable=True, comment="Deleted at")
deleted_at = Column(Integer, nullable=True, comment='Deleted at')

View File

@@ -6,20 +6,20 @@ from services.db import Base
class ShoutCollection(Base):
__tablename__ = "shout_collection"
__tablename__ = 'shout_collection'
id = None # type: ignore
shout = Column(ForeignKey("shout.id"), primary_key=True)
collection = Column(ForeignKey("collection.id"), primary_key=True)
shout = Column(ForeignKey('shout.id'), primary_key=True)
collection = Column(ForeignKey('collection.id'), primary_key=True)
class Collection(Base):
__tablename__ = "collection"
__tablename__ = 'collection'
slug = Column(String, unique=True)
title = Column(String, nullable=False, comment="Title")
body = Column(String, nullable=True, comment="Body")
pic = Column(String, nullable=True, comment="Picture")
title = Column(String, nullable=False, comment='Title')
body = Column(String, nullable=True, comment='Body')
pic = Column(String, nullable=True, comment='Picture')
created_at = Column(Integer, default=lambda: int(time.time()))
created_by = Column(ForeignKey("author.id"), comment="Created By")
publishedAt = Column(Integer, default=lambda: int(time.time()))
created_by = Column(ForeignKey('author.id'), comment='Created By')
published_at = Column(Integer, default=lambda: int(time.time()))

View File

@@ -8,34 +8,34 @@ from services.db import Base, local_session
class CommunityAuthor(Base):
__tablename__ = "community_author"
__tablename__ = 'community_author'
id = None # type: ignore
author = Column(ForeignKey("author.id"), primary_key=True)
community = Column(ForeignKey("community.id"), primary_key=True)
author = Column(ForeignKey('author.id'), primary_key=True)
community = Column(ForeignKey('community.id'), primary_key=True)
joined_at = Column(Integer, nullable=False, default=lambda: int(time.time()))
role = Column(String, nullable=False)
class Community(Base):
__tablename__ = "community"
__tablename__ = 'community'
name = Column(String, nullable=False)
slug = Column(String, nullable=False, unique=True)
desc = Column(String, nullable=False, default="")
pic = Column(String, nullable=False, default="")
desc = Column(String, nullable=False, default='')
pic = Column(String, nullable=False, default='')
created_at = Column(Integer, nullable=False, default=lambda: int(time.time()))
authors = relationship(lambda: Author, secondary=CommunityAuthor.__tablename__)
@staticmethod
def init_table():
with local_session("orm.community") as session:
d = session.query(Community).filter(Community.slug == "discours").first()
with local_session('orm.community') as session:
d = session.query(Community).filter(Community.slug == 'discours').first()
if not d:
d = Community(name="Дискурс", slug="discours")
d = Community(name='Дискурс', slug='discours')
session.add(d)
session.commit()
print("[orm.community] created community %s" % d.slug)
print('[orm.community] created community %s' % d.slug)
Community.default_community = d
print("[orm.community] default community is %s" % d.slug)
print('[orm.community] default community is %s' % d.slug)

View File

@@ -9,17 +9,17 @@ from services.db import Base
class InviteStatus(Enumeration):
PENDING = "PENDING"
ACCEPTED = "ACCEPTED"
REJECTED = "REJECTED"
PENDING = 'PENDING'
ACCEPTED = 'ACCEPTED'
REJECTED = 'REJECTED'
class Invite(Base):
__tablename__ = "invite"
__tablename__ = 'invite'
inviter_id = Column(ForeignKey("author.id"), nullable=False, index=True)
author_id = Column(ForeignKey("author.id"), nullable=False, index=True)
shout_id = Column(ForeignKey("shout.id"), nullable=False, index=True)
inviter_id = Column(ForeignKey('author.id'), nullable=False, index=True)
author_id = Column(ForeignKey('author.id'), nullable=False, index=True)
shout_id = Column(ForeignKey('shout.id'), nullable=False, index=True)
status = Column(String, default=InviteStatus.PENDING.value)
inviter = relationship(Author, foreign_keys=[inviter_id])

View File

@@ -10,34 +10,34 @@ class ReactionKind(Enumeration):
# TYPE = <reaction index> # rating diff
# editor mode
AGREE = "AGREE" # +1
DISAGREE = "DISAGREE" # -1
ASK = "ASK" # +0
PROPOSE = "PROPOSE" # +0
PROOF = "PROOF" # +1
DISPROOF = "DISPROOF" # -1
ACCEPT = "ACCEPT" # +1
REJECT = "REJECT" # -1
AGREE = 'AGREE' # +1
DISAGREE = 'DISAGREE' # -1
ASK = 'ASK' # +0
PROPOSE = 'PROPOSE' # +0
PROOF = 'PROOF' # +1
DISPROOF = 'DISPROOF' # -1
ACCEPT = 'ACCEPT' # +1
REJECT = 'REJECT' # -1
# public feed
QUOTE = "QUOTE" # +0 TODO: use to bookmark in collection
COMMENT = "COMMENT" # +0
LIKE = "LIKE" # +1
DISLIKE = "DISLIKE" # -1
QUOTE = 'QUOTE' # +0 TODO: use to bookmark in collection
COMMENT = 'COMMENT' # +0
LIKE = 'LIKE' # +1
DISLIKE = 'DISLIKE' # -1
class Reaction(Base):
__tablename__ = "reaction"
__tablename__ = 'reaction'
body = Column(String, default="", comment="Reaction Body")
body = Column(String, default='', comment='Reaction Body')
created_at = Column(Integer, nullable=False, default=lambda: int(time.time()))
updated_at = Column(Integer, nullable=True, comment="Updated at")
deleted_at = Column(Integer, nullable=True, comment="Deleted at")
deleted_by = Column(ForeignKey("author.id"), nullable=True, index=True)
reply_to = Column(ForeignKey("reaction.id"), nullable=True)
quote = Column(String, nullable=True, comment="Original quoted text")
shout = Column(ForeignKey("shout.id"), nullable=False, index=True)
created_by = Column(ForeignKey("author.id"), nullable=False, index=True)
updated_at = Column(Integer, nullable=True, comment='Updated at')
deleted_at = Column(Integer, nullable=True, comment='Deleted at')
deleted_by = Column(ForeignKey('author.id'), nullable=True, index=True)
reply_to = Column(ForeignKey('reaction.id'), nullable=True)
quote = Column(String, nullable=True, comment='Original quoted text')
shout = Column(ForeignKey('shout.id'), nullable=False, index=True)
created_by = Column(ForeignKey('author.id'), nullable=False, index=True)
kind = Column(String, nullable=False, index=True)
oid = Column(String)

View File

@@ -12,80 +12,80 @@ from services.db import Base
class ShoutTopic(Base):
__tablename__ = "shout_topic"
__tablename__ = 'shout_topic'
id = None # type: ignore
shout = Column(ForeignKey("shout.id"), primary_key=True, index=True)
topic = Column(ForeignKey("topic.id"), primary_key=True, index=True)
shout = Column(ForeignKey('shout.id'), primary_key=True, index=True)
topic = Column(ForeignKey('topic.id'), primary_key=True, index=True)
main = Column(Boolean, nullable=True)
class ShoutReactionsFollower(Base):
__tablename__ = "shout_reactions_followers"
__tablename__ = 'shout_reactions_followers'
id = None # type: ignore
follower = Column(ForeignKey("author.id"), primary_key=True, index=True)
shout = Column(ForeignKey("shout.id"), primary_key=True, index=True)
follower = Column(ForeignKey('author.id'), primary_key=True, index=True)
shout = Column(ForeignKey('shout.id'), primary_key=True, index=True)
auto = Column(Boolean, nullable=False, default=False)
created_at = Column(Integer, nullable=False, default=lambda: int(time.time()))
deleted_at = Column(Integer, nullable=True)
class ShoutAuthor(Base):
__tablename__ = "shout_author"
__tablename__ = 'shout_author'
id = None # type: ignore
shout = Column(ForeignKey("shout.id"), primary_key=True, index=True)
author = Column(ForeignKey("author.id"), primary_key=True, index=True)
caption = Column(String, nullable=True, default="")
shout = Column(ForeignKey('shout.id'), primary_key=True, index=True)
author = Column(ForeignKey('author.id'), primary_key=True, index=True)
caption = Column(String, nullable=True, default='')
class ShoutCommunity(Base):
__tablename__ = "shout_community"
__tablename__ = 'shout_community'
id = None # type: ignore
shout = Column(ForeignKey("shout.id"), primary_key=True, index=True)
community = Column(ForeignKey("community.id"), primary_key=True, index=True)
shout = Column(ForeignKey('shout.id'), primary_key=True, index=True)
community = Column(ForeignKey('community.id'), primary_key=True, index=True)
class ShoutVisibility(Enumeration):
AUTHORS = "AUTHORS"
COMMUNITY = "COMMUNITY"
PUBLIC = "PUBLIC"
AUTHORS = 'AUTHORS'
COMMUNITY = 'COMMUNITY'
PUBLIC = 'PUBLIC'
class Shout(Base):
__tablename__ = "shout"
__tablename__ = 'shout'
created_at = Column(Integer, nullable=False, default=lambda: int(time.time()))
updated_at = Column(Integer, nullable=True)
published_at = Column(Integer, nullable=True)
deleted_at = Column(Integer, nullable=True)
created_by = Column(ForeignKey("author.id"), nullable=False)
updated_by = Column(ForeignKey("author.id"), nullable=True)
deleted_by = Column(ForeignKey("author.id"), nullable=True)
created_by = Column(ForeignKey('author.id'), nullable=False)
updated_by = Column(ForeignKey('author.id'), nullable=True)
deleted_by = Column(ForeignKey('author.id'), nullable=True)
body = Column(String, nullable=False, comment="Body")
body = Column(String, nullable=False, comment='Body')
slug = Column(String, unique=True)
cover = Column(String, nullable=True, comment="Cover image url")
cover_caption = Column(String, nullable=True, comment="Cover image alt caption")
cover = Column(String, nullable=True, comment='Cover image url')
cover_caption = Column(String, nullable=True, comment='Cover image alt caption')
lead = Column(String, nullable=True)
description = Column(String, nullable=True)
title = Column(String, nullable=False)
subtitle = Column(String, nullable=True)
layout = Column(String, nullable=False, default="article")
layout = Column(String, nullable=False, default='article')
media = Column(JSON, nullable=True)
authors = relationship(lambda: Author, secondary="shout_author")
topics = relationship(lambda: Topic, secondary="shout_topic")
communities = relationship(lambda: Community, secondary="shout_community")
authors = relationship(lambda: Author, secondary='shout_author')
topics = relationship(lambda: Topic, secondary='shout_topic')
communities = relationship(lambda: Community, secondary='shout_community')
reactions = relationship(lambda: Reaction)
visibility = Column(String, default=ShoutVisibility.AUTHORS.value)
lang = Column(String, nullable=False, default="ru", comment="Language")
version_of = Column(ForeignKey("shout.id"), nullable=True)
lang = Column(String, nullable=False, default='ru', comment='Language')
version_of = Column(ForeignKey('shout.id'), nullable=True)
oid = Column(String, nullable=True)
seo = Column(String, nullable=True) # JSON

View File

@@ -6,21 +6,21 @@ from services.db import Base
class TopicFollower(Base):
__tablename__ = "topic_followers"
__tablename__ = 'topic_followers'
id = None # type: ignore
follower = Column(ForeignKey("author.id"), primary_key=True, index=True)
topic = Column(ForeignKey("topic.id"), primary_key=True, index=True)
follower = Column(ForeignKey('author.id'), primary_key=True, index=True)
topic = Column(ForeignKey('topic.id'), primary_key=True, index=True)
created_at = Column(Integer, nullable=False, default=lambda: int(time.time()))
auto = Column(Boolean, nullable=False, default=False)
class Topic(Base):
__tablename__ = "topic"
__tablename__ = 'topic'
slug = Column(String, unique=True)
title = Column(String, nullable=False, comment="Title")
body = Column(String, nullable=True, comment="Body")
pic = Column(String, nullable=True, comment="Picture")
community = Column(ForeignKey("community.id"), default=1)
oid = Column(String, nullable=True, comment="Old ID")
title = Column(String, nullable=False, comment='Title')
body = Column(String, nullable=True, comment='Body')
pic = Column(String, nullable=True, comment='Picture')
community = Column(ForeignKey('community.id'), default=1)
oid = Column(String, nullable=True, comment='Old ID')

View File

@@ -6,7 +6,7 @@ from services.db import Base
class User(Base):
__tablename__ = "authorizer_users"
__tablename__ = 'authorizer_users'
id = Column(String, primary_key=True, unique=True, nullable=False, default=None)
key = Column(String)
@@ -24,7 +24,7 @@ class User(Base):
# preferred_username = Column(String, nullable=False)
picture = Column(String)
revoked_timestamp = Column(Integer)
roles = Column(String, default="author, reader")
signup_methods = Column(String, default="magic_link_login")
roles = Column(String, default='author, reader')
signup_methods = Column(String, default='magic_link_login')
created_at = Column(Integer, default=lambda: int(time.time()))
updated_at = Column(Integer, default=lambda: int(time.time()))