Python alembic.op.alter_column() Examples
The following are 30
code examples of alembic.op.alter_column().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
alembic.op
, or try the search function
.
Example #1
Source File: 0f3bc98edaa0_more_status.py From backend.ai-manager with GNU Lesser General Public License v3.0 | 7 votes |
def upgrade(): agentstatus.create(op.get_bind()) kernelstatus.create(op.get_bind()) op.add_column('agents', sa.Column('lost_at', sa.DateTime(timezone=True), nullable=True)) op.add_column('agents', sa.Column('status', sa.Enum('ALIVE', 'LOST', 'RESTARTING', 'TERMINATED', name='agentstatus'), nullable=False)) op.create_index(op.f('ix_agents_status'), 'agents', ['status'], unique=False) op.add_column('kernels', sa.Column('agent_addr', sa.String(length=128), nullable=False)) op.add_column('kernels', sa.Column('cpu_slot', sa.Integer(), nullable=False)) op.add_column('kernels', sa.Column('gpu_slot', sa.Integer(), nullable=False)) op.add_column('kernels', sa.Column('mem_slot', sa.Integer(), nullable=False)) op.add_column('kernels', sa.Column('repl_in_port', sa.Integer(), nullable=False)) op.add_column('kernels', sa.Column('repl_out_port', sa.Integer(), nullable=False)) op.add_column('kernels', sa.Column('stdin_port', sa.Integer(), nullable=False)) op.add_column('kernels', sa.Column('stdout_port', sa.Integer(), nullable=False)) op.drop_column('kernels', 'allocated_cores') op.add_column('kernels', sa.Column('cpu_set', sa.ARRAY(sa.Integer), nullable=True)) op.add_column('kernels', sa.Column('gpu_set', sa.ARRAY(sa.Integer), nullable=True)) op.alter_column('kernels', column_name='status', type_=sa.Enum(*kernelstatus_choices, name='kernelstatus'), postgresql_using='status::kernelstatus')
Example #2
Source File: 22e52d03fc61_add_allowed_docker_registries_in_domains.py From backend.ai-manager with GNU Lesser General Public License v3.0 | 6 votes |
def upgrade(): # ### commands auto generated by Alembic - please adjust! ### op.add_column('domains', sa.Column('allowed_docker_registries', postgresql.ARRAY(sa.String()), nullable=True)) # ### end Alembic commands ### print('\nSet default allowed_docker_registries.') allowed_registries = os.environ.get('ALLOWED_DOCKER_REGISTRIES', None) if allowed_registries: allowed_registries = allowed_registries.replace(' ', '') allowed_registries = '{index.docker.io,' + allowed_registries + '}' else: allowed_registries = '{index.docker.io}' connection = op.get_bind() query = ("UPDATE domains SET allowed_docker_registries = '{}';".format(allowed_registries)) connection.execute(query) op.alter_column('domains', column_name='allowed_docker_registries', nullable=False)
Example #3
Source File: 22964745c12b_add_total_resource_slots_to_group.py From backend.ai-manager with GNU Lesser General Public License v3.0 | 6 votes |
def upgrade(): # ### commands auto generated by Alembic - please adjust! ### op.add_column('domains', sa.Column('integration_id', sa.String(length=512), nullable=True)) op.alter_column('domains', 'total_resource_slots', existing_type=postgresql.JSONB(astext_type=sa.Text()), nullable=True) op.add_column('groups', sa.Column('integration_id', sa.String(length=512), nullable=True)) op.add_column('groups', sa.Column('total_resource_slots', postgresql.JSONB(astext_type=sa.Text()), nullable=True)) op.add_column('users', sa.Column('integration_id', sa.String(length=512), nullable=True)) # ### end Alembic commandk ### print('\nSet group\'s total_resource_slots with empty dictionary.') query = textwrap.dedent('''\ UPDATE groups SET total_resource_slots = '{}'::jsonb; ''') connection = op.get_bind() connection.execute(query)
Example #4
Source File: d502ce8fb705_add_rp_uuid_to_compute_node.py From zun with Apache License 2.0 | 6 votes |
def upgrade(): op.add_column('compute_node', sa.Column('rp_uuid', sa.String(length=36), nullable=True)) op.create_unique_constraint('uniq_compute_node0rp_uuid', 'compute_node', ['rp_uuid']) # perform data migration between tables session = sa.orm.Session(bind=op.get_bind()) with session.begin(subtransactions=True): for row in session.query(COMPUTE_NODE_TABLE): session.execute( COMPUTE_NODE_TABLE.update().values( rp_uuid=row.uuid).where( COMPUTE_NODE_TABLE.c.uuid == row.uuid) ) # this commit is necessary to allow further operations session.commit() op.alter_column('compute_node', 'rp_uuid', nullable=False, existing_type=sa.String(length=36), existing_nullable=True, existing_server_default=False)
Example #5
Source File: a9c9fb54274a_add_contents_to_volume_mapping_table.py From zun with Apache License 2.0 | 6 votes |
def upgrade(): op.add_column('volume_mapping', sa.Column('contents', MediumText(), nullable=True)) op.alter_column('volume_mapping', 'volume_id', existing_type=sa.String(36), nullable=True)
Example #6
Source File: c401d78cc7b9_add_allowed_vfolder_hosts_to_domain_and_.py From backend.ai-manager with GNU Lesser General Public License v3.0 | 6 votes |
def upgrade(): # ### commands auto generated by Alembic - please adjust! ### op.add_column('domains', sa.Column('allowed_vfolder_hosts', postgresql.ARRAY(sa.String()), nullable=True)) op.add_column('groups', sa.Column('allowed_vfolder_hosts', postgresql.ARRAY(sa.String()), nullable=True)) # ### end Alembic commands ### print('\nSet domain and group\'s allowed_vfolder_hosts with empty array.') connection = op.get_bind() query = ("UPDATE domains SET allowed_vfolder_hosts = '{}';") connection.execute(query) query = ("UPDATE groups SET allowed_vfolder_hosts = '{}';") connection.execute(query) op.alter_column('domains', column_name='allowed_vfolder_hosts', nullable=False) op.alter_column('groups', column_name='allowed_vfolder_hosts', nullable=False)
Example #7
Source File: 0f3bc98edaa0_more_status.py From backend.ai-manager with GNU Lesser General Public License v3.0 | 6 votes |
def downgrade(): op.drop_column('kernels', 'stdout_port') op.drop_column('kernels', 'stdin_port') op.drop_column('kernels', 'repl_out_port') op.drop_column('kernels', 'repl_in_port') op.drop_column('kernels', 'mem_slot') op.drop_column('kernels', 'gpu_slot') op.drop_column('kernels', 'cpu_slot') op.drop_column('kernels', 'agent_addr') op.drop_index(op.f('ix_agents_status'), table_name='agents') op.drop_column('agents', 'status') op.drop_column('agents', 'lost_at') op.alter_column('kernels', column_name='status', type_=sa.String(length=64)) op.add_column('kernels', sa.Column('allocated_cores', sa.ARRAY(sa.Integer), nullable=True)) op.drop_column('kernels', 'cpu_set') op.drop_column('kernels', 'gpu_set') agentstatus.drop(op.get_bind()) kernelstatus.drop(op.get_bind())
Example #8
Source File: 854bd902b1bc_change_kernel_identification.py From backend.ai-manager with GNU Lesser General Public License v3.0 | 6 votes |
def upgrade(): op.drop_constraint('fk_vfolder_attachment_vfolder_vfolders', 'vfolder_attachment', type_='foreignkey') op.drop_constraint('fk_vfolder_attachment_kernel_kernels', 'vfolder_attachment', type_='foreignkey') op.drop_constraint('pk_kernels', 'kernels', type_='primary') op.add_column('kernels', sa.Column('id', GUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False)) op.add_column('kernels', sa.Column('role', sa.String(length=16), nullable=False, default='master')) op.create_primary_key('pk_kernels', 'kernels', ['id']) op.alter_column( 'kernels', 'sess_id', existing_type=postgresql.UUID(), type_=sa.String(length=64), nullable=True, existing_server_default=sa.text('uuid_generate_v4()')) op.create_index(op.f('ix_kernels_sess_id'), 'kernels', ['sess_id'], unique=False) op.create_index(op.f('ix_kernels_sess_id_role'), 'kernels', ['sess_id', 'role'], unique=False) op.create_foreign_key('fk_vfolder_attachment_vfolder_vfolders', 'vfolder_attachment', 'vfolders', ['vfolder'], ['id'], onupdate='CASCADE', ondelete='CASCADE') op.create_foreign_key('fk_vfolder_attachment_kernel_kernels', 'vfolder_attachment', 'kernels', ['kernel'], ['id'], onupdate='CASCADE', ondelete='CASCADE')
Example #9
Source File: 2020_041911_dd911f880b75_.py From app with MIT License | 6 votes |
def upgrade(): # ### commands auto generated by Alembic - please adjust! ### op.create_table('apple_subscription', 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('expires_date', sqlalchemy_utils.types.arrow.ArrowType(), nullable=False), sa.Column('original_transaction_id', sa.String(length=256), nullable=False), sa.Column('receipt_data', sa.Text(), nullable=False), sa.Column('plan', sa.Enum('monthly', 'yearly', name='planenum_apple'), nullable=False), sa.ForeignKeyConstraint(['user_id'], ['users.id'], ondelete='cascade'), sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('user_id') ) op.alter_column('file', 'user_id', existing_type=sa.INTEGER(), nullable=True) # ### end Alembic commands ###
Example #10
Source File: 0d553d59f369_users_replace_is_active_to_status_and_its_info.py From backend.ai-manager with GNU Lesser General Public License v3.0 | 6 votes |
def upgrade(): userstatus.create(op.get_bind()) op.add_column( 'users', sa.Column('status', sa.Enum(*userstatus_choices, name='userstatus'), nullable=True) ) op.add_column('users', sa.Column('status_info', sa.Unicode(), nullable=True)) # Set user's status field. conn = op.get_bind() query = textwrap.dedent( "UPDATE users SET status = 'active', status_info = 'migrated' WHERE is_active = 't';" ) conn.execute(query) query = textwrap.dedent( "UPDATE users SET status = 'inactive', status_info = 'migrated' WHERE is_active <> 't';" ) conn.execute(query) op.alter_column('users', column_name='status', nullable=False) op.drop_column('users', 'is_active')
Example #11
Source File: e7371ca5797a_rename_mem_stats.py From backend.ai-manager with GNU Lesser General Public License v3.0 | 5 votes |
def downgrade(): op.alter_column('kernels', column_name='mem_max_bytes', new_column_name='max_mem_bytes') op.alter_column('kernels', column_name='mem_cur_bytes', new_column_name='cur_mem_bytes')
Example #12
Source File: d1002a1f97f6_update_flow_classifier.py From networking-sfc with Apache License 2.0 | 5 votes |
def upgrade(): op.alter_column('sfc_flow_classifiers', 'logical_source_port', nullable=True, existing_type=sa.String(length=36), existing_nullable=False)
Example #13
Source File: 4255158a6913_create_private_column_in_project_table.py From pagure with GNU General Public License v2.0 | 5 votes |
def upgrade(): ''' Add a private column in the project table ''' op.add_column( 'projects', sa.Column('private', sa.Boolean, nullable=True, default=False) ) op.execute('''UPDATE "projects" ''' '''SET private=False;''') op.alter_column( 'projects', column_name='private', nullable=False, existing_nullable=True)
Example #14
Source File: 770149d96e24_nullable_project_for_api_token.py From pagure with GNU General Public License v2.0 | 5 votes |
def downgrade(): """ Make the field 'project_id' of the table tokens be not nullable. """ op.alter_column( 'tokens', 'project_id', nullable=False, existing_nullable=True, )
Example #15
Source File: e3cc5aedb8bb_add_date_updated_to_pr_flags.py From pagure with GNU General Public License v2.0 | 5 votes |
def upgrade(): """ Add date_updated column to pull_request_flags table """ op.add_column( 'pull_request_flags', sa.Column( 'date_updated', sa.DateTime, nullable=True, default=datetime.datetime.utcnow, ) ) op.execute('UPDATE pull_request_flags SET date_updated=date_created') op.alter_column( 'pull_request_flags', 'date_updated', existing_type=sa.DateTime, nullable=False, existing_nullable=True)
Example #16
Source File: 010308b06b49_rename_tenant_to_project.py From networking-sfc with Apache License 2.0 | 5 votes |
def upgrade(): inspector = get_inspector() data = get_data() for table, column in data: alter_column(table, column) indexes = inspector.get_indexes(table) for index in indexes: if 'tenant_id' in index['name']: recreate_index(index, table)
Example #17
Source File: 010308b06b49_rename_tenant_to_project.py From networking-sfc with Apache License 2.0 | 5 votes |
def alter_column(table, column): old_name = 'tenant_id' new_name = 'project_id' op.alter_column( table_name=table, column_name=old_name, new_column_name=new_name, existing_type=column['type'], existing_nullable=column['nullable'] )
Example #18
Source File: 8329e9be2d8a_modify_value_column_size_in_port_pair_.py From networking-sfc with Apache License 2.0 | 5 votes |
def upgrade(): op.alter_column('sfc_port_pair_group_params', 'value', existing_type=sa.String(255), type_=sa.String(1024))
Example #19
Source File: 58e60d869326_add_notification_bool_to_pr.py From pagure with GNU General Public License v2.0 | 5 votes |
def upgrade(): ''' Add the column notification to the table pull_request_comments. ''' op.add_column( 'pull_request_comments', sa.Column('notification', sa.Boolean, default=False, nullable=True) ) op.execute('''UPDATE "pull_request_comments" SET notification=False;''') op.alter_column( 'pull_request_comments', 'notification', nullable=False, existing_nullable=True)
Example #20
Source File: 22964745c12b_add_total_resource_slots_to_group.py From backend.ai-manager with GNU Lesser General Public License v3.0 | 5 votes |
def downgrade(): # ### commands auto generated by Alembic - please adjust! ### op.drop_column('users', 'integration_id') op.drop_column('groups', 'total_resource_slots') op.drop_column('groups', 'integration_id') op.alter_column('domains', 'total_resource_slots', existing_type=postgresql.JSONB(astext_type=sa.Text()), nullable=False) op.drop_column('domains', 'integration_id') # ### end Alembic commands ###
Example #21
Source File: 9bd986a75a2a_allow_kernels_scaling_group_nullable.py From backend.ai-manager with GNU Lesser General Public License v3.0 | 5 votes |
def upgrade(): # ### commands auto generated by Alembic - please adjust! ### op.alter_column('kernels', 'scaling_group', existing_type=sa.VARCHAR(length=64), nullable=True, existing_server_default=sa.text("'default'::character varying")) # ### end Alembic commands ###
Example #22
Source File: 93e9d31d40bf_agent_add_region.py From backend.ai-manager with GNU Lesser General Public License v3.0 | 5 votes |
def downgrade(): # ### commands auto generated by Alembic - please adjust! ### op.alter_column( 'keypairs', 'is_admin', existing_type=sa.BOOLEAN(), nullable=False, existing_server_default=sa.text('false')) op.drop_index(op.f('ix_agents_region'), table_name='agents') op.drop_column('agents', 'region') # ### end Alembic commands ###
Example #23
Source File: e7371ca5797a_rename_mem_stats.py From backend.ai-manager with GNU Lesser General Public License v3.0 | 5 votes |
def upgrade(): op.alter_column('kernels', column_name='max_mem_bytes', new_column_name='mem_max_bytes') op.alter_column('kernels', column_name='cur_mem_bytes', new_column_name='mem_cur_bytes')
Example #24
Source File: 352fa4f88f61_add_tpu_slot_on_kernel_model.py From backend.ai-manager with GNU Lesser General Public License v3.0 | 5 votes |
def upgrade(): # ### commands auto generated by Alembic - please adjust! ### op.add_column('kernels', sa.Column('tpu_set', sa.ARRAY(sa.Integer()), nullable=True)) op.add_column('kernels', sa.Column('tpu_slot', sa.Float(), nullable=False, server_default='0')) op.alter_column('kernels', 'tpu_slot', server_default=None) # ### end Alembic commands ###
Example #25
Source File: 57b523dec0e8_add_tpu_slots.py From backend.ai-manager with GNU Lesser General Public License v3.0 | 5 votes |
def upgrade(): # ### commands auto generated by Alembic - please adjust! ### op.add_column('agents', sa.Column('tpu_slots', sa.Float(), nullable=False, server_default='0')) op.add_column('agents', sa.Column('used_tpu_slots', sa.Float(), nullable=False, server_default='0')) op.alter_column('agents', 'tpu_slots', server_default=None) op.alter_column('agents', 'used_tpu_slots', server_default=None) # ### end Alembic commands ###
Example #26
Source File: 4b8a66fb8d82_revamp_keypairs.py From backend.ai-manager with GNU Lesser General Public License v3.0 | 5 votes |
def downgrade(): # ### commands auto generated by Alembic - please adjust! ### op.alter_column('keypairs', column_name='resource_policy', new_column_name='billing_plan') op.drop_index(op.f('ix_keypairs_user_id'), table_name='keypairs') op.drop_index(op.f('ix_keypairs_is_active'), table_name='keypairs') # ### end Alembic commands ###
Example #27
Source File: 4b8a66fb8d82_revamp_keypairs.py From backend.ai-manager with GNU Lesser General Public License v3.0 | 5 votes |
def upgrade(): # ### commands auto generated by Alembic - please adjust! ### op.alter_column('keypairs', column_name='billing_plan', new_column_name='resource_policy') op.create_index(op.f('ix_keypairs_is_active'), 'keypairs', ['is_active'], unique=False) op.create_index(op.f('ix_keypairs_user_id'), 'keypairs', ['user_id'], unique=False) # ### end Alembic commands ###
Example #28
Source File: 0c5733f80e4d_index_kernel_timestamps.py From backend.ai-manager with GNU Lesser General Public License v3.0 | 5 votes |
def upgrade(): # ### commands auto generated by Alembic - please adjust! ### op.alter_column('kernels', 'status', existing_type=postgresql.ENUM('PENDING', 'PREPARING', 'BUILDING', 'PULLING', 'RUNNING', 'RESTARTING', 'RESIZING', 'SUSPENDED', 'TERMINATING', 'TERMINATED', 'ERROR', 'CANCELLED', name='kernelstatus'), nullable=False, existing_server_default=sa.text("'PENDING'::kernelstatus")) op.alter_column('kernels', 'type', existing_type=postgresql.ENUM('INTERACTIVE', 'BATCH', name='sessiontypes'), nullable=False, existing_server_default=sa.text("'INTERACTIVE'::sessiontypes")) op.create_index(op.f('ix_kernels_status_changed'), 'kernels', ['status_changed'], unique=False) op.create_index('ix_kernels_updated_order', 'kernels', ['created_at', 'terminated_at', 'status_changed'], unique=False) # ### end Alembic commands ###
Example #29
Source File: 854bd902b1bc_change_kernel_identification.py From backend.ai-manager with GNU Lesser General Public License v3.0 | 5 votes |
def downgrade(): op.drop_constraint('fk_vfolder_attachment_vfolder_vfolders', 'vfolder_attachment', type_='foreignkey') op.drop_constraint('fk_vfolder_attachment_kernel_kernels', 'vfolder_attachment', type_='foreignkey') op.drop_constraint('pk_kernels', 'kernels', type_='primary') op.drop_index(op.f('ix_kernels_sess_id'), table_name='kernels') op.drop_index(op.f('ix_kernels_sess_id_role'), table_name='kernels') op.alter_column( 'kernels', 'sess_id', existing_type=sa.String(length=64), type_=postgresql.UUID(), nullable=False, existing_server_default=sa.text('uuid_generate_v4()'), postgresql_using='sess_id::uuid') op.create_primary_key('pk_kernels', 'kernels', ['sess_id']) op.drop_column('kernels', 'id') op.drop_column('kernels', 'role') op.create_foreign_key('fk_vfolder_attachment_vfolder_vfolders', 'vfolder_attachment', 'vfolders', ['vfolder'], ['id']) op.create_foreign_key('fk_vfolder_attachment_kernel_kernels', 'vfolder_attachment', 'kernels', ['kernel'], ['sess_id'])
Example #30
Source File: a1fd4e7b7782_enumerate_vfolder_perms.py From backend.ai-manager with GNU Lesser General Public License v3.0 | 5 votes |
def downgrade(): # ### commands auto generated by Alembic - please adjust! ### op.alter_column('vfolder_invitations', column_name='permission', type_=sa.String(length=2), postgresql_using='permission::text::vfolderpermission') op.alter_column('vfolder_permissions', column_name='permission', type_=sa.String(length=2), postgresql_using='permission::text::vfolderpermission') vfolderpermission.drop(op.get_bind()) # ### end Alembic commands ###