当前位置: 首页>>代码示例>>Python>>正文


Python ForeignKeyConstraint.drop方法代码示例

本文整理汇总了Python中migrate.ForeignKeyConstraint.drop方法的典型用法代码示例。如果您正苦于以下问题:Python ForeignKeyConstraint.drop方法的具体用法?Python ForeignKeyConstraint.drop怎么用?Python ForeignKeyConstraint.drop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在migrate.ForeignKeyConstraint的用法示例。


在下文中一共展示了ForeignKeyConstraint.drop方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: downgrade

# 需要导入模块: from migrate import ForeignKeyConstraint [as 别名]
# 或者: from migrate.ForeignKeyConstraint import drop [as 别名]
def downgrade(migrate_engine):
    meta = MetaData()
    meta.bind = migrate_engine

    fk_name = None

    if migrate_engine.name == 'mysql':
        fk_name = 'reservations_ibfk_1'
    elif migrate_engine.name == 'postgresql':
        fk_name = 'reservations_usage_id_fkey'

    # NOTE: MySQL and PostgreSQL Cannot drop the quota_usages table
    # until the foreign key is removed.  We remove the foreign key first,
    # and then we drop the table.
    table = Table('reservations', meta, autoload=True)
    ref_table = Table('reservations', meta, autoload=True)
    params = {'columns': [table.c['usage_id']],
              'refcolumns': [ref_table.c['id']],
              'name': fk_name}

    if fk_name:
        fkey = ForeignKeyConstraint(**params)
        fkey.drop()

    quota_classes = Table('quota_classes', meta, autoload=True)
    quota_classes.drop()

    quota_usages = Table('quota_usages', meta, autoload=True)
    quota_usages.drop()

    reservations = Table('reservations', meta, autoload=True)
    reservations.drop()
开发者ID:apporc,项目名称:cinder,代码行数:34,代码来源:002_quota_class.py

示例2: cascade_fkeys

# 需要导入模块: from migrate import ForeignKeyConstraint [as 别名]
# 或者: from migrate.ForeignKeyConstraint import drop [as 别名]
def cascade_fkeys(metadata, restore=False):
    """ Sets all fkeys to cascade on update """
    for table_name, table in metadata.tables.items():
        for fkey in list(table.foreign_keys):
            if restore:
                if fkey.constraint.name in cascade_fkeys.fkey_onupdate_restore:
                    onupdate = cascade_fkeys.fkey_onupdate_restore[
                        fkey.constraint.name]
                else:
                    continue
            else:
                cascade_fkeys.fkey_onupdate_restore[fkey.constraint.name] = \
                    fkey.constraint.onupdate
                onupdate = "CASCADE"

            params = {
                'columns': fkey.constraint.columns,
                'refcolumns': [fkey.column],
                'name': fkey.constraint.name,
                'onupdate': fkey.constraint.onupdate,
                'ondelete': fkey.constraint.ondelete,
                'deferrable': fkey.constraint.deferrable,
                'initially': fkey.constraint.initially,
                'table': table
            }

            fkey_constraint = ForeignKeyConstraint(**params)
            fkey_constraint.drop()

            params['onupdate'] = onupdate
            fkey_constraint = ForeignKeyConstraint(**params)
            fkey_constraint.create()
开发者ID:rcbau,项目名称:fuzzy-happiness,代码行数:34,代码来源:sqlalchemy_fuzzify.py

示例3: upgrade

# 需要导入模块: from migrate import ForeignKeyConstraint [as 别名]
# 或者: from migrate.ForeignKeyConstraint import drop [as 别名]
def upgrade(migrate_engine):
    meta = MetaData()
    meta.bind = migrate_engine

    compute_nodes = Table('compute_nodes', meta, autoload=True)
    shadow_compute_nodes = Table('shadow_compute_nodes', meta, autoload=True)
    services = Table('services', meta, autoload=True)

    _correct_sqlite_unique_constraints(migrate_engine, compute_nodes)

    # Make the service_id column nullable
    compute_nodes.c.service_id.alter(nullable=True)
    shadow_compute_nodes.c.service_id.alter(nullable=True)

    for fk in compute_nodes.foreign_keys:
        if fk.column == services.c.id:
            # Delete the FK
            fkey = ForeignKeyConstraint(columns=[compute_nodes.c.service_id],
                                        refcolumns=[services.c.id],
                                        name=fk.name)
            fkey.drop()
            break
    for index in compute_nodes.indexes:
        if 'service_id' in index.columns:
            # Delete the nested index which was created by the FK
            index.drop()
            break
