Python app.db 模块,metadata() 实例源码

我们从Python开源项目中,提取了以下1个代码示例,用于说明如何使用app.db.metadata()

项目:mincloud    作者:number13dev    | 项目源码 | 文件源码
def dbmigrate():
    app = Flask(__name__)
    conf = app.config.from_object('config.ProductionConfig')

    sqlalchemy_migrate_repo = app.config['SQLALCHEMY_MIGRATE_REPO']
    sqlalchemy_database_uri = app.config['SQLALCHEMY_DATABASE_URI']

    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))