def upgrade():
    inspector = reflection.Inspector.from_engine(op.get_bind())
    foreign_keys = inspector.get_foreign_keys(TABLE_NAME)
    migration.remove_foreign_keys(TABLE_NAME, foreign_keys)

    unique_constraints = inspector.get_unique_constraints(TABLE_NAME)
    for constraint in unique_constraints:
        op.drop_constraint(
            constraint_name=constraint['name'],
            table_name=TABLE_NAME,
            type_="unique"
        )

    op.create_unique_constraint(
        constraint_name=('uniq_port_forwardings0floatingip_id0'
                         'external_port0protocol'),
        table_name=TABLE_NAME,
        columns=['floatingip_id', 'external_port', 'protocol']
    )
    op.create_unique_constraint(
        constraint_name=('uniq_port_forwardings0internal_neutron_port_id0'
                         'socket0protocol'),
        table_name=TABLE_NAME,
        columns=['internal_neutron_port_id', 'socket', 'protocol']
    )

    migration.create_foreign_keys(TABLE_NAME, foreign_keys)
Ejemplo n.º 2
0
def upgrade():
    inspector = sqlalchemy.inspect(op.get_bind())
    fk_constraints = inspector.get_foreign_keys(TABLE_NAME)
    for fk in fk_constraints:
        fk['options']['ondelete'] = 'CASCADE'

    migration.remove_foreign_keys(TABLE_NAME, fk_constraints)
    migration.create_foreign_keys(TABLE_NAME, fk_constraints)
def upgrade():
    inspector = reflection.Inspector.from_engine(op.get_bind())
    fk_constraints = inspector.get_foreign_keys(TABLE_NAME)
    for fk in fk_constraints:
        fk['options']['ondelete'] = 'CASCADE'

    migration.remove_foreign_keys(TABLE_NAME, fk_constraints)
    migration.create_foreign_keys(TABLE_NAME, fk_constraints)
def upgrade():
    inspector = reflection.Inspector.from_engine(op.get_bind())
    fk_constraints = inspector.get_foreign_keys(TABLE_NAME)
    for fk in fk_constraints:
        fk['options']['ondelete'] = 'CASCADE'

    migration.remove_foreign_keys(TABLE_NAME, fk_constraints)
    migration.create_foreign_keys(TABLE_NAME, fk_constraints)
Ejemplo n.º 5
0
def clear_constraints_and_foreign():
    inspect = sa.engine.reflection.Inspector.from_engine(op.get_bind())
    foreign_keys = inspect.get_foreign_keys(PF_TABLE_NAME)
    migration.remove_foreign_keys(PF_TABLE_NAME,
                                  foreign_keys)
    constraints_name = [
        'uniq_port_forwardings0internal_neutron_port_id0socket0protocol',
        'uniq_port_forwardings0floatingip_id0external_port0protocol']
    for constraint_name in constraints_name:
        op.drop_constraint(
            constraint_name=constraint_name,
            table_name=PF_TABLE_NAME,
            type_='unique'
        )

    return foreign_keys
def upgrade():
    inspector = reflection.Inspector.from_engine(op.get_bind())

    fks_to_cascade = {
        'sfc_flow_classifier_l7_parameters': 'classifier_id',
        'sfc_chain_group_associations': 'portchain_id',
        'sfc_port_chain_parameters': 'chain_id',
        'sfc_service_function_params': 'pair_id',
        'sfc_chain_classifier_associations': 'portchain_id'
    }

    for table, column in fks_to_cascade.items():
        fk_constraints = inspector.get_foreign_keys(table)
        for fk in fk_constraints:
            if column in fk['constrained_columns']:
                fk['options']['ondelete'] = 'CASCADE'
                migration.remove_foreign_keys(table, fk_constraints)
                migration.create_foreign_keys(table, fk_constraints)