开发者ID:375670450,项目名称:nova,代码行数:29,代码来源:278_remove_service_fk_in_compute_nodes.py

示例4: downgrade

# 需要导入模块: from migrate import ForeignKeyConstraint [as 别名]
# 或者: from migrate.ForeignKeyConstraint import drop [as 别名]
def downgrade(migrate_engine):
    metadata.bind = migrate_engine
    # Load existing tables
    metadata.reflect()
    # NOTE: all new data added in the upgrade method is eliminated here via table drops
    # Drop 1 foreign key constraint from the metadata_file table
    try:
        MetadataFile_table = Table( "metadata_file", metadata, autoload=True )
    except NoSuchTableError:
        MetadataFile_table = None
        log.debug( "Failed loading table metadata_file" )
    try:
        LibraryDatasetDatasetAssociation_table = Table( "library_dataset_dataset_association", metadata, autoload=True )
    except NoSuchTableError:
        LibraryDatasetDatasetAssociation_table = None
        log.debug( "Failed loading table library_dataset_dataset_association" )
    if MetadataFile_table is not None and LibraryDatasetDatasetAssociation_table is not None:
        try:
            cons = ForeignKeyConstraint( [MetadataFile_table.c.lda_id],
                                         [LibraryDatasetDatasetAssociation_table.c.id],
                                         name='metadata_file_lda_id_fkey' )
            # Drop the constraint
            cons.drop()
        except Exception, e:
            log.debug( "Dropping foreign key constraint 'metadata_file_lda_id_fkey' from table 'metadata_file' failed: %s" % ( str( e ) ) )
开发者ID:ARTbio,项目名称:galaxy,代码行数:27,代码来源:0003_security_and_libraries.py

示例5: downgrade

# 需要导入模块: from migrate import ForeignKeyConstraint [as 别名]
# 或者: from migrate.ForeignKeyConstraint import drop [as 别名]
def downgrade(migrate_engine):
    """Remove volume_type_rate_limit table."""
    meta = MetaData()
    meta.bind = migrate_engine

    qos_specs = Table('quality_of_service_specs', meta, autoload=True)

    if migrate_engine.name == 'mysql':
        # NOTE(alanmeadows): MySQL Cannot drop column qos_specs_id
        # until the foreign key volumes_types_ibfk_1 is removed.  We
        # remove the foreign key first, and then we drop the column.
        table = Table('volume_types', meta, autoload=True)
        ref_table = Table('volume_types', meta, autoload=True)
        params = {'columns': [table.c['qos_specs_id']],
                  'refcolumns': [ref_table.c['id']],
                  'name': 'volume_types_ibfk_1'}

        fkey = ForeignKeyConstraint(**params)
        fkey.drop()

    volume_types = Table('volume_types', meta, autoload=True)
    qos_specs_id = Column('qos_specs_id', String(36))

    volume_types.drop_column(qos_specs_id)
    qos_specs.drop()
开发者ID:apporc,项目名称:cinder,代码行数:27,代码来源:018_add_qos_specs.py

示例6: downgrade

# 需要导入模块: from migrate import ForeignKeyConstraint [as 别名]
# 或者: from migrate.ForeignKeyConstraint import drop [as 别名]
def downgrade(migrate_engine):
    if migrate_engine.name == 'sqlite':
        return
    meta = MetaData(bind=migrate_engine)
    for table_name, ref, child in TABLES:
        table = Table(table_name, meta, autoload=True)

        column_name, ref_table_name, ref_column_name = ref
        column = table.c[column_name]

        ref_table = Table(ref_table_name, meta, autoload=True)
        ref_column = ref_table.c[ref_column_name]

        params = {'columns': [column], 'refcolumns': [ref_column]}
        if migrate_engine.name == 'mysql':
            params['name'] = "_".join(('fk', table_name, column_name))
        with migrate_engine.begin():
            fkey = ForeignKeyConstraint(**params)
            fkey.drop()

        with migrate_engine.begin():
            restore_rows(migrate_engine, meta, table_name)

        # compute_node_stats has a missing foreign key and is a child of
        # of compute_nodes. Don't bother processing it as a child since
        # only want to restore the dump once
        if child and table_name != 'compute_nodes':
            child_table_name, child_column_name, child_ref_column_name = child

            with migrate_engine.begin():
                restore_rows(migrate_engine, meta, child_table_name)
开发者ID:BATYD-Turksat,项目名称:nova_servo,代码行数:33,代码来源:209_add_missing_foreign_keys.py

示例7: upgrade

