def upgrade():
    enum = ENUM(u'289',
                u'619',
                u'679',
                u'889',
                u'789',
                u'998',
                u'589',
                u'380',
                u'798',
                u'689',
                u'89',
                u'498',
                u'489',
                u'389',
                u'189',
                u'298',
                name="ck_region",
                create_type=False)
    enum.create(op.get_bind(), checkfirst=False)
    op.create_table(
        'region_percentage', sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('percentage', sa.Integer(), nullable=True),
        sa.Column('region', enum, nullable=False),
        sa.Column('activity_id', sa.Unicode(), nullable=False),
        sa.ForeignKeyConstraint(['activity_id'], ['activity.iati_identifier'],
                                ondelete='CASCADE'),
        sa.PrimaryKeyConstraint('id'))
def downgrade():
    context = op.get_context()

    op.execute(tcr.update().where(tcr.c.directmedia == u'outgoing').values(
        directmedia=None))

    if context.bind.dialect.name != 'postgresql':
        op.alter_column('sippeers',
                        'directmedia',
                        type_=old_type,
                        existing_type=new_type)
    else:
        enum = ENUM("yes",
                    "no",
                    "nonat",
                    "update",
                    name="sip_directmedia_values")
        enum.create(op.get_bind(), checkfirst=False)

        op.execute('ALTER TABLE sippeers ALTER COLUMN directmedia TYPE'
                   ' sip_directmedia_values USING'
                   ' directmedia::text::sip_directmedia_values')

        ENUM(name="sip_directmedia_values_v2").drop(op.get_bind(),
                                                    checkfirst=False)
def upgrade():
    # If we don't do this, Alembic won't create the type automatically
    enum_type = ENUM("yahoo", "google", "kofia", name="asset_value_source")
    enum_type.create(op.get_bind())

    op.add_column("asset_value", sa.Column("source", enum_type,
                                           nullable=False))
def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    enum = ENUM('unverified',
                'valid',
                'rejected',
                name='nu_item_enum',
                create_type=False)
    enum.create(op.get_bind(), checkfirst=True)

    op.execute(
        "ALTER TABLE nu_release_item ALTER COLUMN reviewed DROP DEFAULT")

    op.alter_column(
        'nu_release_item',
        'reviewed',
        existing_type=sa.BOOLEAN(),
        type_=enum,
        existing_nullable=False,
        nullable=False,
        server_default=sa.text("'unverified'"),
        existing_server_default=sa.text('false'),
        postgresql_using=
        "CASE WHEN reviewed = false THEN 'unverified'::nu_item_enum ELSE 'valid'::nu_item_enum END"
    )

    op.execute(
        "ALTER TABLE nu_release_item ALTER COLUMN reviewed SET DEFAULT 'unverified'"
    )
Пример #5
0
def upgrade():
    # If we don't do this, Alembic won't create the type automatically
    enum_type = ENUM('yahoo', 'google', 'kofia', name='asset_value_source')
    enum_type.create(op.get_bind())

    op.add_column('asset_value', sa.Column('source', enum_type,
                                           nullable=False))
def downgrade():
    downvert_data(op)
    op.drop_table('user_preferences')
    op.drop_table('query_policy')

    # Create a temporary type "_resourcetypeenum" type
    temporary_type = ENUM(*OLD_RESOURCE_TYPES, name='resourcetypeenum_temp')
    new_type = ENUM(*NEW_RESOURCE_TYPES, name='resourcetypeenum')
    temporary_type.create(op.get_bind(), checkfirst=True)

    # Convert the name column from old_type to temporary_type
    with op.batch_alter_table('resource_type', schema=None) as batch_op:
        batch_op.alter_column(
            'name',
            existing_type=new_type,
            type_=temporary_type,
            nullable=False,
            postgresql_using='name::text::resourcetypeenum_temp')

    # Drop the old type, create a new enum of type 'resourcetypeenum'
    new_type.drop(op.get_bind(), checkfirst=True)
    old_type = ENUM(*OLD_RESOURCE_TYPES, name='resourcetypeenum')
    old_type.create(op.get_bind(), checkfirst=True)

    # Convert the name column from temporary_type to new_type
    with op.batch_alter_table('resource_type', schema=None) as batch_op:
        batch_op.alter_column('name',
                              existing_type=temporary_type,
                              type_=old_type,
                              nullable=False,
                              postgresql_using='name::text::resourcetypeenum')

    # Drop the temporary type
    temporary_type.drop(op.get_bind(), checkfirst=True)
def upgrade():
    context = op.get_context()

    # Upgrading to this revision WILL clear your directmedia values.
    if context.bind.dialect.name == 'sqlite':
        with op.batch_alter_table('sippeers') as batch_op:
            batch_op.alter_column('directmedia', type_=new_type)
    elif context.bind.dialect.name != 'postgresql':
        op.alter_column('sippeers',
                        'directmedia',
                        type_=new_type,
                        existing_type=old_type)
    else:
        enum = ENUM("yes",
                    "no",
                    "nonat",
                    "update",
                    "outgoing",
                    name="sip_directmedia_values_v2")
        enum.create(op.get_bind(), checkfirst=False)

        op.execute('ALTER TABLE sippeers ALTER COLUMN directmedia TYPE'
                   ' sip_directmedia_values_v2 USING'
                   ' directmedia::text::sip_directmedia_values_v2')

        ENUM(name="sip_directmedia_values").drop(op.get_bind(),
                                                 checkfirst=False)
def upgrade():
    # If we don't do this, Alembic won't create the type automatically
    enum_type = ENUM('yahoo', 'google', 'kofia', name='asset_value_source')
    enum_type.create(op.get_bind())

    op.add_column(
        'asset_value',
        sa.Column('source', enum_type, nullable=False))
