"Fossies" - the Fresh Open Source Software Archive

Member "indico-2.2.5/indico/migrations/versions/20190118_1213_7ec3949a21c7_use_enum_for_resv_occurrence_state.py" (6 Dec 2019, 1832 Bytes) of package /linux/www/indico-2.2.5.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "20190118_1213_7ec3949a21c7_use_enum_for_resv_occurrence_state.py" see the Fossies "Dox" file reference documentation.

    1 """Use enum for resv occurrence state
    2 
    3 Revision ID: 7ec3949a21c7
    4 Revises: 579a36843848
    5 Create Date: 2019-01-18 12:13:42.042274
    6 """
    7 
    8 import sqlalchemy as sa
    9 from alembic import op
   10 
   11 from indico.core.db.sqlalchemy import PyIntEnum
   12 from indico.modules.rb.models.reservation_occurrences import ReservationOccurrenceState
   13 
   14 
   15 # revision identifiers, used by Alembic.
   16 revision = '7ec3949a21c7'
   17 down_revision = '579a36843848'
   18 branch_labels = None
   19 depends_on = None
   20 
   21 
   22 def upgrade():
   23     op.add_column('reservation_occurrences', sa.Column('state', PyIntEnum(ReservationOccurrenceState), nullable=True),
   24                   schema='roombooking')
   25     op.execute('''
   26         UPDATE roombooking.reservation_occurrences
   27         SET state = CASE
   28             WHEN is_rejected THEN 4
   29             WHEN is_cancelled THEN 3
   30             ELSE 2
   31         END
   32     ''')
   33     op.alter_column('reservation_occurrences', 'state', nullable=False, schema='roombooking')
   34     op.drop_column('reservation_occurrences', 'is_cancelled', schema='roombooking')
   35     op.drop_column('reservation_occurrences', 'is_rejected', schema='roombooking')
   36 
   37 
   38 def downgrade():
   39     op.add_column('reservation_occurrences', sa.Column('is_rejected', sa.Boolean(), nullable=True),
   40                   schema='roombooking')
   41     op.add_column('reservation_occurrences', sa.Column('is_cancelled', sa.Boolean(), nullable=True),
   42                   schema='roombooking')
   43     op.execute('''
   44        UPDATE roombooking.reservation_occurrences
   45        SET is_cancelled = (state = 3),
   46            is_rejected = (state = 4)
   47     ''')
   48     op.alter_column('reservation_occurrences', 'is_rejected', nullable=False, schema='roombooking')
   49     op.alter_column('reservation_occurrences', 'is_cancelled', nullable=False, schema='roombooking')
   50     op.drop_column('reservation_occurrences', 'state', schema='roombooking')