Example #1
0
def downgrade():
    enum_type = Enum(u'by', u'for', u'of', name='user_artwork_relationship_type')
    enum_type.create(bind=op.get_bind())

    op.add_column('user_artwork',
        Column('relationship_type',
            enum_type,
            primary_key=True,
            nullable=False,
            server_default=op.inline_literal('by')))

    op.execute('ALTER TABLE user_artwork DROP CONSTRAINT user_artwork_pkey')
    op.execute('ALTER TABLE user_artwork ADD PRIMARY KEY (user_id, artwork_id, relationship_type)')

    op.drop_index('ix_user_artwork_user_id')
    op.drop_index('ix_user_artwork_artwork_id')
def upgrade():
    # https://bitbucket.org/zzzeek/alembic/issues/159/opdrop_column-never-ends-with-an-enum
    # This enum is declared explicitly because error occurred when declaring ARRAY(ENUM(.....))
    fallback_mode = Enum('walking', 'car', 'bss', 'bike', name='fallback_mode')
    fallback_mode.create(bind=op.get_bind())

    ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        'traveler_profile',
        sa.Column('coverage_id', sa.Integer(), nullable=False),
        sa.Column('traveler_type',
                  sa.Enum('standard',
                          'slow_walker',
                          'fast_walker',
                          'luggage',
                          'wheelchair',
                          'cyclist',
                          'motorist',
                          name='traveler_type'),
                  nullable=False),
        sa.Column('walking_speed', sa.Float(), nullable=False),
        sa.Column('bike_speed', sa.Float(), nullable=False),
        sa.Column('bss_speed', sa.Float(), nullable=False),
        sa.Column('car_speed', sa.Float(), nullable=False),
        sa.Column('wheelchair', sa.Boolean(), nullable=False),
        sa.Column('max_walking_duration_to_pt', sa.Integer(), nullable=False),
        sa.Column('max_bike_duration_to_pt', sa.Integer(), nullable=False),
        sa.Column('max_bss_duration_to_pt', sa.Integer(), nullable=False),
        sa.Column('max_car_duration_to_pt', sa.Integer(), nullable=False),
        sa.Column('first_section_mode',
                  postgresql.ARRAY(fallback_mode),
                  nullable=False),
        sa.Column('last_section_mode',
                  postgresql.ARRAY(fallback_mode),
                  nullable=False),
        sa.ForeignKeyConstraint(
            ['coverage_id'],
            ['instance.id'],
        ), sa.PrimaryKeyConstraint('coverage_id', 'traveler_type'))