本文整理汇总了Python中migrate.versioning.api.make_update_script_for_model函数的典型用法代码示例。如果您正苦于以下问题:Python make_update_script_for_model函数的具体用法?Python make_update_script_for_model怎么用?Python make_update_script_for_model使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了make_update_script_for_model函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _generateMigrationScript
def _generateMigrationScript(dryrun):
newVersion = findMaxAvailableVersion() + 1
migration = SQLALCHEMY_MIGRATE_REPO + \
'/versions/%03d_migration.py' % (newVersion)
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)
if not dryrun:
open(migration, "wt").write(script)
api.upgrade(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
print 'New migration saved as ' + migration
print 'Current database version: ' + \
str(api.db_version(SQLALCHEMY_DATABASE_URI,
SQLALCHEMY_MIGRATE_REPO))
else:
print 'Dryrun:'
print '\nNew migration will be as ' + migration
print '\nNew migration script will be:\n"\n%s"' % str(script)
print '\nNew database version will be: ' + str(newVersion)
示例2: 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))
示例3: 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)
示例4: __init__
def __init__(self,database):
migration=SQLALCHEMY_MIGRATE_CONT+"/versions/%03d_migration.py" % (api.db_version(SQLALCHEMY_DATABASE_URI,SQLALCHEMY_MIGRATE_CONT)+1)
tmp_module=imp.new_module("old_model")
old_model=api.create_model(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_CONT)
exec old_model in tmp_module.__dict__
script=api.make_update_script_for_model(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_CONT, tmp_module.meta, database.metadata)
open(migration,"wt").write(script)
a=api.upgrade(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_CONT)
示例5: 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))
示例6: 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))
示例7: 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)))
示例8: migratedb
def migratedb():
"""Creates a migration file and version."""
migration = app.config.get('SQLALCHEMY_MIGRATE_REPO') + '/versions/%03d_migration.py' % (api.db_version(app.config.get('SQLALCHEMY_DATABASE_URI'), app.config.get('SQLALCHEMY_MIGRATE_REPO')) + 1)
tmp_module = imp.new_module('old_model')
old_model = api.create_model(app.config.get('SQLALCHEMY_DATABASE_URI'), app.config.get('SQLALCHEMY_MIGRATE_REPO'))
exec old_model in tmp_module.__dict__
script = api.make_update_script_for_model(app.config.get('SQLALCHEMY_DATABASE_URI'), app.config.get('SQLALCHEMY_MIGRATE_REPO'), tmp_module.meta, db.metadata)
open(migration, "wt").write(script)
api.upgrade(app.config.get('SQLALCHEMY_DATABASE_URI'), app.config.get('SQLALCHEMY_MIGRATE_REPO'))
print 'New migration saved as ' + migration
print 'Current database version: ' + str(api.db_version(app.config.get('SQLALCHEMY_DATABASE_URI'), app.config.get('SQLALCHEMY_MIGRATE_REPO')))
示例9: 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)
示例10: 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))
示例11: db_migrate
def db_migrate():
import imp
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__ # python2
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)
print ('New migration saved as ' + migration)
print ('Current database version: ' + str(api.db_version(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)))
示例12: db_migrate
def db_migrate():
import imp
import re
from migrate.versioning import api
from wpcgi.db import db
migration = SQLALCHEMY_MIGRATE_REPO + '/versions/%04d_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)
script = re.sub('INTEGER\(.*?\)', 'INTEGER', script)
open(migration, "wt").write(script)
print 'New migration saved as ' + migration
示例13: migrate
def migrate():
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 "New migration saved as " + migration
print "Current database version: " + str(api.db_version(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO))
示例14: db_migrate
def db_migrate():
# This is used for database migration. Newly created database should go through this as well.
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 'New migration saved as ' + migration
print 'Current database version: ' + str(api.db_version(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)) + '\n'
示例15: db_migrate
def db_migrate(self):
print "DataBase Migrate"
import imp
from migrate.versioning import api
from fpost.app import db
from fpost.config import SQLALCHEMY_DATABASE_URI
from fpost.config import SQLALCHEMY_MIGRATE_REPO
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 'New migration saved as ' + migration
print 'Current database version: ' + str(api.db_version(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO))