• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python api.db_version函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中migrate.versioning.api.db_version函数的典型用法代码示例。如果您正苦于以下问题:Python db_version函数的具体用法?Python db_version怎么用?Python db_version使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了db_version函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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."
                )
            )
开发者ID:wputra,项目名称:MOS-centos,代码行数:25,代码来源:migration.py


示例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)
开发者ID:eleventhend,项目名称:jobs-report,代码行数:27,代码来源:elmr-admin.py


示例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))
开发者ID:ikinsella,项目名称:squall,代码行数:32,代码来源:manage.py


示例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))
开发者ID:irishjack,项目名称:Concord,代码行数:8,代码来源:dbmngr.py


示例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()
开发者ID:jessegonzalez,项目名称:healthnmon,代码行数:9,代码来源:test_migration.py


示例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)
开发者ID:akostyuk,项目名称:flask-dbmigrate,代码行数:9,代码来源:flask_dbmigrate.py


示例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
开发者ID:ERC-data,项目名称:ckanext-doi,代码行数:10,代码来源:repo.py


示例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))
开发者ID:jharkins,项目名称:webapp-template,代码行数:10,代码来源:db_manage.py


示例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)
开发者ID:YanshuoH,项目名称:whats-today,代码行数:10,代码来源:manager.py


示例10: create_db

def create_db():
    """
    Creates the test DB
    """
    try:
        db_version(URI, REPO)
    except DatabaseNotControlledError:
        version_control(URI, REPO)

    upgrade(URI, REPO)
开发者ID:aaronfay,项目名称:mypi,代码行数:10,代码来源:test.py


示例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)
开发者ID:TemosEngenharia,项目名称:RPI-IO,代码行数:11,代码来源:models.py


示例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))
开发者ID:dpsmartws,项目名称:PROM.ua-Test-work,代码行数:11,代码来源:run.py


示例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)))
开发者ID:Andor-Z,项目名称:My-Learning-Note,代码行数:11,代码来源:db_migrate.py


示例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))
开发者ID:rsp-internet-services,项目名称:Batex-os,代码行数:12,代码来源:manage.py


示例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)
开发者ID:hardys,项目名称:ceilometer,代码行数:12,代码来源:migration.py


示例16: db_version

def db_version(engine, init_version=INIT_VERSION):
    """Show the current version of the repository.

    :param engine:  SQLAlchemy engine instance for a given database
    :param init_version:  Initial database version
    """
    repository = _find_migrate_repo()
    try:
        return versioning_api.db_version(engine, repository)
    except versioning_exceptions.DatabaseNotControlledError:
        db_version_control(engine, init_version)
        return versioning_api.db_version(engine, repository)
开发者ID:DKILLER123,项目名称:seedbox,代码行数:12,代码来源:migration.py


示例17: db_version

def db_version(engine):
    repository = _find_migrate_repo()
    try:
        return versioning_api.db_version(engine,
                                         repository)
    except versioning_exceptions.DatabaseNotControlledError:
        meta = sqlalchemy.MetaData()
        meta.reflect(bind=engine)
        tables = meta.tables
        if not tables:
            db_version_control(engine, 0)
            return versioning_api.db_version(engine, repository)
开发者ID:akhilhingane,项目名称:ceilometer,代码行数:12,代码来源:migration.py


示例18: 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)))
开发者ID:ricardobergamo,项目名称:flask-base-bootstrap,代码行数:12,代码来源:manager.py


示例19: 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))
开发者ID:widoyo,项目名称:EmeraldBox,代码行数:12,代码来源:box.py


示例20: main

def main(url, repository):
    # Check if database is under version control
    try:
        db_version(url, repository)
    except DatabaseNotControlledError:
        # put database under version control
        version_control(url, repository)         

    kwargs = {'url': url,
        'repository': repository
    }

    shell.main(**kwargs)
开发者ID:prinzdezibel,项目名称:p2.datashackle.repository,代码行数:13,代码来源:manage.py



注:本文中的migrate.versioning.api.db_version函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python api.downgrade函数代码示例发布时间:2022-05-27
下一篇:
Python api.create_model函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap