sdfsfd
This commit is contained in:
parent
7887014474
commit
11c1bbd203
11 changed files with 55 additions and 116 deletions
|
@ -64,17 +64,10 @@ class AwardRelationship(Base):
|
|||
comment_id = Column(Integer, ForeignKey("comments.id"), default=None)
|
||||
kind = Column(String(20))
|
||||
|
||||
user = relationship("User", primaryjoin="AwardRelationship.user_id==User.id", lazy="joined")
|
||||
post = relationship(
|
||||
"Submission",
|
||||
primaryjoin="AwardRelationship.submission_id==Submission.id",
|
||||
lazy="joined"
|
||||
)
|
||||
comment = relationship(
|
||||
"Comment",
|
||||
primaryjoin="AwardRelationship.comment_id==Comment.id",
|
||||
lazy="joined"
|
||||
)
|
||||
user = relationship("User", primaryjoin="AwardRelationship.user_id==User.id", lazy="joined", viewonly=True)
|
||||
|
||||
post = relationship("Submission", primaryjoin="AwardRelationship.submission_id==Submission.id", lazy="joined", viewonly=True)
|
||||
comment = relationship("Comment", primaryjoin="AwardRelationship.comment_id==Comment.id", lazy="joined", viewonly=True)
|
||||
|
||||
@property
|
||||
def given(self):
|
||||
|
|
|
@ -46,7 +46,7 @@ class Badge(Base):
|
|||
badge_id = Column(Integer, ForeignKey("badge_defs.id"))
|
||||
description = Column(String(64))
|
||||
url = Column(String(256))
|
||||
badge = relationship("BadgeDef", lazy="joined", innerjoin=True)
|
||||
badge = relationship("BadgeDef", lazy="joined", innerjoin=True, viewonly=True)
|
||||
|
||||
def __repr__(self):
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ class OauthApp(Base, Stndrd):
|
|||
redirect_uri = Column(String(4096))
|
||||
description = Column(String(256))
|
||||
author_id = Column(Integer, ForeignKey("users.id"))
|
||||
author = relationship("User")
|
||||
author = relationship("User", viewonly=True)
|
||||
|
||||
def __repr__(self): return f"<OauthApp(id={self.id})>"
|
||||
|
||||
|
@ -53,5 +53,5 @@ class ClientAuth(Base, Stndrd):
|
|||
oauth_client = Column(Integer, ForeignKey("oauth_apps.id"))
|
||||
access_token = Column(String(128))
|
||||
user_id = Column(Integer, ForeignKey("users.id"))
|
||||
user = relationship("User", lazy="joined")
|
||||
application = relationship("OauthApp", lazy="joined")
|
||||
user = relationship("User", lazy="joined", viewonly=True)
|
||||
application = relationship("OauthApp", lazy="joined", viewonly=True)
|
|
@ -28,12 +28,7 @@ class Comment(Base, Age_times, Scores, Stndrd, Fuzzing):
|
|||
__tablename__ = "comments"
|
||||
|
||||
id = Column(Integer, primary_key=True)
|
||||
comment_aux = relationship(
|
||||
"CommentAux",
|
||||
lazy="joined",
|
||||
uselist=False,
|
||||
innerjoin=True,
|
||||
primaryjoin="Comment.id==CommentAux.id")
|
||||
comment_aux = relationship("CommentAux", lazy="joined", uselist=False, innerjoin=True, primaryjoin="Comment.id==CommentAux.id", viewonly=True)
|
||||
author_id = Column(Integer, ForeignKey("users.id"))
|
||||
parent_submission = Column(Integer, ForeignKey("submissions.id"))
|
||||
# this column is foreignkeyed to comment(id) but we can't do that yet as
|
||||
|
@ -55,23 +50,19 @@ class Comment(Base, Age_times, Scores, Stndrd, Fuzzing):
|
|||
sentto=Column(Integer)
|
||||
|
||||
app_id = Column(Integer, ForeignKey("oauth_apps.id"))
|
||||
oauth_app=relationship("OauthApp")
|
||||
oauth_app=relationship("OauthApp", viewonly=True)
|
||||
|
||||
post = relationship("Submission")
|
||||
flags = relationship("CommentFlag", lazy="dynamic")
|
||||
author = relationship(
|
||||
"User",
|
||||
lazy="joined",
|
||||
innerjoin=True,
|
||||
primaryjoin="User.id==Comment.author_id")
|
||||
post = relationship("Submission", viewonly=True)
|
||||
flags = relationship("CommentFlag", lazy="dynamic", viewonly=True)
|
||||
author = relationship("User", lazy="joined", innerjoin=True, primaryjoin="User.id==Comment.author_id", viewonly=True)
|
||||
|
||||
upvotes = Column(Integer, default=1)
|
||||
downvotes = Column(Integer, default=0)
|
||||
|
||||
parent_comment = relationship("Comment", remote_side=[id])
|
||||
child_comments = relationship("Comment", remote_side=[parent_comment_id])
|
||||
parent_comment = relationship("Comment", remote_side=[id], viewonly=True)
|
||||
child_comments = relationship("Comment", remote_side=[parent_comment_id], viewonly=True)
|
||||
|
||||
awards = relationship("AwardRelationship", lazy="joined")
|
||||
awards = relationship("AwardRelationship", lazy="joined", viewonly=True)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
|
||||
|
@ -344,8 +335,8 @@ class Notification(Base):
|
|||
blocksender = Column(Integer)
|
||||
unblocksender = Column(Integer)
|
||||
|
||||
comment = relationship("Comment", lazy="joined", innerjoin=True)
|
||||
user=relationship("User", innerjoin=True)
|
||||
comment = relationship("Comment", lazy="joined", innerjoin=True, viewonly=True)
|
||||
user=relationship("User", innerjoin=True, viewonly=True)
|
||||
|
||||
def __repr__(self):
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ class Flag(Base, Stndrd):
|
|||
user_id = Column(Integer, ForeignKey("users.id"))
|
||||
reason = Column(String(100))
|
||||
|
||||
user = relationship("User", lazy = "joined", primaryjoin = "Flag.user_id == User.id", uselist = False)
|
||||
user = relationship("User", lazy = "joined", primaryjoin = "Flag.user_id == User.id", uselist = False, viewonly=True)
|
||||
|
||||
def __repr__(self):
|
||||
|
||||
|
@ -28,7 +28,7 @@ class CommentFlag(Base, Stndrd):
|
|||
comment_id = Column(Integer, ForeignKey("comments.id"))
|
||||
reason = Column(String(100))
|
||||
|
||||
user = relationship("User", lazy = "joined", primaryjoin = "CommentFlag.user_id == User.id", uselist = False)
|
||||
user = relationship("User", lazy = "joined", primaryjoin = "CommentFlag.user_id == User.id", uselist = False, viewonly=True)
|
||||
|
||||
def __repr__(self):
|
||||
|
||||
|
|
|
@ -18,10 +18,10 @@ class ModAction(Base, Stndrd, Age_times):
|
|||
created_utc = Column(Integer, default=0)
|
||||
|
||||
|
||||
user = relationship("User", lazy="joined", primaryjoin="User.id==ModAction.user_id")
|
||||
target_user = relationship("User", lazy="joined", primaryjoin="User.id==ModAction.target_user_id")
|
||||
target_post = relationship("Submission", lazy="joined")
|
||||
target_comment = relationship("Comment", lazy="joined")
|
||||
user = relationship("User", lazy="joined", primaryjoin="User.id==ModAction.user_id", viewonly=True)
|
||||
target_user = relationship("User", lazy="joined", primaryjoin="User.id==ModAction.target_user_id", viewonly=True)
|
||||
target_post = relationship("Submission", lazy="joined", viewonly=True)
|
||||
target_comment = relationship("Comment", lazy="joined", viewonly=True)
|
||||
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
|
|
|
@ -33,12 +33,7 @@ class Submission(Base, Stndrd, Age_times, Scores, Fuzzing):
|
|||
__tablename__ = "submissions"
|
||||
|
||||
id = Column(BigInteger, primary_key=True)
|
||||
submission_aux = relationship(
|
||||
"SubmissionAux",
|
||||
lazy="joined",
|
||||
uselist=False,
|
||||
innerjoin=True,
|
||||
primaryjoin="Submission.id==SubmissionAux.id")
|
||||
submission_aux = relationship("SubmissionAux", lazy="joined", uselist=False, innerjoin=True, primaryjoin="Submission.id==SubmissionAux.id", viewonly=True)
|
||||
author_id = Column(BigInteger, ForeignKey("users.id"))
|
||||
edited_utc = Column(BigInteger, default=0)
|
||||
created_utc = Column(BigInteger, default=0)
|
||||
|
@ -56,19 +51,11 @@ class Submission(Base, Stndrd, Age_times, Scores, Fuzzing):
|
|||
private = Column(Boolean, default=False)
|
||||
club = Column(Boolean, default=False)
|
||||
comment_count = Column(Integer, default=0)
|
||||
comments = relationship(
|
||||
"Comment",
|
||||
lazy="joined",
|
||||
primaryjoin="Comment.parent_submission==Submission.id",
|
||||
)
|
||||
flags = relationship("Flag", lazy="dynamic")
|
||||
comments = relationship("Comment", lazy="joined", primaryjoin="Comment.parent_submission==Submission.id", viewonly=True)
|
||||
flags = relationship("Flag", lazy="dynamic", viewonly=True)
|
||||
is_approved = Column(Integer, ForeignKey("users.id"), default=0)
|
||||
over_18 = Column(Boolean, default=False)
|
||||
author = relationship(
|
||||
"User",
|
||||
lazy="joined",
|
||||
innerjoin=True,
|
||||
primaryjoin="Submission.author_id==User.id")
|
||||
author = relationship("User", lazy="joined", innerjoin=True, primaryjoin="Submission.author_id==User.id", viewonly=True)
|
||||
is_pinned = Column(Boolean, default=False)
|
||||
is_bot = Column(Boolean, default=False)
|
||||
|
||||
|
@ -76,14 +63,11 @@ class Submission(Base, Stndrd, Age_times, Scores, Fuzzing):
|
|||
downvotes = Column(Integer, default=0)
|
||||
|
||||
app_id=Column(Integer, ForeignKey("oauth_apps.id"))
|
||||
oauth_app=relationship("OauthApp")
|
||||
oauth_app=relationship("OauthApp", viewonly=True)
|
||||
|
||||
approved_by = relationship(
|
||||
"User",
|
||||
uselist=False,
|
||||
primaryjoin="Submission.is_approved==User.id")
|
||||
approved_by = relationship("User", uselist=False, primaryjoin="Submission.is_approved==User.id", viewonly=True)
|
||||
|
||||
awards = relationship("AwardRelationship", lazy="joined")
|
||||
awards = relationship("AwardRelationship", lazy="joined", viewonly=True)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
from sqlalchemy import *
|
||||
from sqlalchemy.orm import relationship
|
||||
from files.__main__ import Base
|
||||
import time
|
||||
|
||||
|
||||
class Subscription(Base):
|
||||
|
@ -10,7 +9,7 @@ class Subscription(Base):
|
|||
user_id = Column(BigInteger, ForeignKey("users.id"))
|
||||
submission_id = Column(BigInteger, default=0)
|
||||
|
||||
user = relationship("User", uselist=False)
|
||||
user = relationship("User", uselist=False, viewonly=True)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
@ -25,14 +24,8 @@ class Follow(Base):
|
|||
user_id = Column(BigInteger, ForeignKey("users.id"))
|
||||
target_id = Column(BigInteger, ForeignKey("users.id"))
|
||||
|
||||
user = relationship(
|
||||
"User",
|
||||
uselist=False,
|
||||
primaryjoin="User.id==Follow.user_id")
|
||||
target = relationship(
|
||||
"User",
|
||||
lazy="joined",
|
||||
primaryjoin="User.id==Follow.target_id")
|
||||
user = relationship("User", uselist=False, rimaryjoin="User.id==Follow.user_id", viewonly=True)
|
||||
target = relationship("User", lazy="joined", primaryjoin="User.id==Follow.target_id", viewonly=True)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
|
|
@ -123,20 +123,12 @@ class User(Base, Stndrd, Age_times):
|
|||
oldreddit = Column(Boolean)
|
||||
nitter = Column(Boolean)
|
||||
controversial = Column(Boolean, default=False)
|
||||
submissions = relationship(
|
||||
"Submission",
|
||||
lazy="dynamic",
|
||||
primaryjoin="Submission.author_id==User.id")
|
||||
comments = relationship(
|
||||
"Comment",
|
||||
lazy="dynamic",
|
||||
primaryjoin="Comment.author_id==User.id")
|
||||
submissions = relationship("Submission", lazy="dynamic", primaryjoin="Submission.author_id==User.id", viewonly=True)
|
||||
comments = relationship("Comment", lazy="dynamic", primaryjoin="Comment.author_id==User.id", viewonly=True)
|
||||
bio = Column(String)
|
||||
bio_html = Column(String)
|
||||
badges = relationship("Badge", lazy="dynamic")
|
||||
notifications = relationship(
|
||||
"Notification",
|
||||
lazy="dynamic")
|
||||
badges = relationship("Badge", lazy="dynamic", viewonly=True)
|
||||
notifications = relationship("Notification", lazy="dynamic", viewonly=True)
|
||||
|
||||
is_banned = Column(Integer, default=0)
|
||||
unban_utc = Column(Integer, default=0)
|
||||
|
@ -159,31 +151,24 @@ class User(Base, Stndrd, Age_times):
|
|||
discord_id = Column(String(64))
|
||||
ban_evade = Column(Integer, default=0)
|
||||
original_username = deferred(Column(String(255)))
|
||||
subscriptions = relationship("Subscription")
|
||||
subscriptions = relationship("Subscription", viewonly=True)
|
||||
|
||||
following = relationship("Follow", primaryjoin="Follow.user_id==User.id")
|
||||
followers = relationship("Follow", primaryjoin="Follow.target_id==User.id")
|
||||
following = relationship("Follow", primaryjoin="Follow.user_id==User.id", viewonly=True)
|
||||
followers = relationship("Follow", primaryjoin="Follow.target_id==User.id", viewonly=True)
|
||||
|
||||
viewers = relationship("ViewerRelationship", primaryjoin="User.id == ViewerRelationship.user_id")
|
||||
viewers = relationship("ViewerRelationship", primaryjoin="User.id == ViewerRelationship.user_id", viewonly=True)
|
||||
|
||||
blocking = relationship("UserBlock", lazy="dynamic", primaryjoin="User.id==UserBlock.user_id")
|
||||
blocked = relationship("UserBlock", lazy="dynamic", primaryjoin="User.id==UserBlock.target_id")
|
||||
blocking = relationship("UserBlock", lazy="dynamic", primaryjoin="User.id==UserBlock.user_id", viewonly=True)
|
||||
blocked = relationship("UserBlock", lazy="dynamic", primaryjoin="User.id==UserBlock.target_id", viewonly=True)
|
||||
|
||||
_applications = relationship("OauthApp", lazy="dynamic")
|
||||
authorizations = relationship("ClientAuth", lazy="dynamic")
|
||||
_applications = relationship("OauthApp", lazy="dynamic", viewonly=True)
|
||||
authorizations = relationship("ClientAuth", lazy="dynamic", viewonly=True)
|
||||
|
||||
awards = relationship(
|
||||
"AwardRelationship",
|
||||
lazy="dynamic",
|
||||
primaryjoin="User.id==AwardRelationship.user_id"
|
||||
)
|
||||
awards = relationship("AwardRelationship", lazy="dynamic", primaryjoin="User.id==AwardRelationship.user_id", viewonly=True)
|
||||
|
||||
referred_by = Column(Integer, ForeignKey("users.id"))
|
||||
|
||||
referrals = relationship(
|
||||
"User",
|
||||
lazy="joined"
|
||||
)
|
||||
referrals = relationship("User", lazy="joined", viewonly=True)
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
|
||||
|
@ -623,8 +608,7 @@ class ViewerRelationship(Base):
|
|||
viewer_id = Column(Integer, ForeignKey('users.id'))
|
||||
last_view_utc = Column(Integer)
|
||||
|
||||
user = relationship("User", lazy="joined", primaryjoin="ViewerRelationship.user_id == User.id")
|
||||
viewer = relationship("User", lazy="joined", primaryjoin="ViewerRelationship.viewer_id == User.id")
|
||||
viewer = relationship("User", lazy="joined", primaryjoin="ViewerRelationship.viewer_id == User.id", viewonly=True)
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
|
||||
|
|
|
@ -10,14 +10,8 @@ class UserBlock(Base, Stndrd, Age_times):
|
|||
user_id = Column(Integer, ForeignKey("users.id"))
|
||||
target_id = Column(Integer, ForeignKey("users.id"))
|
||||
|
||||
user = relationship(
|
||||
"User",
|
||||
innerjoin=True,
|
||||
primaryjoin="User.id==UserBlock.user_id")
|
||||
target = relationship(
|
||||
"User",
|
||||
innerjoin=True,
|
||||
primaryjoin="User.id==UserBlock.target_id")
|
||||
user = relationship("User", innerjoin=True, primaryjoin="User.id==UserBlock.user_id", viewonly=True)
|
||||
target = relationship("User", innerjoin=True, primaryjoin="User.id==UserBlock.target_id", viewonly=True)
|
||||
|
||||
def __repr__(self):
|
||||
|
||||
|
|
|
@ -13,8 +13,8 @@ class Vote(Base):
|
|||
submission_id = Column(Integer, ForeignKey("submissions.id"))
|
||||
app_id = Column(Integer, ForeignKey("oauth_apps.id"))
|
||||
|
||||
user = relationship("User", lazy="subquery")
|
||||
post = relationship("Submission", lazy="subquery")
|
||||
user = relationship("User", lazy="subquery", viewonly=True)
|
||||
post = relationship("Submission", lazy="subquery", viewonly=True)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
|
||||
|
@ -51,8 +51,8 @@ class CommentVote(Base):
|
|||
comment_id = Column(Integer, ForeignKey("comments.id"))
|
||||
app_id = Column(Integer, ForeignKey("oauth_apps.id"))
|
||||
|
||||
user = relationship("User", lazy="subquery")
|
||||
comment = relationship("Comment", lazy="subquery")
|
||||
user = relationship("User", lazy="subquery", viewonly=True)
|
||||
comment = relationship("Comment", lazy="subquery", viewonly=True)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue