Skip to content

Commit

Permalink
Merge 8da21bf into 8d62663
Browse files Browse the repository at this point in the history
  • Loading branch information
mvalik authored Jun 5, 2023
2 parents 8d62663 + 8da21bf commit e5bde4c
Showing 1 changed file with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
Create Date: 2018-04-24 16:21:42.017640
"""

# revision identifiers, used by Alembic.
revision = 'f6bc296ba966'
down_revision = 'ce8a1351ecdc'

from alembic import op
from sqlalchemy import Column, Text, Integer, null
# These are the "lightweight" SQL expression versions (not using metadata):
Expand All @@ -19,7 +15,12 @@
from waiverdb.models.waivers import subject_dict_to_type_identifier, \
subject_type_identifier_to_dict

def upgrade():
# revision identifiers, used by Alembic.
revision = 'f6bc296ba966'
down_revision = 'ce8a1351ecdc'


def upgrade() -> None:
# Create the columns NULLable first, so that we can populate them
op.add_column('waiver', Column('subject_identifier', Text, nullable=True))
op.add_column('waiver', Column('subject_type', Text, nullable=True))
Expand All @@ -33,7 +34,7 @@ def upgrade():

# Fill in values for the new columns
connection = op.get_bind()
rows = connection.execute(select([waiver_table.c.id, waiver_table.c.subject]))
rows = connection.execute(select(waiver_table.c.id, waiver_table.c.subject))
for waiver_id, subject in rows:
try:
subject_type, subject_identifier = subject_dict_to_type_identifier(subject)
Expand Down Expand Up @@ -62,7 +63,7 @@ def upgrade():
op.alter_column('waiver', 'subject', nullable=True)


def downgrade():
def downgrade() -> None:
# Lightweight table definition for producing queries:
waiver_table = table('waiver',
column('id', type_=Integer),
Expand All @@ -73,7 +74,7 @@ def downgrade():
# Fill in the old column for any waivers inserted since the upgrade
connection = op.get_bind()
rows = connection.execute(
select([waiver_table.c.id, waiver_table.c.subject_type, waiver_table.c.subject_identifier])
select(waiver_table.c.id, waiver_table.c.subject_type, waiver_table.c.subject_identifier)
.where(waiver_table.c.subject.is_(null())))
for waiver_id, subject_type, subject_identifier in rows:
subject = subject_type_identifier_to_dict(subject_type, subject_identifier)
Expand Down

0 comments on commit e5bde4c

Please sign in to comment.