本文整理汇总了Python中migrate.changeset.UniqueConstraint.drop方法的典型用法代码示例。如果您正苦于以下问题:Python UniqueConstraint.drop方法的具体用法?Python UniqueConstraint.drop怎么用?Python UniqueConstraint.drop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类migrate.changeset.UniqueConstraint
的用法示例。
在下文中一共展示了UniqueConstraint.drop方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: drop_unique_constraint
# 需要导入模块: from migrate.changeset import UniqueConstraint [as 别名]
# 或者: from migrate.changeset.UniqueConstraint import drop [as 别名]
def drop_unique_constraint(migrate_engine, table_name, uc_name, *columns,
**col_name_col_instance):
"""Drop unique constraint from table.
This method drops UC from table and works for mysql, postgresql and sqlite.
In mysql and postgresql we are able to use "alter table" construction.
Sqlalchemy doesn't support some sqlite column types and replaces their
type with NullType in metadata. We process these columns and replace
NullType with the correct column type.
:param migrate_engine: sqlalchemy engine
:param table_name: name of table that contains uniq constraint.
:param uc_name: name of uniq constraint that will be dropped.
:param columns: columns that are in uniq constraint.
:param col_name_col_instance: contains pair column_name=column_instance.
column_instance is instance of Column. These params
are required only for columns that have unsupported
types by sqlite. For example BigInteger.
"""
meta = MetaData()
meta.bind = migrate_engine
t = Table(table_name, meta, autoload=True)
if migrate_engine.name == "sqlite":
override_cols = [
_get_not_supported_column(col_name_col_instance, col.name)
for col in t.columns
if isinstance(col.type, NullType)
]
for col in override_cols:
t.columns.replace(col)
uc = UniqueConstraint(*columns, table=t, name=uc_name)
uc.drop()
示例2: drop_unique_constraint
# 需要导入模块: from migrate.changeset import UniqueConstraint [as 别名]
# 或者: from migrate.changeset.UniqueConstraint import drop [as 别名]
def drop_unique_constraint(migrate_engine, table_name, uc_name, *columns,
**col_name_col_instance):
"""
This method drops UC from table and works for mysql, postgresql and sqlite.
In mysql and postgresql we are able to use "alter table" constuction. In
sqlite is only one way to drop UC:
1) Create new table with same columns, indexes and constraints
(except one that we want to drop).
2) Copy data from old table to new.
3) Drop old table.
4) Rename new table to the name of old table.
:param migrate_engine: sqlalchemy engine
:param table_name: name of table that contains uniq constarint.
:param uc_name: name of uniq constraint that will be dropped.
:param columns: columns that are in uniq constarint.
:param col_name_col_instance: contains pair column_name=column_instance.
column_instance is instance of Column. These params
are required only for columns that have unsupported
types by sqlite. For example BigInteger.
"""
if migrate_engine.name in ["mysql", "postgresql"]:
meta = MetaData()
meta.bind = migrate_engine
t = Table(table_name, meta, autoload=True)
uc = UniqueConstraint(*columns, table=t, name=uc_name)
uc.drop()
else:
_drop_unique_constraint_in_sqlite(migrate_engine, table_name, uc_name,
**col_name_col_instance)
示例3: upgrade
# 需要导入模块: from migrate.changeset import UniqueConstraint [as 别名]
# 或者: from migrate.changeset.UniqueConstraint import drop [as 别名]
def upgrade(migrate_engine):
meta = MetaData()
meta.bind = migrate_engine
dialect = migrate_engine.url.get_dialect().name
aggregates = Table('aggregates', meta, autoload=True)
aggregate_metadata = Table('aggregate_metadata', meta, autoload=True)
record_list = list(aggregates.select().execute())
for rec in record_list:
row = aggregate_metadata.insert()
row.execute({'created_at': rec['created_at'],
'updated_at': rec['updated_at'],
'deleted_at': rec['deleted_at'],
'deleted': rec['deleted'],
'key': 'operational_state',
'value': rec['operational_state'],
'aggregate_id': rec['id'],
})
aggregates.drop_column('operational_state')
aggregate_hosts = Table('aggregate_hosts', meta, autoload=True)
if dialect.startswith('sqlite'):
aggregate_hosts.drop_column('host')
aggregate_hosts.create_column(Column('host', String(255)))
elif dialect.startswith('postgres'):
ucon = UniqueConstraint('host',
name='aggregate_hosts_host_key',
table=aggregate_hosts)
ucon.drop()
else:
col = aggregate_hosts.c.host
UniqueConstraint(col, name='host').drop()
示例4: upgrade
# 需要导入模块: from migrate.changeset import UniqueConstraint [as 别名]
# 或者: from migrate.changeset.UniqueConstraint import drop [as 别名]
def upgrade(migrate_engine):
meta = MetaData()
meta.bind = migrate_engine
dialect = migrate_engine.url.get_dialect().name
aggregates = Table("aggregates", meta, autoload=True)
aggregate_metadata = Table("aggregate_metadata", meta, autoload=True)
record_list = list(aggregates.select().execute())
for rec in record_list:
row = aggregate_metadata.insert()
row.execute(
{
"created_at": rec["created_at"],
"updated_at": rec["updated_at"],
"deleted_at": rec["deleted_at"],
"deleted": rec["deleted"],
"key": "operational_state",
"value": rec["operational_state"],
"aggregate_id": rec["id"],
}
)
aggregates.drop_column("operational_state")
aggregate_hosts = Table("aggregate_hosts", meta, autoload=True)
if dialect.startswith("sqlite"):
aggregate_hosts.c.host.alter(unique=False)
elif dialect.startswith("postgres"):
ucon = UniqueConstraint("host", name="aggregate_hosts_host_key", table=aggregate_hosts)
ucon.drop()
else:
col = aggregate_hosts.c.host
UniqueConstraint(col, name="host").drop()
示例5: upgrade
# 需要导入模块: from migrate.changeset import UniqueConstraint [as 别名]
# 或者: from migrate.changeset.UniqueConstraint import drop [as 别名]
def upgrade(migrate_engine):
meta = MetaData()
meta.bind = migrate_engine
datastore_versions = Table('datastore_versions', meta, autoload=True)
# drop the unique index on the name column - unless we are
# using sqlite - it doesn't support dropping unique constraints
uc = None
if migrate_engine.name == "mysql":
uc = UniqueConstraint('name', table=datastore_versions, name='name')
elif migrate_engine.name == "postgresql":
uc = UniqueConstraint('name', table=datastore_versions,
name='datastore_versions_name_key')
if uc:
try:
uc.drop()
except (OperationalError, InternalError) as e:
logger.info(e)
示例6: upgrade
# 需要导入模块: from migrate.changeset import UniqueConstraint [as 别名]
# 或者: from migrate.changeset.UniqueConstraint import drop [as 别名]
def upgrade(migrate_engine):
meta = MetaData()
meta.bind = migrate_engine
dialect = migrate_engine.url.get_dialect().name
aggregates = Table('aggregates', meta, autoload=True)
if dialect.startswith('sqlite'):
aggregates.c.name.alter(unique=False)
elif dialect.startswith('postgres'):
ucon = UniqueConstraint('name',
name='aggregates_name_key',
table=aggregates)
ucon.drop()
else:
col2 = aggregates.c.name
UniqueConstraint(col2, name='name').drop()
示例7: drop_unique_constraint
# 需要导入模块: from migrate.changeset import UniqueConstraint [as 别名]
# 或者: from migrate.changeset.UniqueConstraint import drop [as 别名]
def drop_unique_constraint(migrate_engine, table_name, uc_name, *columns,
**col_name_col_instance):
"""
Drop unique constraint from table.
"""
meta = MetaData()
meta.bind = migrate_engine
t = Table(table_name, meta, autoload=True)
if migrate_engine.name == "sqlite":
override_cols = [
_get_not_supported_column(col_name_col_instance, col.name)
for col in t.columns
if isinstance(col.type, NullType)
]
for col in override_cols:
t.columns.replace(col)
uc = UniqueConstraint(*columns, table=t, name=uc_name)
uc.drop()