本文整理汇总了Python中alembic.operations.Operations.drop_column方法的典型用法代码示例。如果您正苦于以下问题:Python Operations.drop_column方法的具体用法?Python Operations.drop_column怎么用?Python Operations.drop_column使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类alembic.operations.Operations
的用法示例。
在下文中一共展示了Operations.drop_column方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_missing_column
# 需要导入模块: from alembic.operations import Operations [as 别名]
# 或者: from alembic.operations.Operations import drop_column [as 别名]
def test_missing_column(self):
adapter = self._get_adapter()
adapter.build_table()
with adapter.engine.begin() as connection:
context = MigrationContext.configure(connection)
op = Operations(context)
op.drop_column(adapter.get_table().name, 'name')
doc = {
"_id": '123',
"domain": "domain",
"doc_type": "CommCareCase",
"name": 'bob'
}
with self.assertRaises(MissingColumnWarning):
adapter.best_effort_save(doc)
示例2: update_member
# 需要导入模块: from alembic.operations import Operations [as 别名]
# 或者: from alembic.operations.Operations import drop_column [as 别名]
def update_member(self, id, data):
member=self.get_member(id)
if member is None:
return None
# NOTE: BaseContext's init method sets its base to the base
# struct contained in the request, so we need to reset it here
# to the base struct that is actually in the database - DCarv
# NOTE: Remove base struct from cache! By John Doe
model.BASES.bases.pop(member.name)
# NOTE: Set old base struct as active! By John Doe
self.set_base(member.struct)
# NOTE: Check for base content changes! By John Doe
old_base=json2base(member.struct)
new_base=json2base(data['struct'])
# NOTE: List all fields that should be deleted! By John Doe
del_cols=[]
for old_col_name, old_col in old_base.content.__allstructs__.items():
if old_col_name not in new_base.content.__allsnames__:
del_cols.append(old_col)
# NOTE: If any field will be deleted, delete it from all documents in
# the base! By John Doe
if len(del_cols) > 0:
# NOTE: Create a fake request for DocumentCustomView and
# DocumentContext! By John Doe
url="/%s/doc&$$={\"limit\":null}" % new_base.metadata.name
for col in del_cols:
params={
'path': "[{\"path\":\"%s\",\"fn\":null,\"mode\":" +\
"\"delete\",\"args\":[]}]" % ("/".join(col.path))
}
request=DummyRequest(path=url, params=params)
request.method='PUT'
request.matchdict={"base": new_base.metadata.name}
doc_view=DocumentCustomView(
DocumentContextFactory(request),
request
)
doc_view.update_collection()
# NOTE: Check for relation field changes (to ALTER table if needed)!
# By John Doe
old_doc_table=get_doc_table(old_base.metadata.name, config.METADATA,
**old_base.relational_fields)
new_doc_table=get_doc_table(new_base.metadata.name, config.METADATA,
**new_base.relational_fields)
# NOTE: List relational fields that should be deleted! By John Doe
del_cols=[]
for old_col in old_doc_table.columns:
if old_col.name not in new_doc_table.columns:
del_cols.append(old_col)
# NOTE: List relational fields that should be added! By John Doe
new_cols=[]
for new_col in new_doc_table.columns:
if new_col.name not in old_doc_table.columns:
# NOTE: Get liblightbase.lbbase.fields object! By John Doe
field=new_base.relational_fields[new_col.name]
custom_col=get_custom_column(field)
new_cols.append(custom_col)
# NOTE: Create alembic connection and operation object! By John Doe
db_conn=config.ENGINE.connect()
alembic_ctx=MigrationContext.configure(db_conn)
alembic_op=Operations(alembic_ctx)
# NOTE: Drop columns! By John Doe
for col in del_cols:
alembic_op.drop_column(new_doc_table.name, col.name)
# TODO: New_col cannot be required! By John Doe
# NOTE: Add columns! By John Doe
for col in new_cols:
alembic_op.add_column(new_doc_table.name, col)
# TODO: Alter columns? By John Doe
db_conn.close()
# NOTE: Check for base name change! By John Doe
if member.name != data['name']:
old_name='lb_doc_%s' %(member.name)
new_name='lb_doc_%s' %(data['name'])
self.session.execute('ALTER TABLE %s RENAME TO %s' %(
old_name,
new_name
)
)
#.........这里部分代码省略.........
示例3: downgrade
# 需要导入模块: from alembic.operations import Operations [as 别名]
# 或者: from alembic.operations.Operations import drop_column [as 别名]
def downgrade(pyramid_env):
admin_context = get_admin_context()
op = Operations(admin_context)
with admin_context.begin_transaction():
op.drop_column('WS.WS.SYS_DAV_RES', 'RES_SIZE')