• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python constraint.UniqueConstraint类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中migrate.changeset.constraint.UniqueConstraint的典型用法代码示例。如果您正苦于以下问题:Python UniqueConstraint类的具体用法?Python UniqueConstraint怎么用?Python UniqueConstraint使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: upgrade

def upgrade(migrate_engine):
    meta.bind = migrate_engine
    dialect = migrate_engine.url.get_dialect().name

    domains_table = Table('domains', meta, autoload=True)

    if not dialect.startswith('sqlite'):
        constraint = UniqueConstraint('name', name='name', table=domains_table)
        constraint.drop()
    else:
        # SQLite can't drop a constraint. Yay. This will be fun..

        # Create a new name column without the unique index
        name_tmp_column = Column('name_tmp', String(255))
        name_tmp_column.create(domains_table)

        # Copy the data over.
        query = update(domains_table).values(name_tmp=domains_table.c.name)
        migrate_engine.execute(query)

        # Delete the name column
        domains_table.c.name.drop()

        # Rename the name_tmp column to name
        domains_table.c.name_tmp.alter(name='name')
开发者ID:bluzader,项目名称:designate,代码行数:25,代码来源:017_drop_unique_domain_name_index.py


示例2: downgrade

def downgrade(migrate_engine):
    meta.bind = migrate_engine

    domains_table = Table('domains', meta, autoload=True)

    constraint = UniqueConstraint('name', name='name', table=domains_table)
    constraint.create()
开发者ID:NeCTAR-RC,项目名称:designate,代码行数:7,代码来源:017_drop_unique_domain_name_index.py


示例3: downgrade

def downgrade(migrate_engine):
    meta.bind = migrate_engine

    keys = Enum(name='key', metadata=meta, *ZONE_ATTRIBUTE_KEYS)
    types = Enum(name='types', metadata=meta, *ZONE_TYPES)

    domains_attributes_table = Table('domain_attributes', meta, autoload=True)
    domains_table = Table('domains', meta, autoload=True)

    domains = select(columns=[domains_table.c.id, domains_table.c.type])\
        .where(domains_table.c.type == 'SECONDARY')\
        .execute().fetchall()

    for dom in domains:
        delete = domains_table.delete()\
            .where(domains_table.id == dom.id)
        delete.execute()

    domains_table.c.type.drop()
    domains_table.c.transferred_at.drop()

    domains_attributes_table.drop()
    keys.drop()
    types.drop()

    dialect = migrate_engine.url.get_dialect().name
    if dialect.startswith('sqlite'):
        constraint = UniqueConstraint(
            'name', 'deleted', name='unique_domain_name', table=domains_table)

        # Add missing unique index
        constraint.create()
开发者ID:jkhelil,项目名称:designate,代码行数:32,代码来源:052_secondary_zones.py


示例4: upgrade

def upgrade(migrate_engine):
    meta = MetaData(bind=migrate_engine)
    submissions = Table('submissions', meta, autoload=True)
    slugc = Column('slug', UnicodeText)
    slugc.create(submissions)
    slugu = UniqueConstraint(slugc)
    slugu.create()
开发者ID:azmikamis,项目名称:raggregate,代码行数:7,代码来源:004_Add_slug_column_on_Submissions.py


示例5: unique_collections_slug

def unique_collections_slug(db):
    """Add unique constraint to collection slug"""
    metadata = MetaData(bind=db.bind)
    collection_table = inspect_table(metadata, "core__collections")
    existing_slugs = {}
    slugs_to_change = []

    for row in db.execute(collection_table.select()):
        # if duplicate slug, generate a unique slug
        if row.creator in existing_slugs and row.slug in \
           existing_slugs[row.creator]:
            slugs_to_change.append(row.id)
        else:
            if not row.creator in existing_slugs:
                existing_slugs[row.creator] = [row.slug]
            else:
                existing_slugs[row.creator].append(row.slug)

    for row_id in slugs_to_change:
        new_slug = unicode(uuid.uuid4())
        db.execute(collection_table.update().
                   where(collection_table.c.id == row_id).
                   values(slug=new_slug))
    # sqlite does not like to change the schema when a transaction(update) is
    # not yet completed
    db.commit()

    constraint = UniqueConstraint('creator', 'slug',
                                  name='core__collection_creator_slug_key',
                                  table=collection_table)
    constraint.create()

    db.commit()
