From 4623e7c1a3b19995e696adf90c484522feefd01c Mon Sep 17 00:00:00 2001 From: Aevann Date: Sun, 13 Aug 2023 19:02:55 +0300 Subject: [PATCH] fix ping_cost not getting summed with previous value --- files/classes/comment.py | 2 +- files/classes/post.py | 2 +- files/helpers/actions.py | 2 +- files/helpers/alerts.py | 4 ++-- migrations/20230813-fix-ping-cost-not-getting-summedsql.sql | 4 ++++ 5 files changed, 9 insertions(+), 5 deletions(-) create mode 100644 migrations/20230813-fix-ping-cost-not-getting-summedsql.sql diff --git a/files/classes/comment.py b/files/classes/comment.py index e57d7f488..699f17645 100644 --- a/files/classes/comment.py +++ b/files/classes/comment.py @@ -139,7 +139,7 @@ class Comment(Base): ban_reason = Column(String) treasure_amount = Column(String) slots_result = Column(String) - ping_cost = Column(Integer) + ping_cost = Column(Integer, default=0) blackjack_result = Column(String) casino_game_id = Column(Integer, ForeignKey("casino_games.id")) chudded = Column(Boolean, default=False) diff --git a/files/classes/post.py b/files/classes/post.py index eaa722dc5..c63ddad88 100644 --- a/files/classes/post.py +++ b/files/classes/post.py @@ -60,7 +60,7 @@ class Post(Base): new = Column(Boolean) notify = Column(Boolean) chudded = Column(Boolean, default=False) - ping_cost = Column(Integer) + ping_cost = Column(Integer, default=0) bump_utc = Column(Integer) author = relationship("User", primaryjoin="Post.author_id==User.id") diff --git a/files/helpers/actions.py b/files/helpers/actions.py index 629532be9..d31c628df 100644 --- a/files/helpers/actions.py +++ b/files/helpers/actions.py @@ -210,7 +210,7 @@ def execute_snappy(post, v): ) if ping_cost: - c.ping_cost = ping_cost + c.ping_cost += ping_cost g.db.add(c) diff --git a/files/helpers/alerts.py b/files/helpers/alerts.py index 94dcf3486..dc1501501 100644 --- a/files/helpers/alerts.py +++ b/files/helpers/alerts.py @@ -159,7 +159,7 @@ def NOTIFY_USERS(text, v, oldtext=None, ghost=False, log_cost=None, followers_pi v.charge_account('combined', cost) if log_cost: - log_cost.ping_cost = cost + log_cost.ping_cost += cost return 'everyone' elif i.group(1) == 'jannies': group = None @@ -186,7 +186,7 @@ def NOTIFY_USERS(text, v, oldtext=None, ghost=False, log_cost=None, followers_pi abort(403, f"You need {cost} coins to mention these ping groups!") if log_cost: - log_cost.ping_cost = cost + log_cost.ping_cost += cost if i.group(1) in {'biofoids','neofoids','jannies'}: coin_receivers.update(member_ids) diff --git a/migrations/20230813-fix-ping-cost-not-getting-summedsql.sql b/migrations/20230813-fix-ping-cost-not-getting-summedsql.sql new file mode 100644 index 000000000..b18bffb86 --- /dev/null +++ b/migrations/20230813-fix-ping-cost-not-getting-summedsql.sql @@ -0,0 +1,4 @@ +update posts set ping_cost=0 where ping_cost is null; +alter table posts alter column ping_cost set not null; +update comments set ping_cost=0 where ping_cost is null; +alter table comments alter column ping_cost set not null;