usernotes got created_datetimez
This commit is contained in:
parent
0879033f55
commit
cdb30a963b
3 changed files with 56 additions and 3 deletions
|
@ -1,6 +1,6 @@
|
||||||
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
|
||||||
from files.helpers.config.const import *
|
from files.helpers.config.const import *
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from sqlalchemy import Enum as EnumType
|
from sqlalchemy import Enum as EnumType
|
||||||
|
@ -15,7 +15,7 @@ class UserTag(Enum):
|
||||||
Spam = 6
|
Spam = 6
|
||||||
Bot = 7
|
Bot = 7
|
||||||
|
|
||||||
class UserNote(CreatedBase):
|
class UserNote(CreatedDateTimeBase):
|
||||||
__tablename__ = "usernotes"
|
__tablename__ = "usernotes"
|
||||||
|
|
||||||
id = Column(Integer, primary_key=True)
|
id = Column(Integer, primary_key=True)
|
||||||
|
|
|
@ -169,7 +169,7 @@ def volunteer_janitor_recalc(db: Session, diagnostics: bool = False):
|
||||||
|
|
||||||
usernotes_raw = db.query(UserNote) \
|
usernotes_raw = db.query(UserNote) \
|
||||||
.where(UserNote.tag.in_([UserTag.Warning, UserTag.Tempban, UserTag.Permban, UserTag.Spam, UserTag.Bot])) \
|
.where(UserNote.tag.in_([UserTag.Warning, UserTag.Tempban, UserTag.Permban, UserTag.Spam, UserTag.Bot])) \
|
||||||
.options(sqlalchemy.orm.load_only('reference_user', 'created_utc', 'tag'))
|
.options(sqlalchemy.orm.load_only('reference_user', 'created_datetimez', 'tag'))
|
||||||
|
|
||||||
# Here we're trying to figure out whether modhats are actually warnings/bans
|
# Here we're trying to figure out whether modhats are actually warnings/bans
|
||||||
# We don't have a formal connection between "a comment is bad" and "the user got a warning", so we're kind of awkwardly trying to derive it from our database
|
# We don't have a formal connection between "a comment is bad" and "the user got a warning", so we're kind of awkwardly trying to derive it from our database
|
||||||
|
|
|
@ -0,0 +1,53 @@
|
||||||
|
"""Change to datetimez table usernotes
|
||||||
|
|
||||||
|
Revision ID: 7f0427506952
|
||||||
|
Revises: 4376dcec1ad8
|
||||||
|
Create Date: 2023-07-30 02:06:08.372763+00:00
|
||||||
|
|
||||||
|
"""
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision = '7f0427506952'
|
||||||
|
down_revision = '4376dcec1ad8'
|
||||||
|
branch_labels = None
|
||||||
|
depends_on = None
|
||||||
|
|
||||||
|
|
||||||
|
table_name = 'usernotes'
|
||||||
|
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