def upgrade():
    enum = ENUM(
        u'10', u'15', u'21', u'22', u'23', u'30', u'40', u'60', u'70', u'80',
        name="ck_organisation_type",
        create_type=False
    )
    enum.create(op.get_bind(), checkfirst=False)
    op.add_column('organisation', sa.Column('type', enum, nullable=True))
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    trialoutcome = ENUM(
        "BOTH_SAME", "FIRST_SAME", "SECOND_SAME", "NONE_SAME", name="trialoutcome"
    )
    trialoutcome.create(op.get_bind())
    op.add_column(
        "drug_categorizations", sa.Column("categorization", trialoutcome, nullable=True)
    )
def upgrade():
    ''' Add the column merge_status to the table pull_requests.
    '''
    enum = ENUM('NO_CHANGE', 'FFORWARD', 'CONFLICTS', 'MERGE',
                name='merge_status_enum', create_type=False)
    enum.create(op.get_bind(), checkfirst=False)
    op.add_column(
        'pull_requests',
        sa.Column('merge_status', enum, nullable=True)
    )
Пример #12
0
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    enum = ENUM('plain_text', 'markdown', name='commentreplytype')
    enum.create(op.get_bind(), checkfirst=True)
    op.add_column(
        'comment_reply',
        sa.Column('reply_type',
                  enum,
                  server_default='plain_text',
                  nullable=False))
def upgrade():
    context = op.get_context()

    if context.bind.dialect.name == 'postgresql':
        enum = ENUM(*SHA_HASH_VALUES, name=SHA_HASH_NAME)
        enum.create(op.get_bind(), checkfirst=False)

    op.add_column('ps_endpoints',
             sa.Column('dtls_fingerprint', ENUM(*SHA_HASH_VALUES,
                 name=SHA_HASH_NAME, create_type=False)))