开发者ID:spaetz,项目名称:mediagoblin_blog,代码行数:33,代码来源:migrations.py


示例6: fix_CollectionItem_v0_constraint

def fix_CollectionItem_v0_constraint(db_conn):
    """Add the forgotten Constraint on CollectionItem"""

    global collectionitem_unique_constraint_done
    if collectionitem_unique_constraint_done:
        # Reset it. Maybe the whole thing gets run again
        # For a different db?
        collectionitem_unique_constraint_done = False
        return

    metadata = MetaData(bind=db_conn.bind)

    CollectionItem_table = inspect_table(metadata, 'core__collection_items')

    constraint = UniqueConstraint('collection', 'media_entry',
        name='core__collection_items_collection_media_entry_key',
        table=CollectionItem_table)

    try:
        constraint.create()
    except ProgrammingError:
        # User probably has an install that was run since the
        # collection tables were added, so we don't need to run this migration.
        pass

    db_conn.commit()
开发者ID:spaetz,项目名称:mediagoblin_blog,代码行数:26,代码来源:migrations.py


示例7: upgrade

def upgrade(migrate_engine):
    meta.bind = migrate_engine

    # Load the TSIG Keys tables
    tsigkeys_table = Table('tsigkeys', meta, autoload=True)

    scopes = Enum(name='tsig_scopes', metadata=meta, *TSIG_SCOPES)
    scopes.create()

    # Create the scope and resource columns
    scope_col = Column('scope', scopes, nullable=False, server_default='POOL')
    scope_col.create(tsigkeys_table)

    # Start with nullable=True and populate_default=True, then convert
    # to nullable=False once all rows have been populted with a resource_id
    resource_id_col = Column('resource_id', UUID, default=default_pool_id,
                             nullable=True)
    resource_id_col.create(tsigkeys_table, populate_default=True)

    # Now that we've populated the default pool id in existing rows, MySQL
    # will let us convert this over to nullable=False
    tsigkeys_table.c.resource_id.alter(nullable=False)

    dialect = migrate_engine.url.get_dialect().name
    if dialect.startswith('sqlite'):
        # Add missing unique index
        constraint = UniqueConstraint('name', name='unique_tsigkey_name',
                                      table=tsigkeys_table)
        constraint.create()
开发者ID:jkhelil,项目名称:designate,代码行数:29,代码来源:051_scoped_tsig.py


示例8: upgrade

def upgrade(migrate_engine):
    meta = sqlalchemy.MetaData(bind=migrate_engine)

    event = sqlalchemy.Table('event', meta, autoload=True)
    message_id = sqlalchemy.Column('message_id', sqlalchemy.String(50))
    event.create_column(message_id)

    cons = UniqueConstraint('message_id', table=event)
    cons.create()

    index = sqlalchemy.Index('idx_event_message_id', models.Event.message_id)
    index.create(bind=migrate_engine)

    # Populate the new column ...
    trait = sqlalchemy.Table('trait', meta, autoload=True)
    unique_name = sqlalchemy.Table('unique_name', meta, autoload=True)
    join = trait.join(unique_name, unique_name.c.id == trait.c.name_id)
    traits = sqlalchemy.select([trait.c.event_id, trait.c.t_string],
                               whereclause=(unique_name.c.key == 'message_id'),
                               from_obj=join)

    for event_id, value in traits.execute():
        event.update().\
            where(event.c.id == event_id).\
            values(message_id=value).\
            execute()
开发者ID:siodoon,项目名称:ceilometer,代码行数:26,代码来源:014_add_event_message_id.py


示例9: upgrade

def upgrade(migrate_engine):
    meta.bind = migrate_engine

    domains_table = Table('domains', meta, autoload=True)

    # Get the default pool_id from the config file
    default_pool_id = cfg.CONF['service:central'].default_pool_id

    # Create the pool_id column
    pool_id_column = Column('pool_id',
                            UUID(),
                            default=default_pool_id,
                            nullable=True)
    pool_id_column.create(domains_table, populate_default=True)

    # Alter the table to drop default value after populating it
    domains_table.c.pool_id.alter(default=None)

    dialect = migrate_engine.url.get_dialect().name
    if dialect.startswith('sqlite'):
        # Add missing unique index
        constraint = UniqueConstraint('name', 'deleted',
                                      name='unique_domain_name',
                                      table=domains_table)
        constraint.create()
开发者ID:Vegasq,项目名称:designate,代码行数:25,代码来源:044_add_pool_id_to_domains.py