def upgrade():
    inspector = reflection.Inspector.from_engine(op.get_bind())

    fks_to_cascade = {
        "sfc_flow_classifier_l7_parameters": "classifier_id",
        "sfc_chain_group_associations": "portchain_id",
        "sfc_port_chain_parameters": "chain_id",
        "sfc_service_function_params": "pair_id",
        "sfc_chain_classifier_associations": "portchain_id",
    }

    for table, column in fks_to_cascade.items():
        fk_constraints = inspector.get_foreign_keys(table)
        for fk in fk_constraints:
            if column in fk["constrained_columns"]:
                fk["options"]["ondelete"] = "CASCADE"
                migration.remove_foreign_keys(table, fk_constraints)
                migration.create_foreign_keys(table, fk_constraints)
def upgrade():
    inspector = reflection.Inspector.from_engine(op.get_bind())

    fks_to_cascade = {
        'sfc_flow_classifier_l7_parameters': 'classifier_id',
        'sfc_chain_group_associations': 'portchain_id',
        'sfc_port_chain_parameters': 'chain_id',
        'sfc_service_function_params': 'pair_id',
        'sfc_chain_classifier_associations': 'portchain_id'
    }

    for table, column in fks_to_cascade.items():
        fk_constraints = inspector.get_foreign_keys(table)
        for fk in fk_constraints:
            if column in fk['constrained_columns']:
                fk['options']['ondelete'] = 'CASCADE'
                migration.remove_foreign_keys(table, fk_constraints)
                migration.create_foreign_keys(table, fk_constraints)
def upgrade():
    inspector = sa.inspect(op.get_bind())
    foreign_keys = inspector.get_foreign_keys(TABLE_NAME)
    migration.remove_foreign_keys(TABLE_NAME, foreign_keys)

    unique_constraints = inspector.get_unique_constraints(TABLE_NAME)
    for constraint in unique_constraints:
        op.drop_constraint(constraint_name=constraint['name'],
                           table_name=TABLE_NAME,
                           type_="unique")

    op.create_unique_constraint(
        constraint_name=('uniq_port_forwardings0floatingip_id0'
                         'external_port0protocol'),
        table_name=TABLE_NAME,
        columns=['floatingip_id', 'external_port', 'protocol'])
    op.create_unique_constraint(
        constraint_name=('uniq_port_forwardings0internal_neutron_port_id0'
                         'socket0protocol'),
        table_name=TABLE_NAME,
        columns=['internal_neutron_port_id', 'socket', 'protocol'])

    migration.create_foreign_keys(TABLE_NAME, foreign_keys)
Ejemplo n.º 10
0
def upgrade():
    if migration.schema_has_table('cisco_router_ha_groups'):
        inspector = reflection.Inspector.from_engine(op.get_bind())
        foreign_keys = inspector.get_foreign_keys('cisco_router_ha_groups')
        migration.remove_foreign_keys('cisco_router_ha_groups', foreign_keys)
        primary_key = inspector.get_pk_constraint('cisco_router_ha_groups')
        op.drop_constraint(constraint_name=primary_key['name'],
                           table_name='cisco_router_ha_groups',
                           type_='primary')

        op.create_foreign_key('cisco_router_ha_groups_ibfk_1',
                              source_table='cisco_router_ha_groups',
                              referent_table='ports',
                              local_cols=['ha_port_id'],
                              remote_cols=['id'],
                              ondelete='CASCADE'),
        op.create_foreign_key('cisco_router_ha_groups_ibfk_2',
                              source_table='cisco_router_ha_groups',
                              referent_table='ports',
                              local_cols=['extra_port_id'],
                              remote_cols=['id'],
                              ondelete='SET NULL'),
        op.create_foreign_key('cisco_router_ha_groups_ibfk_3',
                              source_table='cisco_router_ha_groups',
                              referent_table='subnets',
                              local_cols=['subnet_id'],
                              remote_cols=['id'])
        op.create_foreign_key('cisco_router_ha_groups_ibfk_4',
                              source_table='cisco_router_ha_groups',
                              referent_table='routers',
                              local_cols=['user_router_id'],
                              remote_cols=['id'])

        op.create_primary_key(constraint_name='pk_cisco_router_ha_groups',
                              table_name='cisco_router_ha_groups',
                              columns=['ha_port_id', 'subnet_id'])
def upgrade():
    inspector = reflection.Inspector.from_engine(op.get_bind())
    fk_constraints = inspector.get_foreign_keys(TABLE_NAME)
    migration.remove_foreign_keys(TABLE_NAME, fk_constraints)
    migration.create_foreign_keys(TABLE_NAME, fk_constraints)
Ejemplo n.º 12
0
def upgrade():
    op.create_table(
        'cisco_router_types',
        sa.Column('tenant_id', sa.String(length=255), nullable=True),
        sa.Column('id', sa.String(length=36), nullable=False),
        sa.Column('name', sa.String(length=255), nullable=False),
        sa.Column('description', sa.String(length=255), nullable=True),
        sa.Column('template_id', sa.String(length=36), nullable=True),
        sa.Column('ha_enabled_by_default',
                  sa.Boolean(),
                  nullable=False,
                  server_default=sa.sql.false()),
        sa.Column('shared',
                  sa.Boolean(),
                  nullable=False,
                  server_default=sa.sql.true()),
        sa.Column('slot_need',
                  sa.Integer(),
                  autoincrement=False,
                  nullable=True),
        sa.Column('scheduler', sa.String(length=255), nullable=False),
        sa.Column('driver', sa.String(length=255), nullable=False),
        sa.Column('cfg_agent_service_helper',
                  sa.String(length=255),
                  nullable=False),
        sa.Column('cfg_agent_driver', sa.String(length=255), nullable=False),
        sa.ForeignKeyConstraint(['template_id'],
                                ['cisco_hosting_device_templates.id'],
                                ondelete='CASCADE'),
        sa.PrimaryKeyConstraint('id'))
    if migration.schema_has_table('cisco_router_mappings'):
        op.add_column('cisco_router_mappings',
                      sa.Column('role', sa.String(255), nullable=True))
        op.add_column(
            'cisco_router_mappings',
            sa.Column('router_type_id', sa.String(length=36), nullable=False))

        inspector = reflection.Inspector.from_engine(op.get_bind())
        foreign_keys = inspector.get_foreign_keys('cisco_router_mappings')
        migration.remove_foreign_keys('cisco_router_mappings', foreign_keys)
        primary_key = inspector.get_pk_constraint('cisco_router_mappings')
        op.drop_constraint(constraint_name=primary_key['name'],
                           table_name='cisco_router_mappings',
                           type_='primary')

        op.create_foreign_key('cisco_router_mappings_ibfk_1',
                              source_table='cisco_router_mappings',
                              referent_table='cisco_hosting_devices',
                              local_cols=['hosting_device_id'],
                              remote_cols=['id'],
                              ondelete='SET NULL'),
        op.create_foreign_key('cisco_router_mappings_ibfk_2',
                              source_table='cisco_router_mappings',
                              referent_table='routers',
                              local_cols=['router_id'],
                              remote_cols=['id'],
                              ondelete='CASCADE')
        op.create_foreign_key('cisco_router_mappings_ibfk_3',
                              source_table='cisco_router_mappings',
                              referent_table='cisco_router_types',
                              local_cols=['router_type_id'],
                              remote_cols=['id'])
        op.create_primary_key(constraint_name='pk_cisco_router_mappings',
                              table_name='cisco_router_mappings',
                              columns=['router_id', 'router_type_id'])
        op.add_column(
            'cisco_router_mappings',
            sa.Column('inflated_slot_need',
                      sa.Integer(),
                      autoincrement=False,
                      nullable=True,
                      server_default='0'))
        op.add_column(
            'cisco_router_mappings',
            sa.Column('share_hosting_device',
                      sa.Boolean(),
                      nullable=False,
                      server_default=sa.sql.true()))
        op.create_index(op.f('ix_cisco_router_types_tenant_id'),
                        'cisco_router_types', ['tenant_id'],
                        unique=False)
def upgrade():
    inspector = reflection.Inspector.from_engine(op.get_bind())
    fk_constraints = inspector.get_foreign_keys(TABLE_NAME)
    migration.remove_foreign_keys(TABLE_NAME, fk_constraints)
    migration.create_foreign_keys(TABLE_NAME, fk_constraints)