# 需要导入模块: from migrate import ForeignKeyConstraint [as 别名]
# 或者: from migrate.ForeignKeyConstraint import drop [as 别名]
def upgrade(migrate_engine):
    meta = MetaData(migrate_engine)
    trait_type = Table(
        'trait_type', meta,
        Column('id', Integer, primary_key=True),
        Column('desc', String(255)),
        Column('data_type', Integer),
        UniqueConstraint('desc', 'data_type', name="tt_unique")
    )
    trait = Table('trait', meta, autoload=True)
    unique_name = Table('unique_name', meta, autoload=True)
    trait_type.create(migrate_engine)
    # Trait type extracts data from Trait and Unique name.
    # We take all trait names from Unique Name, and data types
    # from Trait. We then remove dtype and name from trait, and
    # remove the name field.

    conn = migrate_engine.connect()
    sql = ("INSERT INTO trait_type "
           "SELECT unique_name.id, unique_name.key, trait.t_type FROM trait "
           "INNER JOIN unique_name "
           "ON trait.name_id = unique_name.id "
           "GROUP BY unique_name.id, unique_name.key, trait.t_type")
    conn.execute(sql)
    conn.close()

    # Now we need to drop the foreign key constraint, rename
    # the trait.name column, and re-add a new foreign
    # key constraint
    params = {'columns': [trait.c.name_id],
              'refcolumns': [unique_name.c.id]}
    if migrate_engine.name == 'mysql':
        params['name'] = "trait_ibfk_1"  # foreign key to the unique name table
    fkey = ForeignKeyConstraint(**params)
    fkey.drop()

    Column('trait_type_id', Integer).create(trait)

    # Move data from name_id column into trait_type_id column
    query = select([trait.c.id, trait.c.name_id])
    for key, value in migration.paged(query):
        trait.update().where(trait.c.id == key)\
            .values({"trait_type_id": value}).execute()

    trait.c.name_id.drop()

    params = {'columns': [trait.c.trait_type_id],
              'refcolumns': [trait_type.c.id]}
    if migrate_engine.name == 'mysql':
        params['name'] = "_".join(('fk', 'trait_type', 'id'))

    fkey = ForeignKeyConstraint(**params)
    fkey.create()

    # Drop the t_type column to data_type.
    trait.c.t_type.drop()

    # Finally, drop the unique_name table - we don't need it
    # anymore.
    unique_name.drop()
开发者ID:akhilhingane,项目名称:ceilometer,代码行数:62,代码来源:023_add_trait_types.py

示例8: downgrade

# 需要导入模块: from migrate import ForeignKeyConstraint [as 别名]
# 或者: from migrate.ForeignKeyConstraint import drop [as 别名]
def downgrade(migrate_engine):
    if migrate_engine.name == "sqlite":
        return
    meta = MetaData(bind=migrate_engine)
    storage_pools = Table("storage_pools", meta, autoload=True)
    storage_groups = Table("storage_groups", meta, autolaod=True)
    params = {"columns": [storage_pools.c.primary_storage_group_id], "refcolumns": [storage_groups.c.id]}
    fkey = ForeignKeyConstraint(**params)
    fkey.drop()
开发者ID:01org,项目名称:virtual-storage-manager,代码行数:11,代码来源:028_add_missing_foreign_key.py

示例9: upgrade

# 需要导入模块: from migrate import ForeignKeyConstraint [as 别名]
# 或者: from migrate.ForeignKeyConstraint import drop [as 别名]
def upgrade(migrate_engine):
    meta = MetaData(bind=migrate_engine)
    event_type = Table(
        'event_type', meta,
        Column('id', Integer, primary_key=True),
        Column('desc', String(255), unique=True),
        mysql_engine='InnoDB',
        mysql_charset='utf8',
    )
    event_type.create()
    event = Table('event', meta, autoload=True)
    unique_name = Table('unique_name', meta, autoload=True)

    # Event type is a specialization of Unique name, so
    # we insert into the event_type table all the distinct
    # unique names from the event.unique_name field along
    # with the key from the unique_name table, and
    # then rename the event.unique_name field to event.event_type
    conn = migrate_engine.connect()
    sql = ("INSERT INTO event_type "
           "SELECT unique_name.id, unique_name.key FROM event "
           "INNER JOIN unique_name "
           "ON event.unique_name_id = unique_name.id "
           "GROUP BY unique_name.id")
    conn.execute(sql)
    conn.close()
    # Now we need to drop the foreign key constraint, rename
    # the event.unique_name column, and re-add a new foreign
    # key constraint
    params = {'columns': [event.c.unique_name_id],
              'refcolumns': [unique_name.c.id]}
    if migrate_engine.name == 'mysql':
        params['name'] = "event_ibfk_1"
    fkey = ForeignKeyConstraint(**params)
    fkey.drop()

    Column('event_type_id', Integer).create(event)

    # Move data from unique_name_id column into event_type_id column
    # and delete the entry from the unique_name table
    query = select([event.c.id, event.c.unique_name_id])
    for key, value in migration.paged(query):
        event.update().where(event.c.id == key)\
            .values({"event_type_id": value}).execute()
        unique_name.delete()\
            .where(unique_name.c.id == key).execute()

    params = {'columns': [event.c.event_type_id],
              'refcolumns': [event_type.c.id]}
    if migrate_engine.name == 'mysql':
        params['name'] = "_".join(('fk', 'event_type', 'id'))
    fkey = ForeignKeyConstraint(**params)
    fkey.create()

    event.c.unique_name_id.drop()