示例10: upgrade

def upgrade(migrate_engine):
    metadata.bind = migrate_engine

    table = Table('notification', metadata, autoload=True)

    cons = UniqueConstraint('event_id', 'user_id', table=table)
    cons.create()
开发者ID:alkadis,项目名称:vcv,代码行数:7,代码来源:077_unique_notifications.py


示例11: upgrade

def upgrade(migrate_engine):
    metadata = MetaData()
    metadata.bind = migrate_engine
    user_table = Table('user', metadata, autoload=True)
#    name_column = user_table.c.name
    unique_name_constraint = UniqueConstraint('name', table=user_table)
    unique_name_constraint.create()
开发者ID:AdamJensen-dk,项目名称:ckan,代码行数:7,代码来源:045_user_name_unique.py


示例12: downgrade

def downgrade(migrate_engine):
    # Operations to reverse the above upgrade go here.
    meta = MetaData(bind=migrate_engine)
    submissions = Table('submissions', meta, autoload=True)
    slugu = UniqueConstraint(submissions.c.slug)
    slugu.drop()
    submissions.c.slug.drop()
开发者ID:azmikamis,项目名称:raggregate,代码行数:7,代码来源:004_Add_slug_column_on_Submissions.py


示例13: downgrade

def downgrade(migrate_engine):
    meta = sqlalchemy.MetaData(bind=migrate_engine)
    event = sqlalchemy.Table('event', meta, autoload=True)
    message_id = sqlalchemy.Column('message_id', sqlalchemy.String(50))
    cons = UniqueConstraint('message_id', table=event)
    cons.drop()
    index = sqlalchemy.Index('idx_event_message_id', models.Event.message_id)
    index.drop(bind=migrate_engine)
    event.drop_column(message_id)
开发者ID:Adrian-Turjak,项目名称:ceilometer,代码行数:9,代码来源:014_add_event_message_id.py


示例14: upgrade

def upgrade(migrate_engine):
    # ignore reflection warnings
    with warnings.catch_warnings():
        warnings.simplefilter("ignore", category=sa_exc.SAWarning)
        metadata = MetaData()
        metadata.bind = migrate_engine
        user_table = Table('user', metadata, autoload=True)
    #    name_column = user_table.c.name
        unique_name_constraint = UniqueConstraint('name', table=user_table)
        unique_name_constraint.create()
开发者ID:CIOIL,项目名称:DataGovIL,代码行数:10,代码来源:045_user_name_unique.py


示例15: upgrade

def upgrade(migrate_engine):
    meta.bind = migrate_engine

    pool_attributes_table = Table('pool_attributes', meta, autoload=True)

    # Create UniqueConstraint
    constraint = UniqueConstraint('pool_id', 'key', 'value',
                                  name='unique_pool_attribute',
                                  table=pool_attributes_table)

    constraint.create()
开发者ID:AnatolyZimin,项目名称:designate,代码行数:11,代码来源:045_add_uniqueconstraint_to_pool_attributes.py


示例16: downgrade

def downgrade(migrate_engine):
    meta.bind = migrate_engine
    dialect = migrate_engine.url.get_dialect().name

    if dialect.startswith('sqlite'):
        records_table = Table('records', meta, autoload=True)

        # Drop the unique index
        constraint = UniqueConstraint('hash',
                                      name='unique_recordset',
                                      table=records_table)
        constraint.drop()
开发者ID:akshatknsl,项目名称:designate,代码行数:12,代码来源:035_add_unique_record_sqlite.py


示例17: downgrade