def upgrade():
    # Create a temporary type "_resourcetypeenum" type
    temporary_type = ENUM(*NEW_RESOURCE_TYPES, name='resourcetypeenum_temp')
    old_type = ENUM(*OLD_RESOURCE_TYPES, name='resourcetypeenum')
    temporary_type.create(op.get_bind(), checkfirst=True)

    # Convert the name column from old_type to temporary_type
    with op.batch_alter_table('resource_type', schema=None) as batch_op:
        batch_op.alter_column(
            'name',
            existing_type=old_type,
            type_=temporary_type,
            nullable=False,
            postgresql_using='name::text::resourcetypeenum_temp')

    # Drop the old type, create a new enum of type 'resourcetypeenum'
    old_type.drop(op.get_bind(), checkfirst=True)
    new_type = ENUM(*NEW_RESOURCE_TYPES, name='resourcetypeenum')
    new_type.create(op.get_bind(), checkfirst=True)

    # Convert the name column from temporary_type to new_type
    with op.batch_alter_table('resource_type', schema=None) as batch_op:
        batch_op.alter_column('name',
                              existing_type=temporary_type,
                              type_=new_type,
                              nullable=False,
                              postgresql_using='name::text::resourcetypeenum')

    # Drop the temporary type
    temporary_type.drop(op.get_bind(), checkfirst=True)

    op.create_table(
        'query_policy', sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('name', sa.String(), nullable=False),
        sa.Column('description', sa.Text(), nullable=True),
        sa.Column('policy_filters',
                  postgresql.JSONB(astext_type=sa.Text()),
                  nullable=False),
        sa.Column('resource_id', sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(['resource_id'], ['resource.id'],
                                name='valid_query_definition_resource',
                                ondelete='CASCADE'),
        sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('name'),
        sa.UniqueConstraint('resource_id'))
    op.create_table(
        'user_preferences', sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('user_id', sa.Integer(), nullable=False),
        sa.Column('preferences',
                  postgresql.JSONB(astext_type=sa.Text()),
                  nullable=False),
        sa.ForeignKeyConstraint(['user_id'], ['user.id'],
                                name='valid_user',
                                ondelete='CASCADE'),
        sa.PrimaryKeyConstraint('id'))
    upvert_data(op)
def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    gender_column = sa.Column(
        'gender', sa.Enum('male', 'female', 'unspecified'))
    if DATABASE_URL[:8] == 'postgres':
        gender_enum = ENUM(
            'male', 'female', 'unspecified', name='alert_gender')
        gender_enum.create(op.get_bind(), checkfirst=False)
        gender_column = sa.Column('gender', gender_enum)
    op.add_column('alerts', sa.Column('age', sa.Integer()))
    op.add_column('alerts', gender_column)
def upgrade():
    context = op.get_context()

    if context.bind.dialect.name == 'postgresql':
        enum = ENUM(*PJSIP_TASKPROCESSOR_OVERLOAD_TRIGGER_VALUES,
                    name=PJSIP_TASKPROCESSOR_OVERLOAD_TRIGGER_NAME)
        enum.create(op.get_bind(), checkfirst=False)

    op.add_column('ps_globals',
        sa.Column('taskprocessor_overload_trigger',
            sa.Enum(*PJSIP_TASKPROCESSOR_OVERLOAD_TRIGGER_VALUES,
            name=PJSIP_TASKPROCESSOR_OVERLOAD_TRIGGER_NAME)))
def upgrade():
    # Create the new enum
    ast_bool_values = ENUM(*AST_BOOL_VALUES, name=AST_BOOL_NAME, create_type=False)
    if op.get_context().bind.dialect.name == 'postgresql':
        ast_bool_values.create(op.get_bind(), checkfirst=False)

    # There is no direct way to convert from Integer to ENUM that is
    # not database specific so we transition through a string type.
    op.alter_column('ps_endpoints', 'mwi_subscribe_replaces_unsolicited',
                    type_=sa.String(5))
    op.alter_column('ps_endpoints', 'mwi_subscribe_replaces_unsolicited',
            type_=ast_bool_values, postgresql_using='mwi_subscribe_replaces_unsolicited::{0}'.format(AST_BOOL_NAME))
Пример #18
0
def upgrade():
    ''' Add the column merge_status to the table pull_requests.
    '''
    enum = ENUM('NO_CHANGE',
                'FFORWARD',
                'CONFLICTS',
                'MERGE',
                name='merge_status_enum',
                create_type=False)
    enum.create(op.get_bind(), checkfirst=False)
    op.add_column('pull_requests',
                  sa.Column('merge_status', enum, nullable=True))
def upgrade():
    # Create the new enum
    ast_bool_values = ENUM(*AST_BOOL_VALUES, name=AST_BOOL_NAME, create_type=False)
    if op.get_context().bind.dialect.name == 'postgresql':
        ast_bool_values.create(op.get_bind(), checkfirst=False)

    # There is no direct way to convert from Integer to ENUM that is
    # not database specific so we transition through a string type.
    op.alter_column('ps_endpoints', 'mwi_subscribe_replaces_unsolicited',
                    type_=sa.String(5))
    op.alter_column('ps_endpoints', 'mwi_subscribe_replaces_unsolicited',
                    type_=ast_bool_values)
Пример #20
0
def upgrade():
    context = op.get_context()

    if context.bind.dialect.name == 'postgresql':
        enum = ENUM(*SHA_HASH_VALUES, name=SHA_HASH_NAME)
        enum.create(op.get_bind(), checkfirst=False)

    op.add_column(
        'ps_endpoints',
        sa.Column(
            'dtls_fingerprint',
            ENUM(*SHA_HASH_VALUES, name=SHA_HASH_NAME, create_type=False)))
Пример #21
0
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    enum = ENUM("unknown",
                "incoming_text",
                "incoming_call",
                "outgoing_call",
                name='contact_types')
    enum.create(op.get_bind(), checkfirst=False)
    op.add_column(
        'calls',
        sa.Column('contact_type', sa.Enum(name='contact_types'),
                  nullable=True))
Пример #22
0
def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    gender_column = sa.Column('gender', sa.Enum('male', 'female',
                                                'unspecified'))
    if DATABASE_URL[:8] == 'postgres':
        gender_enum = ENUM('male',
                           'female',
                           'unspecified',
                           name='alert_gender')
        gender_enum.create(op.get_bind(), checkfirst=False)
        gender_column = sa.Column('gender', gender_enum)
    op.add_column('alerts', sa.Column('age', sa.Integer()))
    op.add_column('alerts', gender_column)
Пример #23
0
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    enum = ENUM('visible', 'archived', 'deleted', name='coursestate')
    enum.create(op.get_bind(), checkfirst=True)
    op.add_column(
        'Course',
        sa.Column('state', enum, server_default='visible', nullable=False))
    op.add_column(
        'Course',
        sa.Column('updated_at',
                  sa.TIMESTAMP(timezone=True),
                  nullable=False,
                  server_default='NOW()'))
Пример #24
0
def upgrade():
    role_column = sa.Column('role',
                            sa.Enum('admin', 'advocate', 'provider'),
                            nullable=True)
    if DATABASE_URL[:8] == 'postgres':
        role_enum = ENUM('admin',
                         'advocate',
                         'provider',
                         name='pgenum',
                         create_type=False)
        role_enum.create(op.get_bind(), checkfirst=False)
        role_column = sa.Column('role', role_enum)
    ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        'users', sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('created_at', sa.DateTime(), nullable=True),
        sa.Column('updated', sa.DateTime(), nullable=True),
        sa.Column('email', sa.String(length=255), nullable=False),
        sa.Column('password', sa.Text(), nullable=False),
        sa.Column('phone_number', sa.String(length=20), nullable=False),
        sa.Column('shelter', sa.Boolean(), nullable=True),
        sa.Column('clothes', sa.Boolean(), nullable=True),
        sa.Column('food', sa.Boolean(), nullable=True),
        sa.Column('other', sa.Boolean(), nullable=True), role_column,
        sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('email'))
    op.create_table(
        'alerts', sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('created_at', sa.DateTime(), nullable=True),
        sa.Column('description', sa.String(length=200), nullable=False),
        sa.Column('shelter', sa.Boolean(), nullable=False),
        sa.Column('clothes', sa.Boolean(), nullable=False),
        sa.Column('food', sa.Boolean(), nullable=False),
        sa.Column('other', sa.Boolean(), nullable=False),
        sa.Column('user_id', sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(
            ['user_id'],
            ['users.id'],
        ), sa.PrimaryKeyConstraint('id'))
    op.create_table('responses', sa.Column('id', sa.Integer(), nullable=False),
                    sa.Column('user_id', sa.Integer(), nullable=True),
                    sa.Column('created_at', sa.DateTime(), nullable=True),
                    sa.Column('alert_id', sa.Integer(), nullable=True),
                    sa.Column('message', sa.Text(), nullable=True),
                    sa.ForeignKeyConstraint(
                        ['alert_id'],
                        ['alerts.id'],
                    ), sa.ForeignKeyConstraint(
                        ['user_id'],
                        ['users.id'],
                    ), sa.PrimaryKeyConstraint('id'))
Пример #25
0
def upgrade():
    context = op.get_context()

    if context.bind.dialect.name == 'postgresql':
        enum = ENUM(*PJSIP_TASKPROCESSOR_OVERLOAD_TRIGGER_VALUES,
                    name=PJSIP_TASKPROCESSOR_OVERLOAD_TRIGGER_NAME)
        enum.create(op.get_bind(), checkfirst=False)

    op.add_column(
        'ps_globals',
        sa.Column(
            'taskprocessor_overload_trigger',
            sa.Enum(*PJSIP_TASKPROCESSOR_OVERLOAD_TRIGGER_VALUES,
                    name=PJSIP_TASKPROCESSOR_OVERLOAD_TRIGGER_NAME)))
Пример #26
0
def upgrade():
    enum = ENUM(u'10',
                u'15',
                u'21',
                u'22',
                u'23',
                u'30',
                u'40',
                u'60',
                u'70',
                u'80',
                name="ck_organisation_type",
                create_type=False)
    enum.create(op.get_bind(), checkfirst=False)
    op.add_column('organisation', sa.Column('type', enum, nullable=True))
Пример #27
0
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    authenticationtype = ENUM('email',
                              'facebook',
                              'google',
                              name='authenticationtype')
    authenticationtype.create(op.get_bind())

    op.add_column(
        'User',
        sa.Column('authentication_type',
                  ENUM('email',
                       'facebook',
                       'google',
                       name='authenticationtype'),
                  nullable=True))
def upgrade():
    package_type = ENUM(
        "bdist_dmg", "bdist_dumb", "bdist_egg", "bdist_msi", "bdist_rpm",
        "bdist_wheel", "bdist_wininst", "sdist",
        name="package_type",
        create_type=False,
    )
    package_type.create(op.get_bind(), checkfirst=False)

    op.execute(
        """ ALTER TABLE release_files
                ALTER COLUMN packagetype
                TYPE package_type
                USING packagetype::package_type
        """
    )
def upgrade():
    enum = ENUM(
        u'289', u'619', u'679', u'889', u'789', u'998', u'589', u'380', u'798', u'689', u'89', u'498', u'489', u'389', u'189', u'298',
        name="ck_region",
        create_type=False
    )
    enum.create(op.get_bind(), checkfirst=False)
    op.create_table(
        'region_percentage',
        sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('percentage', sa.Integer(), nullable=True),
        sa.Column('region', enum, nullable=False),
        sa.Column('activity_id', sa.Unicode(), nullable=False),
        sa.ForeignKeyConstraint(['activity_id'], ['activity.iati_identifier'], ondelete='CASCADE'),
        sa.PrimaryKeyConstraint('id')
    )
def upgrade():
    context = op.get_context()

    # Upgrading to this revision WILL clear your directmedia values.
    if context.bind.dialect.name != "postgresql":
        op.alter_column("sippeers", "directmedia", type_=new_type, existing_type=old_type)
    else:
        enum = ENUM("yes", "no", "nonat", "update", "outgoing", name="sip_directmedia_values_v2")
        enum.create(op.get_bind(), checkfirst=False)

        op.execute(
            "ALTER TABLE sippeers ALTER COLUMN directmedia TYPE"
            " sip_directmedia_values_v2 USING"
            " directmedia::text::sip_directmedia_values_v2"
        )

        ENUM(name="sip_directmedia_values").drop(op.get_bind(), checkfirst=False)
def downgrade():
    context = op.get_context()

    if context.bind.dialect.name != 'postgresql':
        op.alter_column('ps_endpoints', 'dtmf_mode',
                        type_=old_type,
                        existing_type=new_type)
    else:
        enum = ENUM('rfc4733', 'inband', 'info',
                    name='pjsip_dtmf_mode_values')
        enum.create(op.get_bind(), checkfirst=False)

        op.execute('ALTER TABLE ps_endpoints ALTER COLUMN dtmf_mode TYPE'
                   ' pjsip_dtmf_mode_values USING'
                   ' dtmf_mode::text::pjsip_dtmf_mode_values')

        ENUM(name="pjsip_dtmf_mode_values_v2").drop(op.get_bind(), checkfirst=False)
Пример #32
0
def downgrade():
    context = op.get_context()

    if context.bind.dialect.name != 'postgresql':
        op.alter_column('ps_endpoints', 'dtmf_mode',
                        type_=old_type,
                        existing_type=new_type)
    else:
        enum = ENUM('rfc4733', 'inband', 'info', 'auto',
                    name='pjsip_dtmf_mode_values_v2')
        enum.create(op.get_bind(), checkfirst=False)

        op.execute('ALTER TABLE ps_endpoints ALTER COLUMN dtmf_mode TYPE'
                   ' pjsip_dtmf_mode_values_v2 USING'
                   ' dtmf_mode::text::pjsip_dtmf_mode_values_v2')

        ENUM(name="pjsip_dtmf_mode_values_v3").drop(op.get_bind(), checkfirst=False)
def upgrade():
    # Create a temporary type "_resourcetypeenum" type
    temporary_type = ENUM(*NEW_RESOURCE_TYPES, name='resourcetypeenum_temp')
    old_type = ENUM(*OLD_RESOURCE_TYPES, name='resourcetypeenum')
    temporary_type.create(op.get_bind(), checkfirst=True)

    # Convert the name column from old_type to temporary_type
    with op.batch_alter_table('resource_type', schema=None) as batch_op:
        batch_op.alter_column(
            'name',
            existing_type=old_type,
            type_=temporary_type,
            nullable=False,
            postgresql_using='name::text::resourcetypeenum_temp')

    # Drop the old type, create a new enum of type 'resourcetypeenum'
    old_type.drop(op.get_bind(), checkfirst=True)
    new_type = ENUM(*NEW_RESOURCE_TYPES, name='resource_type_enum')
    new_type.create(op.get_bind(), checkfirst=True)

   # Convert the name column from temporary_type to new_type
    with op.batch_alter_table('resource_type', schema=None) as batch_op:
        batch_op.alter_column(
            'name',
            existing_type=temporary_type,
            type_=new_type,
            nullable=False,
            postgresql_using='name::text::resource_type_enum')

    # Drop the temporary type
    temporary_type.drop(op.get_bind(), checkfirst=True)

    with op.batch_alter_table('alert_definitions', schema=None) as batch_op:
        batch_op.add_column(
            sa.Column('authorization_resource_id', sa.Integer(), nullable=True))
        batch_op.create_unique_constraint('unique_alert_resource', [
                                          'authorization_resource_id'])
        batch_op.create_foreign_key('valid_alert_resource', 'resource', [
                                    'authorization_resource_id'], ['id'], ondelete='CASCADE')

    upvert_data(op)

    with op.batch_alter_table('alert_definitions', schema=None) as batch_op:
        batch_op.alter_column(
            sa.Column('authorization_resource_id', sa.Integer(), nullable=False))
def upgrade():
    context = op.get_context()

    # Upgrading to this revision WILL clear your directmedia values.
    if context.bind.dialect.name != 'postgresql':
        op.alter_column('ps_endpoints', 'dtmf_mode',
                        type_=new_type,
                        existing_type=old_type)
    else:
        enum = ENUM('rfc4733', 'inband', 'info', 'auto',
                    name='pjsip_dtmf_mode_values_v2')
        enum.create(op.get_bind(), checkfirst=False)

        op.execute('ALTER TABLE ps_endpoints ALTER COLUMN dtmf_mode TYPE'
                   ' pjsip_dtmf_mode_values_v2 USING'
                   ' dtmf_mode::text::pjsip_dtmf_mode_values_v2')

        ENUM(name="pjsip_dtmf_mode_values").drop(op.get_bind(), checkfirst=False)
def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    enum = ENUM('unverified', 'valid', 'rejected',          name='nu_item_enum', create_type=False)
    enum.create(op.get_bind(), checkfirst=True)

    op.execute("ALTER TABLE nu_release_item ALTER COLUMN reviewed DROP DEFAULT")

    op.alter_column('nu_release_item', 'reviewed',
               existing_type=sa.BOOLEAN(),
               type_=enum,
               existing_nullable=False,
               nullable=False,
               server_default=sa.text("'unverified'"),
               existing_server_default=sa.text('false'),
               postgresql_using="CASE WHEN reviewed = false THEN 'unverified'::nu_item_enum ELSE 'valid'::nu_item_enum END"
               )

    op.execute("ALTER TABLE nu_release_item ALTER COLUMN reviewed SET DEFAULT 'unverified'")
def downgrade():
    context = op.get_context()

    op.execute(tcr.update().where(tcr.c.directmedia == u"outgoing").values(directmedia=None))

    if context.bind.dialect.name != "postgresql":
        op.alter_column("sippeers", "directmedia", type_=old_type, existing_type=new_type)
    else:
        enum = ENUM("yes", "no", "nonat", "update", name="sip_directmedia_values")
        enum.create(op.get_bind(), checkfirst=False)

        op.execute(
            "ALTER TABLE sippeers ALTER COLUMN directmedia TYPE"
            " sip_directmedia_values USING"
            " directmedia::text::sip_directmedia_values"
        )

        ENUM(name="sip_directmedia_values_v2").drop(op.get_bind(), checkfirst=False)
Пример #37
0
def upgrade():
    context = op.get_context()

    # Upgrading to this revision WILL clear your directmedia values.
    if context.bind.dialect.name != 'postgresql':
        op.alter_column('ps_endpoints', 'dtmf_mode',
                        type_=new_type,
                        existing_type=old_type)
    else:
        enum = ENUM('rfc4733', 'inband', 'info', 'auto', 'auto_info',
                    name='pjsip_dtmf_mode_values_v3')
        enum.create(op.get_bind(), checkfirst=False)

        op.execute('ALTER TABLE ps_endpoints ALTER COLUMN dtmf_mode TYPE'
                   ' pjsip_dtmf_mode_values_v3 USING'
                   ' dtmf_mode::text::pjsip_dtmf_mode_values_v3')

        ENUM(name="pjsip_dtmf_mode_values_v2").drop(op.get_bind(), checkfirst=False)
Пример #38
0
def upgrade():
    package_type = ENUM(
        "bdist_dmg",
        "bdist_dumb",
        "bdist_egg",
        "bdist_msi",
        "bdist_rpm",
        "bdist_wheel",
        "bdist_wininst",
        "sdist",
        name="package_type",
        create_type=False,
    )
    package_type.create(op.get_bind(), checkfirst=False)

    op.execute(""" ALTER TABLE release_files
                ALTER COLUMN packagetype
                TYPE package_type
                USING packagetype::package_type
        """)
def upgrade():
    context = op.get_context()

    # Upgrading to this revision WILL clear your directmedia values.
    if context.bind.dialect.name == 'sqlite':
        with op.batch_alter_table('sippeers') as batch_op:
            batch_op.alter_column('directmedia', type_=new_type)
    elif context.bind.dialect.name != 'postgresql':
        op.alter_column('sippeers', 'directmedia',
                        type_=new_type,
                        existing_type=old_type)
    else:
        enum = ENUM("yes", "no", "nonat", "update", "outgoing",
                    name="sip_directmedia_values_v2")
        enum.create(op.get_bind(), checkfirst=False)

        op.execute('ALTER TABLE sippeers ALTER COLUMN directmedia TYPE'
                   ' sip_directmedia_values_v2 USING'
                   ' directmedia::text::sip_directmedia_values_v2')

        ENUM(name="sip_directmedia_values").drop(op.get_bind(), checkfirst=False)
Пример #40
0
def upgrade():
    footprint_type = ENUM(FootprintType, create_type=False, name='footprinttype')
    footprint_type.create(op.get_bind(), checkfirst=True)

    category = op.create_table(
        'category',
        sa.Column('id', sa.BigInteger, primary_key=True, autoincrement=True),
        sa.Column('label', sa.String(80), nullable=False),
        sa.Column('type', footprint_type, nullable=False),
        sa.Column('date_created', sa.DateTime, nullable=False, default=datetime.utcnow),
    )

    op.create_table(
        'footprint_category',
        sa.Column('id', sa.BigInteger, primary_key=True, autoincrement=True),
        sa.Column('category_id', sa.Integer, ForeignKey('category.id'), nullable=False),
        sa.Column('footprint_id', sa.Integer, ForeignKey('footprint.id'), nullable=False),
    )

    question_category = op.create_table(
        'question_category',
        sa.Column('id', sa.BigInteger, primary_key=True, autoincrement=True),
        sa.Column('category_id', sa.Integer, ForeignKey('category.id'), nullable=False),
        sa.Column('question_id', sa.Integer, ForeignKey('question.id'), nullable=False),
    )

    op.create_table(
        'recommendation_category',
        sa.Column('id', sa.BigInteger, primary_key=True, autoincrement=True),
        sa.Column('category_id', sa.Integer, ForeignKey('category.id'), nullable=False),
        sa.Column('recommendation_id', sa.Integer, ForeignKey('recommendation.id'), nullable=False),
    )

    question = table(
        'question',
        sa.Column('id', sa.BigInteger, primary_key=True, autoincrement=True),
        sa.Column('question_name', sa.String(80), nullable=False),
        sa.Column('display_text', footprint_type, nullable=False),
        sa.Column('date_created', sa.DateTime, nullable=False, default=datetime.utcnow),
     )
def downgrade():

    provider_enum = ENUM("loadtesting", "firetext", "mmg", "ses", "twilio", name="providers", create_type=True)
    provider_enum.create(op.get_bind(), checkfirst=False)

    op.add_column("provider_statistics", sa.Column("provider", provider_enum, autoincrement=False, nullable=True))
    op.alter_column("provider_statistics", "provider_id", existing_type=postgresql.UUID(), nullable=True)
    op.add_column("provider_rates", sa.Column("provider", provider_enum, autoincrement=False, nullable=True))
    op.alter_column("provider_rates", "provider_id", existing_type=postgresql.UUID(), nullable=True)

    op.execute(
        "UPDATE provider_rates set provider = 'mmg' where provider_id = (select id from provider_details where identifier = 'mmg')"
    )
    op.execute(
        "UPDATE provider_rates set provider = 'firetext' where provider_id = (select id from provider_details where identifier = 'firetext')"
    )
    op.execute(
        "UPDATE provider_rates set provider = 'ses' where provider_id = (select id from provider_details where identifier = 'ses')"
    )
    op.execute(
        "UPDATE provider_rates set provider = 'loadtesting' where provider_id = (select id from provider_details where identifier = 'loadtesting')"
    )

    op.execute(
        "UPDATE provider_statistics set provider = 'mmg' where provider_id = (select id from provider_details where identifier = 'mmg')"
    )
    op.execute(
        "UPDATE provider_statistics set provider = 'firetext' where provider_id = (select id from provider_details where identifier = 'firetext')"
    )
    op.execute(
        "UPDATE provider_statistics set provider = 'ses' where provider_id = (select id from provider_details where identifier = 'ses')"
    )
    op.execute(
        "UPDATE provider_statistics set provider = 'loadtesting' where provider_id = (select id from provider_details where identifier = 'loadtesting')"
    )

    op.alter_column("provider_rates", "provider", existing_type=postgresql.UUID(), nullable=False)

    op.alter_column("provider_statistics", "provider", existing_type=postgresql.UUID(), nullable=False)
def upgrade():
    # Managing fallback_mode enum as tested in alembic's repo:
    # https://github.com/sqlalchemy/alembic/blob/7257a5b306385318f19d5d16d2196371bb637d66/tests/test_postgresql.py#L328-L333
    fallback_mode = ENUM('walking', 'car', 'bss', 'bike', name='fallback_mode', create_type=False)
    fallback_mode.create(bind=op.get_bind(), checkfirst=False)

    ### 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', ARRAY(fallback_mode), nullable=False),
        sa.Column('last_section_mode', ARRAY(fallback_mode), nullable=False),
        sa.ForeignKeyConstraint(['coverage_id'], ['instance.id']),
        sa.PrimaryKeyConstraint('coverage_id', 'traveler_type'),
    )
