removed unused column

This commit is contained in:
mcinj 2022-05-21 13:12:04 -04:00
parent 6a5e679aec
commit 9f2b2e7be2
6 changed files with 133 additions and 5 deletions

View file

@ -0,0 +1,31 @@
"""won column removed
Revision ID: 15c028536ef5
Revises: 1da33402b659
Create Date: 2022-05-21 10:25:41.647723
"""
import sqlalchemy as sa
from alembic import op
# revision identifiers, used by Alembic.
revision = '15c028536ef5'
down_revision = '1da33402b659'
branch_labels = None
depends_on = None
def upgrade():
op.drop_column('giveaway', 'won')
def downgrade():
# add columns as nullable as existing records don't have that column value set
op.add_column('giveaway', sa.Column('won', sa.Boolean(), nullable=True))
# set value on new columns for all records
with op.get_context().autocommit_block():
op.execute("UPDATE giveaway SET won=false WHERE won is null;")
# SQLite doesn't support ALTERs so alembic uses a batch mode
# Set columns to non-nullable now that all records have a value
with op.batch_alter_table('giveaway') as batch_op:
batch_op.alter_column('won', nullable=False)

View file

@ -124,7 +124,6 @@ class GiveawayHelper:
copies=giveaway.copies,
contributor_level=giveaway.contributor_level,
entered=entered,
won=False,
game_entries=giveaway.game_entries)
session.add(g)
session.commit()
@ -147,7 +146,6 @@ class GiveawayHelper:
copies=giveaway.copies,
contributor_level=giveaway.contributor_level,
entered=entered,
won=False,
game_entries=giveaway.game_entries)
session.merge(g)
session.commit()

View file

@ -42,7 +42,6 @@ class TableGiveaway(Base):
copies = Column(Integer(), nullable=False)
contributor_level = Column(Integer(), nullable=False)
entered = Column(Boolean(), nullable=False)
won = Column(Boolean(), nullable=False)
game_entries = Column(Integer(), nullable=False)
created_at = Column(DateTime(timezone=True), server_default=func.now())
updated_at = Column(DateTime(timezone=True), server_default=func.now(), onupdate=func.now())