本文整理汇总了Python中migrate.versioning.api.db_version函数的典型用法代码示例。如果您正苦于以下问题:Python db_version函数的具体用法?Python db_version怎么用?Python db_version使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了db_version函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: db_version
def db_version(engine, abs_path, init_version):
"""Show the current version of the 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:
return versioning_api.db_version(engine, repository)
except versioning_exceptions.DatabaseNotControlledError:
meta = sqlalchemy.MetaData()
meta.reflect(bind=engine)
tables = meta.tables
if len(tables) == 0 or "alembic_version" in tables:
db_version_control(engine, abs_path, version=init_version)
return versioning_api.db_version(engine, repository)
else:
raise exception.DbMigrationError(
message=_(
"The database is not under version control, but has "
"tables. Please stamp the current version of the schema "
"manually."
)
)
示例2: migrate
def migrate(args):
"""
Create DB migrations for current version
"""
# Get the configruation
config = get_config()
DB_URI = config.DATABASE_URI
M_REPO = config.MIGRATIONS
v = api.db_version(DB_URI, M_REPO)
m = os.path.join(M_REPO, 'versions', '%03d_migration.py' % (v + 1))
tmpmod = imp.new_module('old_model')
oldmod = api.create_model(DB_URI, M_REPO)
exec(oldmod, tmpmod.__dict__)
script = api.make_update_script_for_model(
DB_URI, M_REPO, tmpmod.meta, elmr.db.metadata
)
with open(m, 'wt') as f:
f.write(script)
v = api.db_version(DB_URI, M_REPO)
return "New migration saved as %s\nCurrent database version: %d" % (m, v)
示例3: migratedb
def migratedb():
""" Updates the database and SQLAlchemy-migrate repository
to a new version containing all of the tables defined
in the SQLAlchemy data models.
"""
# Obtain Current Verison
ver = api.db_version(app.config['SQLALCHEMY_DATABASE_URI'],
app.config['SQLALCHEMY_MIGRATE_REPO'])
# Create Migration Script To Apply Model Changes
mgr = app.config['SQLALCHEMY_MIGRATE_REPO'] +\
('/versions/%03d_migration.py' % (ver+1))
tmp_module = imp.new_module('old_model')
old_model = api.create_model(app.config['SQLALCHEMY_DATABASE_URI'],
app.config['SQLALCHEMY_MIGRATE_REPO'])
exec(old_model, tmp_module.__dict__)
script = api.make_update_script_for_model(
app.config['SQLALCHEMY_DATABASE_URI'],
app.config['SQLALCHEMY_MIGRATE_REPO'],
tmp_module.meta, db.metadata)
open(mgr, "wt").write(script)
# Update Database With Migration Script
api.upgrade(app.config['SQLALCHEMY_DATABASE_URI'],
app.config['SQLALCHEMY_MIGRATE_REPO'])
# Obtain & Display Current Version & Migration
ver = api.db_version(app.config['SQLALCHEMY_DATABASE_URI'],
app.config['SQLALCHEMY_MIGRATE_REPO'])
print('New migration saved as: ' + mgr)
print('Current databse version: ' + str(ver))
示例4: 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))
示例5: test_dbSync_withException
def test_dbSync_withException(self):
self.mox.StubOutWithMock(versioning_api, "db_version")
versioning_api.db_version(mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes().AndRaise(
versioning_exceptions.DatabaseNotControlledError
)
self.mox.ReplayAll()
self.assertRaises(Exception, migration.db_sync, "0")
self.mox.UnsetStubs()
示例6: wrapper
def wrapper(self, *args, **kwargs):
try:
api.db_version(self.sqlalchemy_database_uri,
self.sqlalchemy_migration_path)
except InvalidRepositoryError:
print('You have no database under version control. '
'Try to "init" it first')
return
command(self, *args, **kwargs)
示例7: upgrade
def upgrade(self, version=None):
import migrate.versioning.api as mig
self.setup_migration_version_control(version)
version_before = mig.db_version(self.metadata.bind, self.migrate_repository)
mig.upgrade(self.metadata.bind, self.migrate_repository, version=version)
version_after = mig.db_version(self.metadata.bind, self.migrate_repository)
if version_after != version_before:
print 'CKAN database version upgraded: %s -> %s' % (version_before, version_after)
else:
print 'CKAN database version remains as: %s' % version_after
示例8: migrate_database
def migrate_database():
migration = c.SQLALCHEMY_MIGRATE_REPO + '/versions/%03d_migration.py' % (api.db_version(c.SQLALCHEMY_DATABASE_URI, c.SQLALCHEMY_MIGRATE_REPO) + 1)
tmp_module = imp.new_module('old_model')
old_model = api.create_model(c.SQLALCHEMY_DATABASE_URI, c.SQLALCHEMY_MIGRATE_REPO)
exec old_model in tmp_module.__dict__
script = api.make_update_script_for_model(c.SQLALCHEMY_DATABASE_URI, c.SQLALCHEMY_MIGRATE_REPO, tmp_module.meta, db.metadata)
open(migration, "wt").write(script)
api.upgrade(c.SQLALCHEMY_DATABASE_URI, c.SQLALCHEMY_MIGRATE_REPO)
print 'New migration saved as ' + migration
print 'Current database version: ' + str(api.db_version(c.SQLALCHEMY_DATABASE_URI, c.SQLALCHEMY_MIGRATE_REPO))
示例9: 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)
示例10: create_db
def create_db():
"""
Creates the test DB
"""
try:
db_version(URI, REPO)
except DatabaseNotControlledError:
version_control(URI, REPO)
upgrade(URI, REPO)
示例11: migrate_db
def migrate_db():
import imp
v = api.db_version(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
migration = SQLALCHEMY_MIGRATE_REPO + ('/versions/%03d_migration.py' % (v+1))
tmp_module = imp.new_module('old_model')
old_model = api.create_model(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
exec(old_model, tmp_module.__dict__)
script = api.make_update_script_for_model(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO, tmp_module.meta, Base.metadata)
open(migration, "wt").write(script)
api.upgrade(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
v = api.db_version(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
示例12: migrate
def migrate():
from migrate.versioning import api
migration = SQLALCHEMY_MIGRATE_REPO + '/versions/%03d_migration.py' % (api.db_version(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO) + 1)
tmp_module = imp.new_module('old_model')
old_model = api.create_model(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
exec old_model in tmp_module.__dict__
script = api.make_update_script_for_model(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO, tmp_module.meta, db.metadata)
open(migration, "wt").write(script)
api.upgrade(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
print u'Миграция успешна: ' + migration
print u'Версия базы данных: ' + str(api.db_version(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO))
示例13: migrate_db
def migrate_db():
migration = os.path.join(MG_REPO, 'versions', '%03d_migration.py' % (api.db_version(DB_URI, MG_REPO) + 1))
tmp_module = imp.new_module('old_model')
old_model = api.create_model(DB_URI, MG_REPO)
exec(old_model, tmp_module.__dict__)
script = api.make_update_script_for_model(DB_URI, MG_REPO, tmp_module.meta, db.metadata)
# ?
open(migration, 'wt').write(script)
api.upgrade(DB_URI, MG_REPO)
print('New migration saved as ' + migration)
print('Current database version: ' + str(api.db_version(DB_URI, MG_REPO)))
示例14: migrate_db
def migrate_db():
v = api.db_version(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
migration = SQLALCHEMY_MIGRATE_REPO + ('/versions/%03d_migration.py' % (v + 1))
tmp_module = imp.new_module('old_model')
old_model = api.create_model(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
exec(old_model, tmp_module.__dict__)
script = api.make_update_script_for_model(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO, tmp_module.meta, db.metadata)
open(migration, "wt").write(script)
api.upgrade(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
v = api.db_version(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
print('New migration saved as ' + migration)
print('Current database version: ' + str(v))
示例15: db_version
def db_version():
repository = _find_migrate_repo()
try:
return versioning_api.db_version(get_engine(), repository)
except versioning_exceptions.DatabaseNotControlledError:
meta = sqlalchemy.MetaData()
engine = get_engine()
meta.reflect(bind=engine)
tables = meta.tables
if len(tables) == 0:
db_version_control(0)
return versioning_api.db_version(get_engine(), repository)