def downgrade():
    with op.batch_alter_table('alert_definitions', schema=None) as batch_op:
        batch_op.drop_constraint('valid_alert_resource', type_='foreignkey')
        batch_op.drop_constraint('unique_alert_resource', type_='unique')
        batch_op.drop_column('authorization_resource_id')

    downvert_data(op)

    # Create a temporary type "_resourcetypeenum" type
    temporary_type = ENUM(*OLD_RESOURCE_TYPES, name='resourcetypeenum_temp')
    new_type = ENUM(*NEW_RESOURCE_TYPES, name='resource_type_enum')
    temporary_type.create(op.get_bind(), checkfirst=True)

    # Convert the name column from old_type to temporary_type
    with op.batch_alter_table('resource_type', schema=None) as batch_op:
        batch_op.alter_column(
            'name',
            existing_type=new_type,
            type_=temporary_type,
            nullable=False,
            postgresql_using='name::text::resourcetypeenum_temp')

    # Drop the old type, create a new enum of type 'resourcetypeenum'
    new_type.drop(op.get_bind(), checkfirst=True)
    old_type = ENUM(*OLD_RESOURCE_TYPES, name='resourcetypeenum')
    old_type.create(op.get_bind(), checkfirst=True)

   # Convert the name column from temporary_type to new_type
    with op.batch_alter_table('resource_type', schema=None) as batch_op:
        batch_op.alter_column(
            'name',
            existing_type=temporary_type,
            type_=old_type,
            nullable=False,
            postgresql_using='name::text::resourcetypeenum')

    # Drop the temporary type
    temporary_type.drop(op.get_bind(), checkfirst=True)
