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