开发者ID:Adrian-Turjak,项目名称:ceilometer,代码行数:57,代码来源:021_add_event_types.py

示例10: downgrade

# 需要导入模块: from migrate import ForeignKeyConstraint [as 别名]
# 或者: from migrate.ForeignKeyConstraint import drop [as 别名]
def downgrade(migrate_engine):
    """Convert volume_type from UUID back to int."""
    meta = MetaData()
    meta.bind = migrate_engine

    volumes = Table("volumes", meta, autoload=True)
    volume_types = Table("volume_types", meta, autoload=True)
    extra_specs = Table("volume_type_extra_specs", meta, autoload=True)

    fkey_remove_list = [volumes.c.volume_type_id, volume_types.c.id, extra_specs.c.volume_type_id]

    for column in fkey_remove_list:
        fkeys = list(column.foreign_keys)
        if fkeys:
            fkey_name = fkeys[0].constraint.name
            fkey = ForeignKeyConstraint(columns=[column], refcolumns=[volume_types.c.id], name=fkey_name)

            try:
                fkey.drop()
            except Exception:
                if migrate_engine.url.get_dialect().name.startswith("sqlite"):
                    pass
                else:
                    raise

    vtype_list = list(volume_types.select().execute())
    new_id = 1

    for t in vtype_list:
        volumes.update().where(volumes.c.volume_type_id == t["id"]).values(volume_type_id=new_id).execute()

        extra_specs.update().where(extra_specs.c.volume_type_id == t["id"]).values(volume_type_id=new_id).execute()

        volume_types.update().where(volume_types.c.id == t["id"]).values(id=new_id).execute()

        new_id += 1

    volumes.c.volume_type_id.alter(Integer)
    volume_types.c.id.alter(Integer)
    extra_specs.c.volume_type_id.alter(Integer)

    for column in fkey_remove_list:
        fkeys = list(column.foreign_keys)
        if fkeys:
            fkey_name = fkeys[0].constraint.name
            fkey = ForeignKeyConstraint(columns=[column], refcolumns=[volume_types.c.id], name=fkey_name)
            try:
                fkey.create()
                LOG.info("Created foreign key %s" % fkey_name)
            except Exception:
                if migrate_engine.url.get_dialect().name.startswith("sqlite"):
                    pass
                else:
                    raise
开发者ID:Kumar-Acharya,项目名称:cinder,代码行数:56,代码来源:004_volume_type_to_uuid.py

示例11: _remove_foreign_key_constraints

# 需要导入模块: from migrate import ForeignKeyConstraint [as 别名]
# 或者: from migrate.ForeignKeyConstraint import drop [as 别名]
    def _remove_foreign_key_constraints(engine, meta, table_name):
        inspector = reflection.Inspector.from_engine(engine)

        for fk in inspector.get_foreign_keys(table_name):
            source_table = Table(table_name, meta, autoload=True)
            target_table = Table(fk['referred_table'], meta, autoload=True)

            fkey = ForeignKeyConstraint(
                columns=_get_columns(source_table, fk['constrained_columns']),
                refcolumns=_get_columns(target_table, fk['referred_columns']),
                name=fk['name'])
            fkey.drop()
开发者ID:375670450,项目名称:nova,代码行数:14,代码来源:292_drop_nova_volumes_tables.py

示例12: downgrade

# 需要导入模块: from migrate import ForeignKeyConstraint [as 别名]
# 或者: from migrate.ForeignKeyConstraint import drop [as 别名]
def downgrade(migrate_engine):
    # Operations to reverse the above upgrade go here.
    meta.bind = migrate_engine

    tt = Table('proc_SelectedHistoriesTable', meta, autoload=True)

    con = ForeignKeyConstraint([tt.c.selected_arar_id], [t.c.id])
    con.drop()

    t.drop()
    th.drop()
    tt.c.selected_arar_id.drop()