Пример #44
0
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    enum = ENUM('Canvas',
                'Blackboard',
                'Sakai',
                'Open edX',
                'Moodle',
                'BrightSpace',
                name='lti1p1lmsnames')
    enum.create(op.get_bind(), checkfirst=True)
    op.add_column('LTIProvider', sa.Column('lms_1p1_name', enum,
                                           nullable=True))
    op.add_column(
        'LTIProvider',
        sa.Column('lms_1p1_secret', ARRAY(sa.Unicode()), nullable=True))
    bind = op.get_bind()
    for key, (
            lms,
            secrets) in current_app.config['LTI_CONSUMER_KEY_SECRETS'].items():
        res = bind.execute(
            text("""
        UPDATE "LTIProvider" SET lms_1p1_name = :lms, lms_1p1_secret = :secrets
        WHERE key = :key AND lti_provider_version = 'lti1.1'
        """),
            key=key,
            lms=lms,
            secrets=secrets,
        )
        if res.rowcount == 0:
            bind.execute(
                text("""
                INSERT INTO "LTIProvider" (id, lms_1p1_name, lms_1p1_secret, key, lti_provider_version)
                VALUES (uuid_generate_v4(), :lms, :secrets, :key, 'lti1.1')
        """),
                key=key,
                lms=lms,
                secrets=secrets,
            )
def downgrade():
    context = op.get_context()

    op.execute(tcr.update().where(tcr.c.directmedia==u'outgoing')
               .values(directmedia=None))

    if context.bind.dialect.name == 'sqlite':
        with op.batch_alter_table('sippeers') as batch_op:
            batch_op.alter_column('directmedia', type_=old_type)
    elif context.bind.dialect.name != 'postgresql':
        op.alter_column('sippeers', 'directmedia',
                        type_=old_type,
                        existing_type=new_type)
    else:
        enum = ENUM("yes", "no", "nonat", "update",
                    name="sip_directmedia_values")
        enum.create(op.get_bind(), checkfirst=False)

        op.execute('ALTER TABLE sippeers ALTER COLUMN directmedia TYPE'
                   ' sip_directmedia_values USING'
                   ' directmedia::text::sip_directmedia_values')

        ENUM(name="sip_directmedia_values_v2").drop(op.get_bind(),
                                                checkfirst=False)
Пример #46
0
def upgrade():
    # alembic cannot handle enum for now
    enum = ENUM("free",
                "trial",
                "monthly",
                "yearly",
                name="plan_enum",
                create_type=False)
    enum.create(op.get_bind(), checkfirst=False)

    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        'file',
        sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
        sa.Column('created_at',
                  sqlalchemy_utils.types.arrow.ArrowType(),
                  nullable=False),
        sa.Column('updated_at',
                  sqlalchemy_utils.types.arrow.ArrowType(),
                  nullable=True),
        sa.Column('path', sa.String(length=128), nullable=False),
        sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('path'))
    op.create_table(
        'scope',
        sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
        sa.Column('created_at',
                  sqlalchemy_utils.types.arrow.ArrowType(),
                  nullable=False),
        sa.Column('updated_at',
                  sqlalchemy_utils.types.arrow.ArrowType(),
                  nullable=True),
        sa.Column('name', sa.String(length=128), nullable=False),
        sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('name'))
    op.create_table(
        'users',
        sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
        sa.Column('created_at',
                  sqlalchemy_utils.types.arrow.ArrowType(),
                  nullable=False),
        sa.Column('updated_at',
                  sqlalchemy_utils.types.arrow.ArrowType(),
                  nullable=True),
        sa.Column('email', sa.String(length=128), nullable=False),
        sa.Column('salt', sa.String(length=128), nullable=False),
        sa.Column('password', sa.String(length=128), nullable=False),
        sa.Column('name', sa.String(length=128), nullable=False),
        sa.Column('is_admin', sa.Boolean(), nullable=False),
        sa.Column('activated', sa.Boolean(), nullable=False),
        sa.Column('plan', enum, server_default='free', nullable=False),
        sa.Column('trial_expiration',
                  sqlalchemy_utils.types.arrow.ArrowType(),
                  nullable=True),
        sa.Column('stripe_customer_id', sa.String(length=128), nullable=True),
        sa.Column('stripe_card_token', sa.String(length=128), nullable=True),
        sa.Column('stripe_subscription_id',
                  sa.String(length=128),
                  nullable=True), sa.PrimaryKeyConstraint('id'),
        sa.UniqueConstraint('email'), sa.UniqueConstraint('stripe_card_token'),
        sa.UniqueConstraint('stripe_customer_id'),
        sa.UniqueConstraint('stripe_subscription_id'))
    op.create_table(
        'activation_code',
        sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
        sa.Column('created_at',
                  sqlalchemy_utils.types.arrow.ArrowType(),
                  nullable=False),
        sa.Column('updated_at',
                  sqlalchemy_utils.types.arrow.ArrowType(),
                  nullable=True),
        sa.Column('user_id', sa.Integer(), nullable=False),
        sa.Column('code', sa.String(length=128), nullable=False),
        sa.ForeignKeyConstraint(['user_id'], ['users.id'], ondelete='cascade'),
        sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('code'))
    op.create_table(
        'client',
        sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
        sa.Column('created_at',
                  sqlalchemy_utils.types.arrow.ArrowType(),
                  nullable=False),
        sa.Column('updated_at',
                  sqlalchemy_utils.types.arrow.ArrowType(),
                  nullable=True),
        sa.Column('oauth_client_id', sa.String(length=128), nullable=False),
        sa.Column('oauth_client_secret', sa.String(length=128),
                  nullable=False),
        sa.Column('name', sa.String(length=128), nullable=False),
        sa.Column('home_url', sa.String(length=1024), nullable=True),
        sa.Column('published', sa.Boolean(), nullable=False),
        sa.Column('user_id', sa.Integer(), nullable=False),
        sa.Column('icon_id', sa.Integer(), nullable=True),
        sa.ForeignKeyConstraint(
            ['icon_id'],
            ['file.id'],
        ),
        sa.ForeignKeyConstraint(['user_id'], ['users.id'], ondelete='cascade'),
        sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('oauth_client_id'))
    op.create_table(
        'gen_email',
        sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
        sa.Column('created_at',
                  sqlalchemy_utils.types.arrow.ArrowType(),
                  nullable=False),
        sa.Column('updated_at',
                  sqlalchemy_utils.types.arrow.ArrowType(),
                  nullable=True),
        sa.Column('user_id', sa.Integer(), nullable=False),
        sa.Column('email', sa.String(length=128), nullable=False),
        sa.Column('enabled', sa.Boolean(), nullable=False),
        sa.ForeignKeyConstraint(['user_id'], ['users.id'], ondelete='cascade'),
        sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('email'))
    op.create_table(
        'authorization_code',
        sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
        sa.Column('created_at',
                  sqlalchemy_utils.types.arrow.ArrowType(),
                  nullable=False),
        sa.Column('updated_at',
                  sqlalchemy_utils.types.arrow.ArrowType(),
                  nullable=True),
        sa.Column('code', sa.String(length=128), nullable=False),
        sa.Column('client_id', sa.Integer(), nullable=False),
        sa.Column('user_id', sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(['client_id'], ['client.id'],
                                ondelete='cascade'),
        sa.ForeignKeyConstraint(['user_id'], ['users.id'], ondelete='cascade'),
        sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('code'))
    op.create_table(
        'client_scope', sa.Column('client_id', sa.Integer(), nullable=False),
        sa.Column('scope_id', sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(['client_id'], ['client.id'],
                                ondelete='cascade'),
        sa.ForeignKeyConstraint(['scope_id'], ['scope.id'],
                                ondelete='cascade'),
        sa.PrimaryKeyConstraint('client_id', 'scope_id'))
    op.create_table(
        'client_user',
        sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
        sa.Column('created_at',
                  sqlalchemy_utils.types.arrow.ArrowType(),
                  nullable=False),
        sa.Column('updated_at',
                  sqlalchemy_utils.types.arrow.ArrowType(),
                  nullable=True),
        sa.Column('user_id', sa.Integer(), nullable=False),
        sa.Column('client_id', sa.Integer(), nullable=False),
        sa.Column('gen_email_id', sa.Integer(), nullable=True),
        sa.ForeignKeyConstraint(['client_id'], ['client.id'],
                                ondelete='cascade'),
        sa.ForeignKeyConstraint(['gen_email_id'], ['gen_email.id'],
                                ondelete='cascade'),
        sa.ForeignKeyConstraint(['user_id'], ['users.id'], ondelete='cascade'),
        sa.PrimaryKeyConstraint('id'),
        sa.UniqueConstraint('user_id', 'client_id', name='uq_client_user'))
    op.create_table(
        'oauth_token',
        sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
        sa.Column('created_at',
                  sqlalchemy_utils.types.arrow.ArrowType(),
                  nullable=False),
        sa.Column('updated_at',
                  sqlalchemy_utils.types.arrow.ArrowType(),
                  nullable=True),
        sa.Column('access_token', sa.String(length=128), nullable=True),
        sa.Column('client_id', sa.Integer(), nullable=False),
        sa.Column('user_id', sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(['client_id'], ['client.id'],
                                ondelete='cascade'),
        sa.ForeignKeyConstraint(['user_id'], ['users.id'], ondelete='cascade'),
        sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('access_token'))
    op.create_table(
        'redirect_uri',
        sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
        sa.Column('created_at',
                  sqlalchemy_utils.types.arrow.ArrowType(),
                  nullable=False),
        sa.Column('updated_at',
                  sqlalchemy_utils.types.arrow.ArrowType(),
                  nullable=True),
        sa.Column('client_id', sa.Integer(), nullable=False),
        sa.Column('uri', sa.String(length=1024), nullable=False),
        sa.ForeignKeyConstraint(['client_id'], ['client.id'],
                                ondelete='cascade'),
        sa.PrimaryKeyConstraint('id'))
Пример #47
0
def downgrade():

    provider_enum = ENUM(
        "loadtesting",
        "firetext",
        "mmg",
        "ses",
        "twilio",
        name="providers",
        create_type=True,
    )
    provider_enum.create(op.get_bind(), checkfirst=False)

    op.add_column(
        "provider_statistics",
        sa.Column("provider",
                  provider_enum,
                  autoincrement=False,
                  nullable=True),
    )
    op.alter_column(
        "provider_statistics",
        "provider_id",
        existing_type=postgresql.UUID(),
        nullable=True,
    )
    op.add_column(
        "provider_rates",
        sa.Column("provider",
                  provider_enum,
                  autoincrement=False,
                  nullable=True),
    )
    op.alter_column("provider_rates",
                    "provider_id",
                    existing_type=postgresql.UUID(),
                    nullable=True)

    op.execute(
        "UPDATE provider_rates set provider = 'mmg' where provider_id = (select id from provider_details where identifier = 'mmg')"
    )
    op.execute(
        "UPDATE provider_rates set provider = 'firetext' where provider_id = (select id from provider_details where identifier = 'firetext')"
    )
    op.execute(
        "UPDATE provider_rates set provider = 'ses' where provider_id = (select id from provider_details where identifier = 'ses')"
    )
    op.execute(
        "UPDATE provider_rates set provider = 'loadtesting' where provider_id = (select id from provider_details where identifier = 'loadtesting')"
    )

    op.execute(
        "UPDATE provider_statistics set provider = 'mmg' where provider_id = (select id from provider_details where identifier = 'mmg')"
    )
    op.execute(
        "UPDATE provider_statistics set provider = 'firetext' where provider_id = (select id from provider_details where identifier = 'firetext')"
    )
    op.execute(
        "UPDATE provider_statistics set provider = 'ses' where provider_id = (select id from provider_details where identifier = 'ses')"
    )
    op.execute(
        "UPDATE provider_statistics set provider = 'loadtesting' where provider_id = (select id from provider_details where identifier = 'loadtesting')"
    )

    op.alter_column("provider_rates",
                    "provider",
                    existing_type=postgresql.UUID(),
                    nullable=False)

    op.alter_column(
        "provider_statistics",
        "provider",
        existing_type=postgresql.UUID(),
        nullable=False,
    )