本文整理汇总了Python中migrate.versioning.api.downgrade函数的典型用法代码示例。如果您正苦于以下问题:Python downgrade函数的具体用法?Python downgrade怎么用?Python downgrade使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了downgrade函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: execute
def execute(self, parsed_args):
url = cfg.CONF['backend:powerdns'].database_connection
if not os.path.exists(REPOSITORY):
raise Exception('Migration Repository Not Found')
try:
target_version = int(parsed_args.to_version) \
if parsed_args.to_version else None
current_version = versioning_api.db_version(url=url,
repository=REPOSITORY)
except DatabaseNotControlledError:
raise Exception('PowerDNS database not yet initialized')
LOG.info("Attempting to synchronize PowerDNS database from version "
"'%s' to '%s'",
current_version,
target_version if target_version is not None else "latest")
if target_version and target_version < current_version:
versioning_api.downgrade(url=url, repository=REPOSITORY,
version=parsed_args.to_version)
else:
versioning_api.upgrade(url=url, repository=REPOSITORY,
version=parsed_args.to_version)
LOG.info('PowerDNS database synchronized successfully')
示例2: sync
def sync(self, version=None):
url = cfg.CONF['storage:sqlalchemy'].database_connection
if not os.path.exists(REPOSITORY):
raise Exception('Migration Repository Not Found')
try:
target_version = int(version) if version else None
current_version = versioning_api.db_version(url=url,
repository=REPOSITORY)
except DatabaseNotControlledError:
raise Exception('Database not yet initialized')
LOG.info("Attempting to synchronize database from version "
"'%s' to '%s'",
current_version,
target_version if target_version is not None else "latest")
if target_version and target_version < current_version:
versioning_api.downgrade(url=url, repository=REPOSITORY,
version=version)
else:
versioning_api.upgrade(url=url, repository=REPOSITORY,
version=version)
LOG.info('Database synchronized successfully')
示例3: __init__
def __init__(self, file, repository, echoresults):
#for backward compatibelity
if re.match('^\w+://', file) == None:
file = 'sqlite:///'+file
self.version = 2
self.dbfile = file
self.repository = repository
#migrate code
try:
dbversion = api.db_version(file, self.repository)
#print dbversion
except :
dbversion = 0
api.version_control(file, self.repository, dbversion)
if dbversion < self.version:
api.upgrade(file, self.repository, self.version)
elif dbversion > self.version:
api.downgrade(file, self.repository, self.version)
engine = create_engine(file , echo=False)#edit by hassan : echoresults to True
metadata = Base.metadata
metadata.create_all(engine)
Session = sessionmaker(engine)
self.session = Session()
示例4: execute
def execute(self, parsed_args):
url = cfg.CONF['storage:sqlalchemy'].database_connection
if not os.path.exists(REPOSITORY):
raise Exception('Migration Respository Not Found')
try:
target_version = int(parsed_args.to_version) \
if parsed_args.to_version else None
current_version = versioning_api.db_version(url=url,
repository=REPOSITORY)
except DatabaseNotControlledError:
raise Exception('Database not yet initialized')
LOG.info("Attempting to synchronize database from version '%s' to '%s'"
% (current_version, target_version))
if target_version and target_version < current_version:
versioning_api.downgrade(url=url, repository=REPOSITORY,
version=parsed_args.to_version)
else:
versioning_api.upgrade(url=url, repository=REPOSITORY,
version=parsed_args.to_version)
LOG.info('Database synchronized sucessfully')
示例5: downgrade_db
def downgrade_db(*opts):
'''
Downgrades the Database 1 rev.
'''
v = api.db_version(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
api.downgrade(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO, v - 1)
print 'Current database version: ' + str(api.db_version(SQLALCHEMY_DATABASE_URI,
SQLALCHEMY_MIGRATE_REPO))
示例6: db_downgrade
def db_downgrade(version):
"""Downgrade the database"""
v1 = get_db_version()
migrate_api.downgrade(url=db_url, repository=db_repo, version=version)
v2 = get_db_version()
if v1 == v2:
print 'No changes made.'
else:
print 'Downgraded: %s ... %s' % (v1, v2)
示例7: downgraddb
def downgraddb():
v = api.db_version(Config.SQLALCHEMY_DATABASE_URI,
Config.SQLALCHEMY_MIGRATE_REPO)
api.downgrade(Config.SQLALCHEMY_DATABASE_URI,
Config.SQLALCHEMY_MIGRATE_REPO, v - 1)
v = api.db_version(Config.SQLALCHEMY_DATABASE_URI,
Config.SQLALCHEMY_MIGRATE_REPO)
print 'Current database version: ' + str(v)
示例8: downgrade_db
def downgrade_db(v):
"""downgrade database schema to specified version"""
from_version = db_version(url=db, repository=repo)
to_version = int(v)
print("Downgrading db from version %d to %d. " % (from_version, to_version))
print("Schema upgrade ... ")
downgrade(url=db, repository=repo, version=v)
print("Data upgrade ... ")
datamigrations.run_downgrade_scripts(app, from_version, to_version)
print("Done!")
示例9: _migrate_down
def _migrate_down(self, engine, version, with_data=False):
migration_api.downgrade(engine, TestMigrations.REPOSITORY, version)
self.assertEqual(version, migration_api.db_version(engine, TestMigrations.REPOSITORY))
# NOTE(sirp): `version` is what we're downgrading to (i.e. the 'target'
# version). So if we have any downgrade checks, they need to be run for
# the previous (higher numbered) migration.
if with_data:
post_downgrade = getattr(self, "_post_downgrade_%03d" % (version + 1), None)
if post_downgrade:
post_downgrade(engine)
示例10: _downgradeDB
def _downgradeDB(expectedVersion, dryrun):
if not dryrun:
api.downgrade(SQLALCHEMY_DATABASE_URI,
SQLALCHEMY_MIGRATE_REPO,
expectedVersion)
print 'Current database version: ' + \
str(api.db_version(SQLALCHEMY_DATABASE_URI,
SQLALCHEMY_MIGRATE_REPO))
if dryrun:
print 'Dryrun'
print '\tNew database version will be: ' + str(expectedVersion)
示例11: db_downgrade
def db_downgrade(version=None):
# This is used to downgrade the database schema to a certain version or to one version before.
# If you know exactly the version you wish to use then you can directly downgrade to that version.
if not version:
current_version = api.db_version(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
downgrade_version = current_version - 1
else:
downgrade_version = version
api.downgrade(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO, downgrade_version)
print 'Database downgrade completed!'
print 'Current database version: ' + str(api.db_version(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO))
示例12: rollback
def rollback(count):
if (rollbacks > v) or (rollbacks < 0):
print "Invalid rollbacks count. Current version is %d." % v
rollbacks = int(raw_input("Input valid count:"))
rollback(rollbacks)
else:
api.downgrade(SQLALCHEMY_DATABASE_URI,
SQLALCHEMY_MIGRATE_REPO,
v - count)
print ('Current database version: ' +
str(api.db_version(SQLALCHEMY_DATABASE_URI,
SQLALCHEMY_MIGRATE_REPO)))
示例13: downgrade
def downgrade(args):
"""
Restores the database one previous version, run multiple times to go
back multiple versions if needed.
"""
# Get the configruation
config = get_config()
DB_URI = config.DATABASE_URI
M_REPO = config.MIGRATIONS
v = api.db_version(DB_URI, M_REPO)
api.downgrade(DB_URI, M_REPO, v - 1)
v = api.db_version(DB_URI, M_REPO)
return "Current database version: %i" % v
示例14: db_sync
def db_sync(abs_path, version=None, init_version=0):
"""Upgrade or downgrade a database.
Function runs the upgrade() or downgrade() functions in change scripts.
:param abs_path: Absolute path to migrate repository.
:param version: Database will upgrade/downgrade until this version.
If None - database will update to the latest
available version.
:param init_version: Initial database version
"""
if version is not None:
try:
version = int(version)
except ValueError:
raise exception.DbMigrationError(
message=_("version should be an integer"))
current_version = db_version(abs_path, init_version)
repository = _find_migrate_repo(abs_path)
if version is None or version > current_version:
return versioning_api.upgrade(get_engine(), repository, version)
else:
return versioning_api.downgrade(get_engine(), repository,
version)
示例15: db_sync
def db_sync(engine, version=None, init_version=INIT_VERSION):
"""Upgrade or downgrade a database.
Function runs the upgrade() or downgrade() functions in change scripts.
:param engine: SQLAlchemy engine instance for a given database
:param version: Database will upgrade/downgrade until this version.
If None - database will update to the latest
available version.
:param init_version: Initial database version
"""
if version is not None:
try:
version = int(version)
except ValueError:
raise exception.DbMigrationError(
message='version should be an integer')
current_version = db_version(engine, init_version)
repository = _find_migrate_repo()
if version is None or version > current_version:
return versioning_api.upgrade(engine, repository, version)
else:
return versioning_api.downgrade(engine, repository, version)