开发者ID:softtrainee,项目名称:arlab,代码行数:14,代码来源:057_add_arar_tables.py

示例13: upgrade

# 需要导入模块: from migrate import ForeignKeyConstraint [as 别名]
# 或者: from migrate.ForeignKeyConstraint import drop [as 别名]
def upgrade(migrate_engine):
    meta = sa.MetaData(bind=migrate_engine)
    load_tables = dict((table_name, sa.Table(table_name, meta,
                                             autoload=True))
                       for table_name in TABLES)

    if migrate_engine.name != 'sqlite':
        for table_name, indexes in INDEXES.items():
            table = load_tables[table_name]
            for column, ref_table_name, ref_column_name in indexes:
                ref_table = load_tables[ref_table_name]
                params = {'columns': [table.c[column]],
                          'refcolumns': [ref_table.c[ref_column_name]]}

                if migrate_engine.name == "mysql" and \
                        table_name != 'alarm_history':
                    params['name'] = "_".join(('fk', table_name, column))
                elif migrate_engine.name == "postgresql" and \
                        table_name == "sample":
                    # The fk contains the old table name
                    params['name'] = "_".join(('meter', column, 'fkey'))

                fkey = ForeignKeyConstraint(**params)
                fkey.drop()

    sourceassoc = load_tables['sourceassoc']
    if migrate_engine.name != 'sqlite':
        idx = sa.Index('idx_su', sourceassoc.c.source_id,
                       sourceassoc.c.user_id)
        idx.drop(bind=migrate_engine)
        idx = sa.Index('idx_sp', sourceassoc.c.source_id,
                       sourceassoc.c.project_id)
        idx.drop(bind=migrate_engine)

        params = {}
        if migrate_engine.name == "mysql":
            params = {'name': 'uniq_sourceassoc0sample_id'}
        uc = UniqueConstraint('sample_id', table=sourceassoc, **params)
        uc.create()

        params = {}
        if migrate_engine.name == "mysql":
            params = {'name': 'uniq_sourceassoc0sample_id0user_id'}
        uc = UniqueConstraint('sample_id', 'user_id',
                              table=sourceassoc, **params)
        uc.drop()
    sourceassoc.c.user_id.drop()
    sourceassoc.c.project_id.drop()

    for table_name in TABLES_DROP:
        sa.Table(table_name, meta, autoload=True).drop()
开发者ID:sahilbhagat0710,项目名称:ceilometer,代码行数:53,代码来源:035_drop_user_project_tables.py

示例14: upgrade

# 需要导入模块: from migrate import ForeignKeyConstraint [as 别名]
# 或者: from migrate.ForeignKeyConstraint import drop [as 别名]
def upgrade(migrate_engine):
    if migrate_engine.name == "sqlite":
        return
    meta = MetaData(bind=migrate_engine)
    load_tables = dict((table_name, Table(table_name, meta, autoload=True)) for table_name in TABLES)
    for table_name, indexes in INDEXES.items():
        table = load_tables[table_name]
        for column, ref_table_name, ref_column_name in indexes:
            ref_table = load_tables[ref_table_name]
            params = {"columns": [table.c[column]], "refcolumns": [ref_table.c[ref_column_name]]}
            if migrate_engine.name == "mysql":
                params["name"] = "_".join(("fk", table_name, column))
            fkey = ForeignKeyConstraint(**params)
            fkey.drop()
开发者ID:idegtiarov,项目名称:ceilometer,代码行数:16,代码来源:027_remove_alarm_fk_constraints.py

示例15: downgrade

# 需要导入模块: from migrate import ForeignKeyConstraint [as 别名]
# 或者: from migrate.ForeignKeyConstraint import drop [as 别名]
def downgrade(migrate_engine):
    meta = MetaData(bind=migrate_engine)
    load_tables = dict((table_name, Table(table_name, meta, autoload=True))
                       for table_name in TABLES)
    for table_name, indexes in INDEXES.items():
        table = load_tables[table_name]
        for column, ref_table_name, ref_column_name in indexes:
            ref_table = load_tables[ref_table_name]
            params = {'columns': [table.c[column]],
                      'refcolumns': [ref_table.c[ref_column_name]]}
            if migrate_engine.name == 'mysql':
                params['name'] = "_".join(('fk', table_name, column))
            fkey = ForeignKeyConstraint(**params)
            fkey.drop()
开发者ID:Arete97,项目名称:ceilometer,代码行数:16,代码来源:012_add_missing_foreign_keys.py


注:本文中的migrate.ForeignKeyConstraint.drop方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。