mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
feat(migrations): add upgrade_voteinfo_integers ref
This migration modifies the Yes, No, Abstain and ActiveTUs columns of the TUVoteInfo table from unsigned TINYINT to unsigned INTEGER. TINYINT supports a total of 1 byte (up to 255 trusted users). This is quite limited and we don't spend too much more by storing a standard 4-byte INTEGER. Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
parent
6e27f62e1b
commit
b5ff8581f3
2 changed files with 53 additions and 4 deletions
|
@ -391,10 +391,10 @@ TU_VoteInfo = Table(
|
|||
if db_backend == "mysql" else String(5),
|
||||
nullable=False),
|
||||
Column('SubmitterID', ForeignKey('Users.ID', ondelete='CASCADE'), nullable=False),
|
||||
Column('Yes', TINYINT(3, unsigned=True), nullable=False, server_default=text("'0'")),
|
||||
Column('No', TINYINT(3, unsigned=True), nullable=False, server_default=text("'0'")),
|
||||
Column('Abstain', TINYINT(3, unsigned=True), nullable=False, server_default=text("'0'")),
|
||||
Column('ActiveTUs', TINYINT(3, unsigned=True), nullable=False, server_default=text("'0'")),
|
||||
Column('Yes', INTEGER(unsigned=True), nullable=False, server_default=text("'0'")),
|
||||
Column('No', INTEGER(unsigned=True), nullable=False, server_default=text("'0'")),
|
||||
Column('Abstain', INTEGER(unsigned=True), nullable=False, server_default=text("'0'")),
|
||||
Column('ActiveTUs', INTEGER(unsigned=True), nullable=False, server_default=text("'0'")),
|
||||
mysql_engine='InnoDB',
|
||||
mysql_charset='utf8mb4',
|
||||
mysql_collate='utf8mb4_general_ci',
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
"""
|
||||
upgrade voteinfo integers
|
||||
|
||||
Within `aurweb/schema.py`, these were previously forced to use
|
||||
TINYINT(3, unsigned=True) types. When generating with dummy data,
|
||||
it is very easy to bypass 3-character TU counts; in addition,
|
||||
this is possible in the future on production, and so we should
|
||||
deal with this case regardless.
|
||||
|
||||
All previous TINYINT(3, unsigned=True) typed columns are upgraded
|
||||
INTEGER(unsigned=True) types, supporting up to 4-bytes of active TUs
|
||||
and votes for one particular proposal.
|
||||
|
||||
Revision ID: be7adae47ac3
|
||||
Revises: 56e2ce8e2ffa
|
||||
Create Date: 2022-01-06 14:37:07.899778
|
||||
"""
|
||||
from alembic import op
|
||||
from sqlalchemy.dialects.mysql import INTEGER, TINYINT
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = 'be7adae47ac3'
|
||||
down_revision = '56e2ce8e2ffa'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
# Upgrade to INTEGER(unsigned=True); supports 4-byte values.
|
||||
UPGRADE_T = INTEGER(unsigned=True)
|
||||
|
||||
# Downgrade to TINYINT(3, unsigned=True); supports 1-byte values.
|
||||
DOWNGRADE_T = TINYINT(3, unsigned=True)
|
||||
|
||||
|
||||
def upgrade():
|
||||
""" Upgrade 'Yes', 'No', 'Abstain' and 'ActiveTUs' to unsigned INTEGER. """
|
||||
op.alter_column("TU_VoteInfo", "Yes", type_=UPGRADE_T)
|
||||
op.alter_column("TU_VoteInfo", "No", type_=UPGRADE_T)
|
||||
op.alter_column("TU_VoteInfo", "Abstain", type_=UPGRADE_T)
|
||||
op.alter_column("TU_VoteInfo", "ActiveTUs", type_=UPGRADE_T)
|
||||
|
||||
|
||||
def downgrade():
|
||||
"""
|
||||
Downgrade 'Yes', 'No', 'Abstain' and 'ActiveTUs' to unsigned TINYINT.
|
||||
"""
|
||||
op.alter_column("TU_VoteInfo", "ActiveTUs", type_=DOWNGRADE_T)
|
||||
op.alter_column("TU_VoteInfo", "Abstain", type_=DOWNGRADE_T)
|
||||
op.alter_column("TU_VoteInfo", "No", type_=DOWNGRADE_T)
|
||||
op.alter_column("TU_VoteInfo", "Yes", type_=DOWNGRADE_T)
|
Loading…
Add table
Reference in a new issue