Verified Commit 8387f325 authored by Kevin Morris's avatar Kevin Morris
Browse files

fix: resolve null VoteTS columns via migration



Somehow, many aur.al records of PackageVotes do not have a valid VoteTS
value. This migration fixes that issue by setting all null VoteTS
columns to the epoch timestamp.
Signed-off-by: Kevin Morris's avatarKevin Morris <kevr@0cost.org>
parent 1d86b3e2
Pipeline #15998 passed with stages
in 2 minutes and 57 seconds
......@@ -269,7 +269,7 @@ PackageVotes = Table(
'PackageVotes', metadata,
Column('UsersID', ForeignKey('Users.ID', ondelete='CASCADE'), nullable=False),
Column('PackageBaseID', ForeignKey('PackageBases.ID', ondelete='CASCADE'), nullable=False),
Column('VoteTS', BIGINT(unsigned=True)),
Column('VoteTS', BIGINT(unsigned=True), nullable=False),
Index('VoteUsersIDPackageID', 'UsersID', 'PackageBaseID', unique=True),
Index('VotesPackageBaseID', 'PackageBaseID'),
Index('VotesUsersID', 'UsersID'),
......
"""fix pkgvote votets
Revision ID: d64e5571bc8d
Revises: be7adae47ac3
Create Date: 2022-02-18 12:47:05.322766
"""
from datetime import datetime
import sqlalchemy as sa
from alembic import op
from aurweb import db
from aurweb.models import PackageVote
# revision identifiers, used by Alembic.
revision = 'd64e5571bc8d'
down_revision = 'be7adae47ac3'
branch_labels = None
depends_on = None
table = PackageVote.__tablename__
column = 'VoteTS'
epoch = datetime(1970, 1, 1)
def upgrade():
with db.begin():
records = db.query(PackageVote).filter(PackageVote.VoteTS.is_(None))
for record in records:
record.VoteTS = epoch.timestamp()
op.alter_column(table, column, existing_type=sa.BIGINT(), nullable=False)
def downgrade():
op.alter_column(table, column, existing_type=sa.BIGINT(), nullable=True)
......@@ -16,6 +16,8 @@ import random
import sys
import time
from datetime import datetime
import bcrypt
LOG_LEVEL = logging.DEBUG # logging level. set to logging.INFO to reduce output
......@@ -203,7 +205,7 @@ for u in user_keys:
log.debug("Number of developers: %d" % len(developers))
log.debug("Number of trusted users: %d" % len(trustedusers))
log.debug("Number of users: %d" % (MAX_USERS-len(developers)-len(trustedusers)))
log.debug("Number of users: %d" % (MAX_USERS - len(developers) - len(trustedusers)))
log.debug("Number of packages: %d" % MAX_PKGS)
log.debug("Gathering text from fortune file...")
......@@ -244,26 +246,27 @@ for p in list(seen_pkgs.keys()):
#
num_comments = random.randrange(PKG_CMNTS[0], PKG_CMNTS[1])
for i in range(0, num_comments):
now = NOW + random.randrange(400, 86400*3)
now = NOW + random.randrange(400, 86400 * 3)
s = ("INSERT INTO PackageComments (PackageBaseID, UsersID,"
" Comments, RenderedComment, CommentTS) VALUES (%d, %d, '%s', '', %d);\n")
s = s % (seen_pkgs[p], genUID(), genFortune(), now)
out.write(s)
# Cast votes
#
utcnow = int(datetime.utcnow().timestamp())
track_votes = {}
log.debug("Casting votes for packages.")
for u in user_keys:
num_votes = random.randrange(int(len(seen_pkgs)*VOTING[0]),
int(len(seen_pkgs)*VOTING[1]))
num_votes = random.randrange(int(len(seen_pkgs) * VOTING[0]),
int(len(seen_pkgs) * VOTING[1]))
pkgvote = {}
for v in range(num_votes):
pkg = random.randrange(1, len(seen_pkgs) + 1)
if pkg not in pkgvote:
s = ("INSERT INTO PackageVotes (UsersID, PackageBaseID)"
" VALUES (%d, %d);\n")
s = s % (seen_users[u], pkg)
s = ("INSERT INTO PackageVotes (UsersID, PackageBaseID, VoteTS)"
" VALUES (%d, %d, %d);\n")
s = s % (seen_users[u], pkg, utcnow)
pkgvote[pkg] = 1
if pkg not in track_votes:
track_votes[pkg] = 0
......@@ -318,14 +321,14 @@ for p in seen_pkgs_keys:
#
log.debug("Creating SQL statements for trusted user proposals.")
count = 0
for t in range(0, OPEN_PROPOSALS+CLOSE_PROPOSALS):
for t in range(0, OPEN_PROPOSALS + CLOSE_PROPOSALS):
now = int(time.time())
if count < CLOSE_PROPOSALS:
start = now - random.randrange(3600*24*7, 3600*24*21)
end = now - random.randrange(0, 3600*24*7)
start = now - random.randrange(3600 * 24 * 7, 3600 * 24 * 21)
end = now - random.randrange(0, 3600 * 24 * 7)
else:
start = now
end = now + random.randrange(3600*24, 3600*24*7)
end = now + random.randrange(3600 * 24, 3600 * 24 * 7)
if count % 5 == 0: # Don't make the vote about anyone once in a while
user = ""
else:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment