How to use the alembic.op.batch_alter_table function in alembic

To help you get started, we’ve selected a few alembic examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github asterisk / asterisk / contrib / ast-db-manage / config / versions / 339a3bdf53fc_expand_accountcode_to_80.py View on Github external
def upgrade():
    with op.batch_alter_table('ps_endpoints') as batch_op:
        batch_op.alter_column('accountcode', type_=sa.String(80))
    with op.batch_alter_table('sippeers') as batch_op:
        batch_op.alter_column('accountcode', type_=sa.String(80))
    with op.batch_alter_table('iaxfriends') as batch_op:
        batch_op.alter_column('accountcode', type_=sa.String(80))
    pass
github Mailu / Mailu / core / admin / migrations / versions / 27ae2f102682_.py View on Github external
def upgrade():
    connection = op.get_bind()
    # spam_threshold is a X/15 based value, we're converting it to percent.
    for user in connection.execute(user_table.select()):
         connection.execute(
            user_table.update().where(
                user_table.c.email == user.email
            ).values(
                spam_threshold=int(100. * float(user.spam_threshold or 0.) / 15.)
            )
         )
    # set default to 80%
    with op.batch_alter_table('user') as batch:
        batch.alter_column('spam_threshold', server_default="80.")
github apache / airflow / airflow / migrations / versions / 2e541a1dcfed_task_duration.py View on Github external
def upgrade():
    # use batch_alter_table to support SQLite workaround
    with op.batch_alter_table("task_instance") as batch_op:
        batch_op.alter_column('duration',
                              existing_type=mysql.INTEGER(display_width=11),
                              type_=sa.Float(),
                              existing_nullable=True)
github armadillica / flamenco / flamenco / server / migrations / versions / 4bbcb4d706ef_dropping_workers_and_new_jobs.py View on Github external
def downgrade():
    ### commands auto generated by Alembic - please adjust! ###
    with op.batch_alter_table('task', schema=None) as batch_op:
        batch_op.add_column(sa.Column('chunk_start', mysql.INTEGER(display_width=11), autoincrement=False, nullable=True))
        batch_op.add_column(sa.Column('current_frame', mysql.INTEGER(display_width=11), autoincrement=False, nullable=True))
        batch_op.add_column(sa.Column('chunk_end', mysql.INTEGER(display_width=11), autoincrement=False, nullable=True))
        batch_op.drop_column('type')
        batch_op.drop_column('settings')
        batch_op.drop_column('name')
        batch_op.drop_column('log')
        batch_op.drop_column('activity')

    with op.batch_alter_table('manager', schema=None) as batch_op:
        batch_op.add_column(sa.Column('running_tasks', mysql.INTEGER(display_width=11), autoincrement=False, nullable=False))
        batch_op.add_column(sa.Column('total_workers', mysql.INTEGER(display_width=11), autoincrement=False, nullable=True))

    with op.batch_alter_table('job', schema=None) as batch_op:
        batch_op.add_column(sa.Column('frame_start', mysql.INTEGER(display_width=11), autoincrement=False, nullable=True))
        batch_op.add_column(sa.Column('current_frame', mysql.INTEGER(display_width=11), autoincrement=False, nullable=True))
github ubc / compair / alembic / versions / aafd2a91e3a_add_score_columns.py View on Github external
def upgrade():
    with op.batch_alter_table('score', naming_convention=convention) as batch_op:
        batch_op.add_column(sa.Column('scoring_algorithm', EnumType(ScoringAlgorithm), nullable=True))
        batch_op.add_column(sa.Column('variable1', sa.Float(), nullable=True))
        batch_op.add_column(sa.Column('variable2', sa.Float(), nullable=True))
        batch_op.add_column(sa.Column('loses', sa.Integer(), nullable=False, default='0', server_default='0'))
github freenas / freenas / src / middlewared / middlewared / alembic / versions / 12.0 / 2020-05-29_16-06_remove_replication_dedup.py View on Github external
def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    with op.batch_alter_table('storage_replication', schema=None) as batch_op:
        batch_op.add_column(sa.Column('repl_dedup', sa.BOOLEAN(), nullable=False))
github openstack / ironic-inspector / ironic_inspector / migrations / versions / 882b2d84cb1b_attribute_constraints_relaxing.py View on Github external
with op.batch_alter_table(ATTRIBUTES,
                              naming_convention=naming_convention) as batch_op:
        batch_op.drop_constraint(fk_constraint, type_='foreignkey')

    rows = connection.execute(sa.select([attributes.c.uuid,
                                         attributes.c.node_uuid]))

    for row in rows:
        # move uuid to node_uuid, reuse uuid as a new primary key
        connection.execute(
            attributes.update().where(attributes.c.uuid == row.uuid).
            values(node_uuid=row.uuid, uuid=uuidutils.generate_uuid())
        )

    with op.batch_alter_table(ATTRIBUTES,
                              naming_convention=naming_convention) as batch_op:
        batch_op.drop_constraint(pk_constraint, type_='primary')
        batch_op.create_primary_key(pk_constraint, [UUID])
        batch_op.create_foreign_key('fk_node_attribute', NODES,
                                    [NODE_UUID], [UUID])
        batch_op.alter_column('name', nullable=False, type_=name_type)
        batch_op.alter_column('value', nullable=True, type_=value_type)
github ngoduykhanh / PowerDNS-Admin / migrations / versions / 0fb6d23a4863_remove_user_avatar.py View on Github external
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    with op.batch_alter_table('user') as batch_op:
        batch_op.drop_column('avatar')
    # ### end Alembic commands ###
github hypothesis / h / h / migrations / versions / ef3059e0396_add_staff_column_to_feature_table.py View on Github external
def downgrade():
    with op.batch_alter_table('feature') as batch_op:
        batch_op.drop_column('staff')
    with op.batch_alter_table('user') as batch_op:
        batch_op.drop_column('staff')
github ubc / compair / alembic / versions / b7b941f61291_added_uuid.py View on Github external
def downgrade():
    # drop uuid unique constraint and column for each table
    for table_name in table_names:
        with op.batch_alter_table(table_name, naming_convention=convention) as batch_op:
            batch_op.drop_constraint("uq_"+table_name+"_uuid", type_='unique')
            batch_op.drop_column('uuid')