def downgrade(migrate_engine):
    meta.bind = migrate_engine
    dialect = migrate_engine.url.get_dialect().name
    zones_table = Table('domains', meta, autoload=True)
    records_table = Table('records', meta, autoload=True)

    RECORD_TYPES = ['A', 'AAAA', 'CNAME', 'MX', 'SRV', 'TXT', 'SPF', 'NS',
                    'PTR', 'SSHFP']

    recordsets_table = Table('recordsets', meta, autoload=True)

    # Delete all SOA records
    recordsets_table.delete().where(recordsets_table.c.type == 'SOA').execute()

    # Remove SOA from the ENUM
    recordsets_table.c.type.alter(type=Enum(name='recordset_types',
                                            *RECORD_TYPES))

    # Remove non-delegated NS records
    # Get all the zones
    zones = select(
        columns=[
            zones_table.c.id,
            zones_table.c.created_at,
            zones_table.c.tenant_id,
            zones_table.c.name,
            zones_table.c.email,
            zones_table.c.serial,
            zones_table.c.refresh,
            zones_table.c.retry,
            zones_table.c.expire,
            zones_table.c.minimum
        ]
    ).execute().fetchall()

    for zone in zones:
        # for each zone, get all non-delegated NS recordsets
        results = recordsets_table.select().\
            where(recordsets_table.c.type == 'NS').\
            where(recordsets_table.c.name == zone.name).execute()
        for r in results:
            records_table.delete().\
                where(records_table.c.recordset_id == r.id).\
                where(records_table.c.managed == 1).execute()
        # NOTE: The value 1 is used instead of True because flake8 complains

    # Re-add the constraint for sqlite
    if dialect.startswith('sqlite'):
        constraint = UniqueConstraint('domain_id', 'name', 'type',
                                      name='unique_recordset',
                                      table=recordsets_table)

        constraint.create()
开发者ID:Vegasq,项目名称:designate,代码行数:53,代码来源:039_support_soa_records.py


示例18: pw_hash_nullable

def pw_hash_nullable(db):
    """Make pw_hash column nullable"""
    metadata = MetaData(bind=db.bind)
    user_table = inspect_table(metadata, "core__users")

    user_table.c.pw_hash.alter(nullable=True)

    # sqlite+sqlalchemy seems to drop this constraint during the
    # migration, so we add it back here for now a bit manually.
    if db.bind.url.drivername == 'sqlite':
        constraint = UniqueConstraint('username', table=user_table)
        constraint.create()

    db.commit()
开发者ID:spaetz,项目名称:mediagoblin_blog,代码行数:14,代码来源:migrations.py


示例19: upgrade

def upgrade(migrate_engine):
    meta = MetaData()
    meta.bind = migrate_engine
    service_statuses_table = Table('service_statuses', meta, autoload=True)

    # Add UniqueConstraint based on service_name and hostname.
    constraint = UniqueConstraint('service_name', 'hostname',
                                  table=service_statuses_table,
                                  name="unique_service_status")
    try:
        constraint.create()
    except exc.IntegrityError as e:
        LOG.error(EXPLANATION, e)
        # Use sys.exit so we don't blow up with a huge trace
        sys.exit(1)
开发者ID:mrlesmithjr,项目名称:designate,代码行数:15,代码来源:100_unique_service_status.py


示例20: upgrade

def upgrade(migrate_engine):
    meta.bind = migrate_engine

    keys = Enum(name='key', *ZONE_ATTRIBUTE_KEYS)

    domain_attributes_table = Table(
        'domain_attributes', meta,
        Column('id', UUID(), default=utils.generate_uuid, primary_key=True),
        Column('version', Integer(), default=1, nullable=False),
        Column('created_at', DateTime, default=lambda: timeutils.utcnow()),
        Column('updated_at', DateTime, onupdate=lambda: timeutils.utcnow()),

        Column('key', keys),
        Column('value', String(255), nullable=False),
        Column('domain_id', UUID(), nullable=False),

        UniqueConstraint('key', 'value', 'domain_id',
                         name='unique_attributes'),
        ForeignKeyConstraint(['domain_id'], ['domains.id'],
                             ondelete='CASCADE'),

        mysql_engine='INNODB',
        mysql_charset='utf8'
    )

    domains_table = Table('domains', meta, autoload=True)
    types = Enum(name='types', metadata=meta, *ZONE_TYPES)
    types.create()

    # Add type and transferred_at to domains
    type_ = Column('type', types, default='PRIMARY', server_default='PRIMARY')
    transferred_at = Column('transferred_at', DateTime, default=None)

    type_.create(domains_table, populate_default=True)
    transferred_at.create(domains_table, populate_default=True)

    domain_attributes_table.create()

    dialect = migrate_engine.url.get_dialect().name
    if dialect.startswith('sqlite'):
        constraint = UniqueConstraint(
            'name', 'deleted', name='unique_domain_name', table=domains_table)

        # Add missing unique index
        constraint.create()
开发者ID:jkhelil,项目名称:designate,代码行数:45,代码来源:052_secondary_zones.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python visitor.get_engine_visitor函数代码示例发布时间:2022-05-27
下一篇:
Python constraint.ForeignKeyConstraint类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap