本文整理汇总了Python中migrate.versioning.schema.ControlledSchema.upgrade方法的典型用法代码示例。如果您正苦于以下问题:Python ControlledSchema.upgrade方法的具体用法?Python ControlledSchema.upgrade怎么用?Python ControlledSchema.upgrade使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类migrate.versioning.schema.ControlledSchema
的用法示例。
在下文中一共展示了ControlledSchema.upgrade方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from migrate.versioning.schema import ControlledSchema [as 别名]
# 或者: from migrate.versioning.schema.ControlledSchema import upgrade [as 别名]
def main():
import camelot
import logging
logging.basicConfig(level=logging.INFO)
#logging.getLogger('sqlalchemy.engine').setLevel(logging.DEBUG)
parser = CommandOptionParser(usage=usage,
description=description,
version=camelot.__version__)
(_options, args) = parser.parse_args()
if not args:
parser.print_help()
elif args[0]=='console':
setup_model()
sh = Shell()
sh.interact()
elif args[0]=='schema_display':
setup_model()
schema_display()
elif args[0] in ('version_control', 'db_version', 'version', 'upgrade'):
import settings
from migrate.versioning.repository import Repository
from migrate.versioning.schema import ControlledSchema
from migrate.versioning.exceptions import DatabaseNotControlledError
from sqlalchemy.exceptions import NoSuchTableError
migrate_engine = settings.ENGINE()
repository = Repository(settings.REPOSITORY)
schema = None
try:
schema = ControlledSchema(migrate_engine, repository)
except (NoSuchTableError, DatabaseNotControlledError):
print 'database not yet under version control, putting it under version_control first.'
if args[0]=='version_control' or schema is None:
migrate_connection = migrate_engine.connect()
transaction = migrate_connection.begin()
try:
schema = ControlledSchema.create(migrate_engine, repository)
transaction.commit()
except:
transaction.rollback()
raise
finally:
migrate_connection.close()
print 'database was put under version control'
if schema:
if args[0]=='db_version':
print schema.version
elif args[0]=='version':
print repository.latest
elif args[0]=='upgrade':
migrate_connection = migrate_engine.connect()
if len(args)>=2:
version = int(args[1])
else:
version = repository.latest
#
# perform each upgrade step in a separate transaction, since
# one upgrade might depend on an other being fully executed
#
try:
if schema.version == version:
print 'database is allready at requested version'
if schema.version <= version:
step = 1
else:
step = -1
for i in range(schema.version+step, version+step, step):
transaction = migrate_connection.begin()
try:
schema.upgrade(i)
transaction.commit()
if step==1:
print 'upgrade %s'%i
else:
print 'downgrade %s'%i
except:
transaction.rollback()
raise
finally:
migrate_connection.close()
else:
parser.print_help()