本文整理汇总了Python中migrate.changeset.constraint.UniqueConstraint.create方法的典型用法代码示例。如果您正苦于以下问题:Python UniqueConstraint.create方法的具体用法?Python UniqueConstraint.create怎么用?Python UniqueConstraint.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类migrate.changeset.constraint.UniqueConstraint
的用法示例。
在下文中一共展示了UniqueConstraint.create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: fix_CollectionItem_v0_constraint
# 需要导入模块: from migrate.changeset.constraint import UniqueConstraint [as 别名]
# 或者: from migrate.changeset.constraint.UniqueConstraint import create [as 别名]
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()
示例2: downgrade
# 需要导入模块: from migrate.changeset.constraint import UniqueConstraint [as 别名]
# 或者: from migrate.changeset.constraint.UniqueConstraint import create [as 别名]
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()
示例3: unique_collections_slug
# 需要导入模块: from migrate.changeset.constraint import UniqueConstraint [as 别名]
# 或者: from migrate.changeset.constraint.UniqueConstraint import create [as 别名]
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()
示例4: upgrade
# 需要导入模块: from migrate.changeset.constraint import UniqueConstraint [as 别名]
# 或者: from migrate.changeset.constraint.UniqueConstraint import create [as 别名]
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()
示例5: upgrade
# 需要导入模块: from migrate.changeset.constraint import UniqueConstraint [as 别名]
# 或者: from migrate.changeset.constraint.UniqueConstraint import create [as 别名]
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()
示例6: downgrade
# 需要导入模块: from migrate.changeset.constraint import UniqueConstraint [as 别名]
# 或者: from migrate.changeset.constraint.UniqueConstraint import create [as 别名]
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()
示例7: downgrade
# 需要导入模块: from migrate.changeset.constraint import UniqueConstraint [as 别名]
# 或者: from migrate.changeset.constraint.UniqueConstraint import create [as 别名]
def downgrade(migrate_engine):
meta.bind = migrate_engine
RESOURCE_STATUSES = ['ACTIVE', 'PENDING', 'DELETED']
# Get associated database tables
domains_table = Table('domains', meta, autoload=True)
records_table = Table('records', meta, autoload=True)
# Downgrade the domains table.
domains_table.c.status.alter(
type=Enum(name='resource_statuses', *RESOURCE_STATUSES),
default='ACTIVE', server_default='ACTIVE')
domains_table.c.action.drop()
# Re-add constraint for sqlite.
dialect = migrate_engine.url.get_dialect().name
if dialect.startswith('sqlite'):
constraint = UniqueConstraint(
'name', 'deleted', name='unique_domain_name', table=domains_table)
constraint.create()
# Downgrade the records table.
records_table.c.status.alter(
type=Enum(name='resource_statuses', *RESOURCE_STATUSES),
default='ACTIVE', server_default='ACTIVE')
records_table.c.action.drop()
records_table.c.serial.drop()
# Re-add constraint for sqlite.
if dialect.startswith('sqlite'):
constraint = UniqueConstraint(
'hash', name='unique_record', table=records_table)
constraint.create()
示例8: upgrade
# 需要导入模块: from migrate.changeset.constraint import UniqueConstraint [as 别名]
# 或者: from migrate.changeset.constraint.UniqueConstraint import create [as 别名]
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()
示例9: upgrade
# 需要导入模块: from migrate.changeset.constraint import UniqueConstraint [as 别名]
# 或者: from migrate.changeset.constraint.UniqueConstraint import create [as 别名]
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()
示例10: upgrade
# 需要导入模块: from migrate.changeset.constraint import UniqueConstraint [as 别名]
# 或者: from migrate.changeset.constraint.UniqueConstraint import create [as 别名]
def upgrade(migrate_engine):
metadata.bind = migrate_engine
table = Table('notification', metadata, autoload=True)
cons = UniqueConstraint('event_id', 'user_id', table=table)
cons.create()
示例11: downgrade
# 需要导入模块: from migrate.changeset.constraint import UniqueConstraint [as 别名]
# 或者: from migrate.changeset.constraint.UniqueConstraint import create [as 别名]
def downgrade(migrate_engine):
meta.bind = migrate_engine
# Domains Table
domains_table = Table("domains", meta, autoload=True)
rev_ind = Index("reverse_name_deleted", domains_table.c.reverse_name, domains_table.c.deleted)
rev_ind.drop(migrate_engine)
# Recordsets Table
rsets_table = Table("recordsets", meta, autoload=True)
rev_ind = Index("reverse_name_dom_id", rsets_table.c.reverse_name, rsets_table.c.domain_id)
rev_ind.drop(migrate_engine)
domains_table.c.reverse_name.drop()
rsets_table.c.reverse_name.drop()
# Recreate constraints for SQLite
dialect = migrate_engine.url.get_dialect().name
if dialect.startswith("sqlite"):
domains_constraint = UniqueConstraint("name", "deleted", name="unique_domain_name", table=domains_table)
recordsets_constraint = UniqueConstraint(
"domain_id", "name", "type", name="unique_recordset", table=rsets_table
)
domains_constraint.create()
recordsets_constraint.create()
示例12: upgrade
# 需要导入模块: from migrate.changeset.constraint import UniqueConstraint [as 别名]
# 或者: from migrate.changeset.constraint.UniqueConstraint import create [as 别名]
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()
示例13: upgrade
# 需要导入模块: from migrate.changeset.constraint import UniqueConstraint [as 别名]
# 或者: from migrate.changeset.constraint.UniqueConstraint import create [as 别名]
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()
示例14: upgrade
# 需要导入模块: from migrate.changeset.constraint import UniqueConstraint [as 别名]
# 或者: from migrate.changeset.constraint.UniqueConstraint import create [as 别名]
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()
示例15: upgrade
# 需要导入模块: from migrate.changeset.constraint import UniqueConstraint [as 别名]
# 或者: from migrate.changeset.constraint.UniqueConstraint import create [as 别名]
def upgrade(migrate_engine):
meta.bind = migrate_engine
dialect = migrate_engine.url.get_dialect().name
if dialect.startswith('sqlite'):
records_table = Table('records', meta, autoload=True)
# Add missing unique index
constraint = UniqueConstraint('hash',
name='unique_recordset',
table=records_table)
constraint.create()