def downgrade(): with migration.remove_fks_from_table(TABLE_NAME): op.drop_constraint( CONSTRAINT_NAME, TABLE_NAME, type_='unique' )
def upgrade(active_plugins=None, options=None): inspector = reflection.Inspector.from_engine(op.get_bind()) unique_constraints = inspector.get_unique_constraints( 'gp_policy_target_groups') op.drop_constraint('gp_policy_target_groups_ibfk_nsp', 'gp_policy_target_groups', 'foreignkey') for constraint in unique_constraints: if constraint['column_names'] == ['network_service_policy_id']: op.drop_constraint(constraint['name'], 'gp_policy_target_groups', 'unique') break op.create_foreign_key('gp_policy_target_groups_ibfk_nsp', source='gp_policy_target_groups', referent='gp_network_service_policies', local_cols=['network_service_policy_id'], remote_cols=['id']) with migration.remove_fks_from_table( 'gpm_service_policy_ipaddress_mappings'): op.drop_constraint(None, table_name='gpm_service_policy_ipaddress_mappings', type_='primary') op.create_primary_key( name='pk_policytargetgroup_servicepolicyid', table_name='gpm_service_policy_ipaddress_mappings', cols=['policy_target_group', 'service_policy_id'])
def upgrade(active_plugins=None, options=None): inspector = reflection.Inspector.from_engine(op.get_bind()) unique_constraints = inspector.get_unique_constraints( 'gp_policy_target_groups') op.drop_constraint('gp_policy_target_groups_ibfk_nsp', 'gp_policy_target_groups', 'foreignkey') for constraint in unique_constraints: if constraint['column_names'] == ['network_service_policy_id']: op.drop_constraint(constraint['name'], 'gp_policy_target_groups', 'unique') break op.create_foreign_key('gp_policy_target_groups_ibfk_nsp', source='gp_policy_target_groups', referent='gp_network_service_policies', local_cols=['network_service_policy_id'], remote_cols=['id']) with migration.remove_fks_from_table( 'gpm_service_policy_ipaddress_mappings'): op.drop_constraint( None, table_name='gpm_service_policy_ipaddress_mappings', type_='primary') op.create_primary_key( name='pk_policytargetgroup_servicepolicyid', table_name='gpm_service_policy_ipaddress_mappings', cols=['policy_target_group', 'service_policy_id'])
def downgrade(): context = op.get_context() dialect = context.bind.dialect.name op.drop_constraint( name=PK_NAME, table_name=TABLE_NAME, type_='primary' ) op.add_column( TABLE_NAME, sa.Column('id', sa.String(32)) ) if dialect == 'ibm_db_sa': # DB2 doesn't support nullable column in primary key op.alter_column( table_name=TABLE_NAME, column_name='id', nullable=False ) with migration.remove_fks_from_table(TABLE_NAME): op.create_primary_key( name=PK_NAME, table_name=TABLE_NAME, cols=['id'] )
def downgrade(): with migration.remove_fks_from_table(TABLE_NAME): op.drop_constraint(name=CONSTRAINT_NAME_NEW, table_name='extradhcpopts', type_='unique') op.drop_column('extradhcpopts', 'ip_version') op.create_unique_constraint(name=CONSTRAINT_NAME_OLD, source='extradhcpopts', local_cols=['port_id', 'opt_name'])
def upgrade(): with migration.remove_fks_from_table(TABLE_NAME): op.drop_constraint(constraint_name=CONSTRAINT_NAME_OLD, table_name=TABLE_NAME, type_="unique") op.add_column("extradhcpopts", sa.Column("ip_version", sa.Integer(), server_default="4", nullable=False)) op.execute("UPDATE extradhcpopts SET ip_version = 4") op.create_unique_constraint( constraint_name=CONSTRAINT_NAME_NEW, table_name="extradhcpopts", columns=["port_id", "opt_name", "ip_version"] )
def upgrade(active_plugins=None, options=None): inspector = reflection.Inspector.from_engine(op.get_bind()) unique_constraints = inspector.get_unique_constraints( 'gp_es_to_l3p_associations') for constraint in unique_constraints: if constraint['column_names'] == [ 'external_segment_id', 'allocated_address' ]: with migration.remove_fks_from_table('gp_es_to_l3p_associations'): op.drop_constraint(constraint['name'], 'gp_es_to_l3p_associations', 'unique') break
def downgrade(): inspector = reflection.Inspector.from_engine(op.get_bind()) prev_pk_const = inspector.get_pk_constraint(TABLE_NAME) prev_pk_name = prev_pk_const.get('name') with migration.remove_fks_from_table(TABLE_NAME): op.drop_constraint(name=prev_pk_name, table_name=TABLE_NAME, type_='primary') op.create_primary_key(name=None, table_name=TABLE_NAME, cols=['router_id'])
def upgrade(active_plugins=None, options=None): inspector = reflection.Inspector.from_engine(op.get_bind()) unique_constraints = inspector.get_unique_constraints( 'gp_es_to_l3p_associations') for constraint in unique_constraints: if constraint['column_names'] == ['external_segment_id', 'allocated_address']: with migration.remove_fks_from_table( 'gp_es_to_l3p_associations'): op.drop_constraint(constraint['name'], 'gp_es_to_l3p_associations', 'unique') break
def upgrade(): inspector = reflection.Inspector.from_engine(op.get_bind()) prev_pk_const = inspector.get_pk_constraint(TABLE_NAME) prev_pk_name = prev_pk_const.get('name') with migration.remove_fks_from_table(TABLE_NAME): op.drop_constraint(constraint_name=prev_pk_name, table_name=TABLE_NAME, type_='primary') op.create_primary_key(constraint_name=None, table_name=TABLE_NAME, columns=['router_id', 'l3_agent_id'])
def downgrade(): with migration.remove_fks_from_table(TABLE_NAME): op.drop_constraint( name=CONSTRAINT_NAME_NEW, table_name='extradhcpopts', type_='unique' ) op.drop_column('extradhcpopts', 'ip_version') op.create_unique_constraint( name=CONSTRAINT_NAME_OLD, source='extradhcpopts', local_cols=['port_id', 'opt_name'] )
def upgrade(): if op.get_context().bind.dialect.name == 'postgresql': direction_enum.create(op.get_bind(), checkfirst=True) with migration.remove_fks_from_table(bw_limit_table_name, remove_unique_constraints=True): op.add_column(bw_limit_table_name, sa.Column("direction", direction_enum, server_default=constants.EGRESS_DIRECTION, nullable=False)) op.create_unique_constraint( op.f('qos_bandwidth_rules0qos_policy_id0direction'), bw_limit_table_name, ['qos_policy_id', 'direction'])
def upgrade(): # In order to sanitize the data during migration, # the current records in the table need to be verified # and all the duplicate records which violate the PK # constraint need to be removed. context = op.get_context() query_args = {'table': TABLE_NAME, 'agents_table': AGENTS_TABLE_NAME} if context.bind.dialect.name in ('postgresql', 'ibm_db_sa'): op.execute('DELETE FROM %(table)s WHERE id in (' 'SELECT %(table)s.id FROM %(table)s LEFT OUTER JOIN ' '(SELECT MIN(id) as id, router_id, l3_agent_id ' ' FROM %(table)s GROUP BY router_id, l3_agent_id) AS temp ' 'ON %(table)s.id = temp.id WHERE temp.id is NULL);' % query_args) else: op.execute('DELETE %(table)s FROM %(table)s LEFT OUTER JOIN ' '(SELECT MIN(id) as id, router_id, l3_agent_id ' ' FROM %(table)s GROUP BY router_id, l3_agent_id) AS temp ' 'ON %(table)s.id = temp.id WHERE temp.id is NULL;' % query_args) # Remove orphaned records - bindings that reference non-existent agents op.execute('DELETE FROM %(table)s ' 'WHERE l3_agent_id NOT IN (select id from %(agents_table)s);' % query_args) op.drop_column(TABLE_NAME, 'id') with migration.remove_fks_from_table(TABLE_NAME): # DB2 doesn't support nullable column in primary key if context.bind.dialect.name == 'ibm_db_sa': op.alter_column( table_name=TABLE_NAME, column_name='router_id', nullable=False ) op.alter_column( table_name=TABLE_NAME, column_name='l3_agent_id', nullable=False ) op.create_primary_key( name=PK_NAME, table_name=TABLE_NAME, cols=['router_id', 'l3_agent_id'] )
def upgrade(): with migration.remove_fks_from_table(TABLE_NAME): op.drop_constraint( name=CONSTRAINT_NAME_OLD, table_name=TABLE_NAME, type_='unique' ) op.add_column('extradhcpopts', sa.Column('ip_version', sa.Integer(), server_default='4', nullable=False)) op.execute("UPDATE extradhcpopts SET ip_version = 4") op.create_unique_constraint( name=CONSTRAINT_NAME_NEW, source='extradhcpopts', local_cols=['port_id', 'opt_name', 'ip_version'] )
def upgrade(): with migration.remove_fks_from_table(TABLE_NAME): op.drop_constraint( constraint_name=CONSTRAINT_NAME_OLD, table_name=TABLE_NAME, type_='unique' ) op.add_column('extradhcpopts', sa.Column('ip_version', sa.Integer(), server_default='4', nullable=False)) op.execute("UPDATE extradhcpopts SET ip_version = 4") op.create_unique_constraint( constraint_name=CONSTRAINT_NAME_NEW, table_name='extradhcpopts', columns=['port_id', 'opt_name', 'ip_version'] )
def upgrade(): # re-size existing data if necessary identifier_map = table('cisco_csr_identifier_map', column('ipsec_site_conn_id', sa.String(36))) ipsec_site_conn_id = identifier_map.columns['ipsec_site_conn_id'] op.execute(identifier_map.update(values={ ipsec_site_conn_id: expr.case([(func.length(ipsec_site_conn_id) > 36, func.substr(ipsec_site_conn_id, 1, 36))], else_=ipsec_site_conn_id)})) # Need to drop foreign key constraint before mysql will allow changes with migration.remove_fks_from_table('cisco_csr_identifier_map'): op.alter_column(table_name='cisco_csr_identifier_map', column_name='ipsec_site_conn_id', type_=sa.String(36), existing_nullable=False)
def upgrade(): # In order to sanitize the data during migration, # the current records in the table need to be verified # and all the duplicate records which violate the PK # constraint need to be removed. context = op.get_context() if context.bind.dialect.name in ('postgresql', 'ibm_db_sa'): op.execute('DELETE FROM %(table)s WHERE id in (' 'SELECT %(table)s.id FROM %(table)s LEFT OUTER JOIN ' '(SELECT MIN(id) as id, router_id, l3_agent_id ' ' FROM %(table)s GROUP BY router_id, l3_agent_id) AS temp ' 'ON %(table)s.id = temp.id WHERE temp.id is NULL);' % {'table': TABLE_NAME}) else: op.execute('DELETE %(table)s FROM %(table)s LEFT OUTER JOIN ' '(SELECT MIN(id) as id, router_id, l3_agent_id ' ' FROM %(table)s GROUP BY router_id, l3_agent_id) AS temp ' 'ON %(table)s.id = temp.id WHERE temp.id is NULL;' % {'table': TABLE_NAME}) op.drop_column(TABLE_NAME, 'id') with migration.remove_fks_from_table(TABLE_NAME): # DB2 doesn't support nullable column in primary key if context.bind.dialect.name == 'ibm_db_sa': op.alter_column( table_name=TABLE_NAME, column_name='router_id', nullable=False ) op.alter_column( table_name=TABLE_NAME, column_name='l3_agent_id', nullable=False ) op.create_primary_key( name=PK_NAME, table_name=TABLE_NAME, cols=['router_id', 'l3_agent_id'] )
def downgrade(): with migration.remove_fks_from_table(TABLE_NAME): op.drop_constraint(CONSTRAINT_NAME, TABLE_NAME, type_='unique')