本文整理汇总了Python中migrate.versioning.api.version_control方法的典型用法代码示例。如果您正苦于以下问题:Python api.version_control方法的具体用法?Python api.version_control怎么用?Python api.version_control使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类migrate.versioning.api
的用法示例。
在下文中一共展示了api.version_control方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: db_version_control
# 需要导入模块: from migrate.versioning import api [as 别名]
# 或者: from migrate.versioning.api import version_control [as 别名]
def db_version_control(engine, abs_path, version=None):
"""Mark a database as under this repository's version control.
Once a database is under version control, schema changes should
only be done via change scripts in this repository.
:param engine: SQLAlchemy engine instance for a given database
:param abs_path: Absolute path to migrate repository
:param version: Initial database version
"""
repository = _find_migrate_repo(abs_path)
try:
versioning_api.version_control(engine, repository, version)
except versioning_exceptions.InvalidVersionError as ex:
raise exception.DBMigrationError("Invalid version : %s" % ex)
except versioning_exceptions.DatabaseAlreadyControlledError:
raise exception.DBMigrationError("Database is already controlled.")
return version
示例2: db_version_control
# 需要导入模块: from migrate.versioning import api [as 别名]
# 或者: from migrate.versioning.api import version_control [as 别名]
def db_version_control(version=None):
repository = _find_migrate_repo()
versioning_api.version_control(get_engine(), repository, version)
return version
示例3: setup_migration_version_control
# 需要导入模块: from migrate.versioning import api [as 别名]
# 或者: from migrate.versioning.api import version_control [as 别名]
def setup_migration_version_control(self, version=None):
import migrate.exceptions
import migrate.versioning.api as mig
# set up db version control (if not already)
try:
mig.version_control(self.metadata.bind,
self.migrate_repository, version)
except migrate.exceptions.DatabaseAlreadyControlledError:
pass
示例4: __init__
# 需要导入模块: from migrate.versioning import api [as 别名]
# 或者: from migrate.versioning.api import version_control [as 别名]
def __init__(self, file, repository, echoresults):
# for backward compatibelity
if re.match('^\w+://', file) == None:
file = 'sqlite:///'+file
self.version = 3
self.dbfile = file
self.repository = repository
# migrate code
try:
dbversion = api.db_version(file, self.repository)
logging.debug('Current DB version: "%d"' % dbversion)
except: # if no previous database found => first installing
dbversion = 0
api.version_control(file, self.repository, dbversion)
versioningDone = False
if dbversion < self.version:
api.upgrade(file, self.repository, self.version)
versioningDone = True
elif dbversion > self.version:
api.downgrade(file, self.repository, self.version)
versioningDone = True
# edit by hassan : echoresults to True
engine = create_engine(file, echo=echoresults)
self.engine = engine
metadata = Base.metadata
metadata.create_all(engine)
Session = sessionmaker(engine)
self.session = Session()
if versioningDone:
self.rebuild_nested_set(0, 0)
示例5: migrate
# 需要导入模块: from migrate.versioning import api [as 别名]
# 或者: from migrate.versioning.api import version_control [as 别名]
def migrate(connection_string: str = None):
folder = os.path.dirname(__file__)
connection_string = connection_string or SA_CONNECTION_STRING
try:
api.version_control(url=connection_string, repository=folder)
except DatabaseAlreadyControlledError:
pass
api.upgrade(url=connection_string, repository=folder)