notifications got created_datetimez
This commit is contained in:
parent
d72a94728c
commit
0879033f55
3 changed files with 57 additions and 5 deletions
|
@ -1,8 +1,8 @@
|
||||||
from sqlalchemy import *
|
from sqlalchemy import *
|
||||||
from sqlalchemy.orm import relationship
|
from sqlalchemy.orm import relationship
|
||||||
from files.classes.base import CreatedBase
|
from files.classes.base import CreatedDateTimeBase
|
||||||
|
|
||||||
class Notification(CreatedBase):
|
class Notification(CreatedDateTimeBase):
|
||||||
__tablename__ = "notifications"
|
__tablename__ = "notifications"
|
||||||
|
|
||||||
user_id = Column(Integer, ForeignKey("users.id"), primary_key=True)
|
user_id = Column(Integer, ForeignKey("users.id"), primary_key=True)
|
||||||
|
|
|
@ -30,7 +30,7 @@ def unread(v):
|
||||||
Comment.state_mod == StateMod.VISIBLE,
|
Comment.state_mod == StateMod.VISIBLE,
|
||||||
Comment.state_user_deleted_utc == None,
|
Comment.state_user_deleted_utc == None,
|
||||||
Comment.author_id != AUTOJANNY_ID,
|
Comment.author_id != AUTOJANNY_ID,
|
||||||
).order_by(Notification.created_utc.desc()).all()
|
).order_by(Notification.created_datetimez.desc()).all()
|
||||||
|
|
||||||
for n, c in listing:
|
for n, c in listing:
|
||||||
n.read = True
|
n.read = True
|
||||||
|
@ -52,7 +52,7 @@ def notifications_main(v: User):
|
||||||
Comment.state_mod == StateMod.VISIBLE,
|
Comment.state_mod == StateMod.VISIBLE,
|
||||||
Comment.state_user_deleted_utc == None,
|
Comment.state_user_deleted_utc == None,
|
||||||
Comment.author_id != AUTOJANNY_ID,
|
Comment.author_id != AUTOJANNY_ID,
|
||||||
).order_by(Notification.created_utc.desc()))
|
).order_by(Notification.created_datetimez.desc()))
|
||||||
|
|
||||||
if not v.shadowbanned and v.admin_level < 3:
|
if not v.shadowbanned and v.admin_level < 3:
|
||||||
comments = comments.join(Comment.author).filter(User.shadowbanned == None)
|
comments = comments.join(Comment.author).filter(User.shadowbanned == None)
|
||||||
|
@ -96,7 +96,7 @@ def notifications_posts(v: User):
|
||||||
notifications = (g.db.query(Notification, Comment)
|
notifications = (g.db.query(Notification, Comment)
|
||||||
.join(Comment, Notification.comment_id == Comment.id)
|
.join(Comment, Notification.comment_id == Comment.id)
|
||||||
.filter(Notification.user_id == v.id, Comment.author_id == AUTOJANNY_ID)
|
.filter(Notification.user_id == v.id, Comment.author_id == AUTOJANNY_ID)
|
||||||
.order_by(Notification.created_utc.desc()).offset(25 * (page - 1)).limit(101).all())
|
.order_by(Notification.created_datetimez.desc()).offset(25 * (page - 1)).limit(101).all())
|
||||||
|
|
||||||
listing = []
|
listing = []
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,52 @@
|
||||||
|
"""Change to datetimez table notifications
|
||||||
|
|
||||||
|
Revision ID: 4376dcec1ad8
|
||||||
|
Revises: 84e02ade75a8
|
||||||
|
Create Date: 2023-07-30 01:49:16.238320+00:00
|
||||||
|
|
||||||
|
"""
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
from sqlalchemy.sql.functions import now
|
||||||
|
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision = '4376dcec1ad8'
|
||||||
|
down_revision = '84e02ade75a8'
|
||||||
|
branch_labels = None
|
||||||
|
depends_on = None
|
||||||
|
|
||||||
|
table_name = 'notifications'
|
||||||
|
from_column = 'created_utc'
|
||||||
|
to_column = 'created_datetimez'
|
||||||
|
|
||||||
|
def upgrade():
|
||||||
|
op.add_column(table_name, sa.Column(to_column, sa.DateTime(timezone=True), nullable=True, server_default=now()))
|
||||||
|
op.execute(f"""
|
||||||
|
UPDATE {table_name}
|
||||||
|
SET {to_column} =
|
||||||
|
CASE
|
||||||
|
WHEN {from_column} > 0 THEN
|
||||||
|
(timestamp 'epoch' + {from_column} * interval '1 second') at time zone 'utc'
|
||||||
|
ELSE NULL
|
||||||
|
END
|
||||||
|
""")
|
||||||
|
op.alter_column(table_name, to_column, nullable=False)
|
||||||
|
op.drop_column(table_name, from_column)
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade():
|
||||||
|
"""
|
||||||
|
Downgrade will truncate the milliseconds.
|
||||||
|
"""
|
||||||
|
op.add_column(table_name, sa.Column('created_utc', sa.Integer(), server_default=sa.text('0'), nullable=True))
|
||||||
|
op.execute(f"""
|
||||||
|
UPDATE {table_name}
|
||||||
|
SET created_utc =
|
||||||
|
COALESCE(
|
||||||
|
EXTRACT(EPOCH FROM {to_column})::integer,
|
||||||
|
0
|
||||||
|
)
|
||||||
|
""")
|
||||||
|
op.alter_column(table_name, from_column, nullable=False)
|
||||||
|
op.drop_column(table_name, to_column)
|
Loading…
Add table
Add a link
Reference in a new issue