mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
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 <kevr@0cost.org>
This commit is contained in:
parent
1d86b3e210
commit
8387f325f6
3 changed files with 53 additions and 13 deletions
37
migrations/versions/d64e5571bc8d_fix_pkgvote_votets.py
Normal file
37
migrations/versions/d64e5571bc8d_fix_pkgvote_votets.py
Normal file
|
@ -0,0 +1,37 @@
|
|||
"""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)
|
Loading…
Add table
Add a link
Reference in a new issue