From d7c3ddf474c82fb34235bfff868f7a24f8431c82 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Mon, 12 Sep 2022 12:19:35 +0200 Subject: [PATCH] add created_utc column to all tables --- files/classes/alts.py | 7 ++++++- files/classes/award.py | 6 ++++++ files/classes/badges.py | 5 +++++ files/classes/category.py | 9 +++++++++ files/classes/clients.py | 12 +++++++++++- files/classes/domains.py | 6 ++++++ files/classes/exiles.py | 6 ++++++ files/classes/hats.py | 17 +++++++++++++++++ files/classes/lottery.py | 6 +++++- files/classes/marsey.py | 6 ++++++ files/classes/polls.py | 10 ++++++++++ files/classes/saves.py | 12 +++++++++++- files/classes/sub.py | 6 ++++++ files/classes/sub_block.py | 6 ++++++ files/classes/sub_join.py | 6 ++++++ files/classes/sub_subscription.py | 6 ++++++ files/classes/subscriptions.py | 5 ++++- files/classes/user.py | 3 --- files/classes/userblock.py | 6 ++++++ files/classes/views.py | 7 +++---- sql/20220912-created_utc-columns.sql | 23 +++++++++++++++++++++++ 21 files changed, 158 insertions(+), 12 deletions(-) create mode 100644 sql/20220912-created_utc-columns.sql diff --git a/files/classes/alts.py b/files/classes/alts.py index 5e9bf1d8ae..1a0c11a3c4 100644 --- a/files/classes/alts.py +++ b/files/classes/alts.py @@ -1,6 +1,6 @@ from sqlalchemy import * from files.__main__ import Base - +import time class Alt(Base): __tablename__ = "alts" @@ -8,6 +8,11 @@ class Alt(Base): user1 = Column(Integer, ForeignKey("users.id"), primary_key=True) user2 = Column(Integer, ForeignKey("users.id"), primary_key=True) is_manual = Column(Boolean, default=False) + created_utc = Column(Integer) + + def __init__(self, *args, **kwargs): + if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time()) + super().__init__(*args, **kwargs) def __repr__(self): diff --git a/files/classes/award.py b/files/classes/award.py index 4e2793ad9f..60b00664d8 100644 --- a/files/classes/award.py +++ b/files/classes/award.py @@ -3,6 +3,7 @@ from sqlalchemy.orm import relationship from files.__main__ import Base from files.helpers.lazy import lazy from files.helpers.const import * +import time class AwardRelationship(Base): @@ -15,11 +16,16 @@ class AwardRelationship(Base): kind = Column(String) awarded_utc = Column(Integer) granted = Column(Boolean) + created_utc = Column(Integer) user = relationship("User", primaryjoin="AwardRelationship.user_id==User.id", back_populates="awards") post = relationship("Submission", primaryjoin="AwardRelationship.submission_id==Submission.id", back_populates="awards") comment = relationship("Comment", primaryjoin="AwardRelationship.comment_id==Comment.id", back_populates="awards") + def __init__(self, *args, **kwargs): + if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time()) + super().__init__(*args, **kwargs) + def __repr__(self): return f"" diff --git a/files/classes/badges.py b/files/classes/badges.py index 98fe6a3ff9..0fc6333f44 100644 --- a/files/classes/badges.py +++ b/files/classes/badges.py @@ -11,6 +11,11 @@ class BadgeDef(Base): id = Column(Integer, primary_key=True, autoincrement=True) name = Column(String) description = Column(String) + created_utc = Column(Integer) + + def __init__(self, *args, **kwargs): + if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time()) + super().__init__(*args, **kwargs) def __repr__(self): return f"" diff --git a/files/classes/category.py b/files/classes/category.py index 655e711d6d..c601bb1258 100644 --- a/files/classes/category.py +++ b/files/classes/category.py @@ -1,6 +1,7 @@ from sqlalchemy import * from sqlalchemy.orm import relationship from files.__main__ import Base +import time class Category(Base): __tablename__ = "category" @@ -10,6 +11,14 @@ class Category(Base): sub = Column(String(20), ForeignKey("subs.name")) color_text = Column(String(6)) color_bg = Column(String(6)) + created_utc = Column(Integer) + + def __init__(self, *args, **kwargs): + if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time()) + super().__init__(*args, **kwargs) + + def __repr__(self): + return f"" def as_json(self): data = { diff --git a/files/classes/clients.py b/files/classes/clients.py index 2a767d3fde..12d753d472 100644 --- a/files/classes/clients.py +++ b/files/classes/clients.py @@ -18,9 +18,14 @@ class OauthApp(Base): redirect_uri = Column(String) description = Column(String) author_id = Column(Integer, ForeignKey("users.id")) + created_utc = Column(Integer) author = relationship("User", back_populates="apps") + def __init__(self, *args, **kwargs): + if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time()) + super().__init__(*args, **kwargs) + def __repr__(self): return f"" @@ -61,9 +66,14 @@ class ClientAuth(Base): user_id = Column(Integer, ForeignKey("users.id"), primary_key=True) oauth_client = Column(Integer, ForeignKey("oauth_apps.id"), primary_key=True) access_token = Column(String) - + created_utc = Column(Integer) + user = relationship("User") application = relationship("OauthApp") + def __init__(self, *args, **kwargs): + if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time()) + super().__init__(*args, **kwargs) + def __repr__(self): return f"" \ No newline at end of file diff --git a/files/classes/domains.py b/files/classes/domains.py index 9047dbe76b..fb24316fed 100644 --- a/files/classes/domains.py +++ b/files/classes/domains.py @@ -1,11 +1,17 @@ from sqlalchemy import * from files.__main__ import Base +import time class BannedDomain(Base): __tablename__ = "banneddomains" domain = Column(String, primary_key=True) reason = Column(String) + created_utc = Column(Integer) + + def __init__(self, *args, **kwargs): + if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time()) + super().__init__(*args, **kwargs) def __repr__(self): return f"" \ No newline at end of file diff --git a/files/classes/exiles.py b/files/classes/exiles.py index 16ba16bc55..9330840d0b 100644 --- a/files/classes/exiles.py +++ b/files/classes/exiles.py @@ -1,6 +1,7 @@ from sqlalchemy import * from sqlalchemy.orm import relationship from files.__main__ import Base +import time class Exile(Base): @@ -8,8 +9,13 @@ class Exile(Base): user_id = Column(Integer, ForeignKey("users.id"), primary_key=True) sub = Column(String, ForeignKey("subs.name"), primary_key=True) exiler_id = Column(Integer, ForeignKey("users.id")) + created_utc = Column(Integer) exiler = relationship("User", primaryjoin="User.id==Exile.exiler_id") + def __init__(self, *args, **kwargs): + if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time()) + super().__init__(*args, **kwargs) + def __repr__(self): return f"" \ No newline at end of file diff --git a/files/classes/hats.py b/files/classes/hats.py index a65739a4c2..32824b7c38 100644 --- a/files/classes/hats.py +++ b/files/classes/hats.py @@ -4,6 +4,7 @@ from files.__main__ import Base from files.helpers.lazy import lazy from files.helpers.regex import censor_slurs from flask import g +import time class HatDef(Base): __tablename__ = "hat_defs" @@ -14,10 +15,18 @@ class HatDef(Base): author_id = Column(Integer, ForeignKey('users.id')) price = Column(Integer) submitter_id = Column(Integer, ForeignKey("users.id")) + created_utc = Column(Integer) author = relationship("User", primaryjoin="HatDef.author_id == User.id", back_populates="designed_hats") submitter = relationship("User", primaryjoin="HatDef.submitter_id == User.id") + def __init__(self, *args, **kwargs): + if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time()) + super().__init__(*args, **kwargs) + + def __repr__(self): + return f"" + @property @lazy def number_sold(self): @@ -33,10 +42,18 @@ class Hat(Base): user_id = Column(Integer, ForeignKey('users.id'), primary_key=True) hat_id = Column(Integer, ForeignKey('hat_defs.id'), primary_key=True) equipped = Column(Boolean, default=False) + created_utc = Column(Integer) hat_def = relationship("HatDef") owners = relationship("User", back_populates="owned_hats") + def __init__(self, *args, **kwargs): + if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time()) + super().__init__(*args, **kwargs) + + def __repr__(self): + return f"" + @property @lazy def name(self): diff --git a/files/classes/lottery.py b/files/classes/lottery.py index b05ece920f..8ea2fe1d1b 100644 --- a/files/classes/lottery.py +++ b/files/classes/lottery.py @@ -4,7 +4,6 @@ from files.__main__ import Base from files.helpers.lazy import lazy from files.helpers.const import * - class Lottery(Base): __tablename__ = "lotteries" @@ -14,6 +13,11 @@ class Lottery(Base): prize = Column(Integer, default=0) tickets_sold = Column(Integer, default=0) winner_id = Column(Integer, ForeignKey("users.id")) + created_utc = Column(Integer) + + def __init__(self, *args, **kwargs): + if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time()) + super().__init__(*args, **kwargs) def __repr__(self): return f"" diff --git a/files/classes/marsey.py b/files/classes/marsey.py index a5c88a7187..8a60a12a95 100644 --- a/files/classes/marsey.py +++ b/files/classes/marsey.py @@ -1,5 +1,6 @@ from sqlalchemy import * from files.__main__ import Base +import time class Marsey(Base): __tablename__ = "marseys" @@ -9,6 +10,11 @@ class Marsey(Base): tags = Column(String) count = Column(Integer, default=0) submitter_id = Column(Integer, ForeignKey("users.id")) + created_utc = Column(Integer) + + def __init__(self, *args, **kwargs): + if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time()) + super().__init__(*args, **kwargs) def __repr__(self): return f"" \ No newline at end of file diff --git a/files/classes/polls.py b/files/classes/polls.py index 066b3006d5..1b90dba28b 100644 --- a/files/classes/polls.py +++ b/files/classes/polls.py @@ -12,10 +12,15 @@ class SubmissionOption(Base): submission_id = Column(Integer, ForeignKey("submissions.id")) body_html = Column(Text) exclusive = Column(Integer) + created_utc = Column(Integer) votes = relationship("SubmissionOptionVote") post = relationship("Submission", back_populates="options") + def __init__(self, *args, **kwargs): + if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time()) + super().__init__(*args, **kwargs) + def __repr__(self): return f"" @@ -57,10 +62,15 @@ class CommentOption(Base): comment_id = Column(Integer, ForeignKey("comments.id")) body_html = Column(Text) exclusive = Column(Integer) + created_utc = Column(Integer) votes = relationship("CommentOptionVote") comment = relationship("Comment", back_populates="options") + def __init__(self, *args, **kwargs): + if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time()) + super().__init__(*args, **kwargs) + def __repr__(self): return f"" diff --git a/files/classes/saves.py b/files/classes/saves.py index 6143395569..85a11afa2b 100644 --- a/files/classes/saves.py +++ b/files/classes/saves.py @@ -1,7 +1,7 @@ from sqlalchemy import * from sqlalchemy.orm import relationship from files.__main__ import Base - +import time class SaveRelationship(Base): @@ -9,9 +9,14 @@ class SaveRelationship(Base): user_id=Column(Integer, ForeignKey("users.id"), primary_key=True) submission_id=Column(Integer, ForeignKey("submissions.id"), primary_key=True) + created_utc = Column(Integer) post = relationship("Submission", uselist=False) + def __init__(self, *args, **kwargs): + if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time()) + super().__init__(*args, **kwargs) + def __repr__(self): return f"" @@ -22,8 +27,13 @@ class CommentSaveRelationship(Base): user_id=Column(Integer, ForeignKey("users.id"), primary_key=True) comment_id=Column(Integer, ForeignKey("comments.id"), primary_key=True) + created_utc = Column(Integer) comment = relationship("Comment", uselist=False) + def __init__(self, *args, **kwargs): + if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time()) + super().__init__(*args, **kwargs) + def __repr__(self): return f"" \ No newline at end of file diff --git a/files/classes/sub.py b/files/classes/sub.py index d9e4f8954f..97f3a54ad4 100644 --- a/files/classes/sub.py +++ b/files/classes/sub.py @@ -5,6 +5,7 @@ from files.helpers.lazy import lazy from os import environ from .sub_block import * from .sub_subscription import * +import time SITE_NAME = environ.get("SITE_NAME", '').strip() SITE = environ.get("DOMAIN", '').strip() @@ -21,10 +22,15 @@ class Sub(Base): marseyurl = Column(String) css = Column(String) stealth = Column(Boolean) + created_utc = Column(Integer) blocks = relationship("SubBlock", primaryjoin="SubBlock.sub==Sub.name") followers = relationship("SubSubscription", primaryjoin="SubSubscription.sub==Sub.name") + def __init__(self, *args, **kwargs): + if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time()) + super().__init__(*args, **kwargs) + def __repr__(self): return self.name diff --git a/files/classes/sub_block.py b/files/classes/sub_block.py index cfdcad1415..6f8d387500 100644 --- a/files/classes/sub_block.py +++ b/files/classes/sub_block.py @@ -1,10 +1,16 @@ from sqlalchemy import * from files.__main__ import Base +import time class SubBlock(Base): __tablename__ = "sub_blocks" user_id = Column(Integer, ForeignKey("users.id"), primary_key=True) sub = Column(String(20), ForeignKey("subs.name"), primary_key=True) + created_utc = Column(Integer) + + def __init__(self, *args, **kwargs): + if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time()) + super().__init__(*args, **kwargs) def __repr__(self): return f"" \ No newline at end of file diff --git a/files/classes/sub_join.py b/files/classes/sub_join.py index 7bb60780f8..b4ba7e23e8 100644 --- a/files/classes/sub_join.py +++ b/files/classes/sub_join.py @@ -1,10 +1,16 @@ from sqlalchemy import * from files.__main__ import Base +import time class SubJoin(Base): __tablename__ = "sub_joins" user_id = Column(Integer, ForeignKey("users.id"), primary_key=True) sub = Column(String(20), ForeignKey("subs.name"), primary_key=True) + created_utc = Column(Integer) + + def __init__(self, *args, **kwargs): + if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time()) + super().__init__(*args, **kwargs) def __repr__(self): return f"" \ No newline at end of file diff --git a/files/classes/sub_subscription.py b/files/classes/sub_subscription.py index a82ffc8853..4f289f145a 100644 --- a/files/classes/sub_subscription.py +++ b/files/classes/sub_subscription.py @@ -1,10 +1,16 @@ from sqlalchemy import * from files.__main__ import Base +import time class SubSubscription(Base): __tablename__ = "sub_subscriptions" user_id = Column(Integer, ForeignKey("users.id"), primary_key=True) sub = Column(String(20), ForeignKey("subs.name"), primary_key=True) + created_utc = Column(Integer) + + def __init__(self, *args, **kwargs): + if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time()) + super().__init__(*args, **kwargs) def __repr__(self): return f"" \ No newline at end of file diff --git a/files/classes/subscriptions.py b/files/classes/subscriptions.py index debdad8824..dc2b9c27d2 100644 --- a/files/classes/subscriptions.py +++ b/files/classes/subscriptions.py @@ -1,16 +1,19 @@ from sqlalchemy import * from sqlalchemy.orm import relationship from files.__main__ import Base +import time class Subscription(Base): __tablename__ = "subscriptions" user_id = Column(Integer, ForeignKey("users.id"), primary_key=True) submission_id = Column(Integer, ForeignKey("submissions.id"), primary_key=True) - + created_utc = Column(Integer) + user = relationship("User", uselist=False) post = relationship("Submission", uselist=False) def __init__(self, *args, **kwargs): + if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time()) super().__init__(*args, **kwargs) def __repr__(self): diff --git a/files/classes/user.py b/files/classes/user.py index 268bac9a4e..dca2d8a87a 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -475,9 +475,6 @@ class User(Base): def url(self): return f"/@{self.username}" - def __repr__(self): - return f"" - @property @lazy def unban_string(self): diff --git a/files/classes/userblock.py b/files/classes/userblock.py index b4c5ad3ac9..2dd5bd3e4d 100644 --- a/files/classes/userblock.py +++ b/files/classes/userblock.py @@ -1,15 +1,21 @@ from sqlalchemy import * from sqlalchemy.orm import relationship from files.__main__ import Base +import time class UserBlock(Base): __tablename__ = "userblocks" user_id = Column(Integer, ForeignKey("users.id"), primary_key=True) target_id = Column(Integer, ForeignKey("users.id"), primary_key=True) + created_utc = Column(Integer) user = relationship("User", primaryjoin="User.id==UserBlock.user_id", back_populates="blocking") target = relationship("User", primaryjoin="User.id==UserBlock.target_id", back_populates="blocked") + def __init__(self, *args, **kwargs): + if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time()) + super().__init__(*args, **kwargs) + def __repr__(self): return f"" \ No newline at end of file diff --git a/files/classes/views.py b/files/classes/views.py index 2b12f5695a..b3007003de 100644 --- a/files/classes/views.py +++ b/files/classes/views.py @@ -11,14 +11,13 @@ class ViewerRelationship(Base): user_id = Column(Integer, ForeignKey('users.id'), primary_key=True) viewer_id = Column(Integer, ForeignKey('users.id'), primary_key=True) last_view_utc = Column(Integer) + created_utc = Column(Integer) viewer = relationship("User", primaryjoin="ViewerRelationship.viewer_id == User.id") def __init__(self, **kwargs): - - if 'last_view_utc' not in kwargs: - kwargs['last_view_utc'] = int(time.time()) - + if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time()) + if 'last_view_utc' not in kwargs: kwargs['last_view_utc'] = int(time.time()) super().__init__(**kwargs) def __repr__(self): diff --git a/sql/20220912-created_utc-columns.sql b/sql/20220912-created_utc-columns.sql new file mode 100644 index 0000000000..a39fcd0939 --- /dev/null +++ b/sql/20220912-created_utc-columns.sql @@ -0,0 +1,23 @@ +alter table alts add column created_utc int; +alter table award_relationships add column created_utc int; +alter table badge_defs add column created_utc int; +alter table category add column created_utc int; +alter table oauth_apps add column created_utc int; +alter table client_auths add column created_utc int; +alter table banneddomains add column created_utc int; +alter table exiles add column created_utc int; +alter table hat_defs add column created_utc int; +alter table hats add column created_utc int; +alter table lotteries add column created_utc int; +alter table marseys add column created_utc int; +alter table submission_options add column created_utc int; +alter table comment_options add column created_utc int; +alter table save_relationship add column created_utc int; +alter table comment_save_relationship add column created_utc int; +alter table sub_blocks add column created_utc int; +alter table sub_joins add column created_utc int; +alter table sub_subscriptions add column created_utc int; +alter table subs add column created_utc int; +alter table subscriptions add column created_utc int; +alter table userblocks add column created_utc int; +alter table viewers add column created_utc int;