当前位置: 首页>>代码示例>>Python>>正文


Python api.db_version方法代码示例

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


在下文中一共展示了api.db_version方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: db_version

# 需要导入模块: from migrate.versioning import api [as 别名]
# 或者: from migrate.versioning.api import db_version [as 别名]
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(INIT_VERSION)
            return versioning_api.db_version(get_engine(), repository)
        else:
            # Some pre-Essex DB's may not be version controlled.
            # Require them to upgrade using Essex first.
            raise exception.EC2Exception(
                _("Upgrade DB using Essex release first.")) 
开发者ID:openstack,项目名称:ec2-api,代码行数:19,代码来源:migration.py

示例2: upgrade_db

# 需要导入模块: from migrate.versioning import api [as 别名]
# 或者: from migrate.versioning.api import db_version [as 别名]
def upgrade_db(self, version=None):
        '''Upgrade db using sqlalchemy migrations.

        @param version: version to upgrade to (if None upgrade to latest)
        '''
        assert meta.engine.name in ('postgres', 'postgresql'), \
            'Database migration - only Postgresql engine supported (not %s).' \
                % meta.engine.name
        import migrate.versioning.api as mig
        self.setup_migration_version_control()
        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:
            log.info('CKAN database version upgraded: %s -> %s', version_before, version_after)
        else:
            log.info('CKAN database version remains as: %s', version_after)

        ##this prints the diffs in a readable format
        ##import pprint
        ##from migrate.versioning.schemadiff import getDiffOfModelAgainstDatabase
        ##pprint.pprint(getDiffOfModelAgainstDatabase(self.metadata, self.metadata.bind).colDiffs) 
开发者ID:italia,项目名称:daf-recipes,代码行数:24,代码来源:__init__.py

示例3: db_version

# 需要导入模块: from migrate.versioning import api [as 别名]
# 或者: from migrate.versioning.api import db_version [as 别名]
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 init_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 or
                'migrate_version' in tables):
            db_version_control(engine, abs_path, version=init_version)
            return versioning_api.db_version(engine, repository)
        else:
            raise exception.DBMigrationError(
                _("The database is not under version control, but has "
                  "tables. Please stamp the current version of the schema "
                  "manually.")) 
开发者ID:openstack,项目名称:oslo.db,代码行数:25,代码来源:migration.py

示例4: db_sync

# 需要导入模块: from migrate.versioning import api [as 别名]
# 或者: from migrate.versioning.api import db_version [as 别名]
def db_sync(version=None):
    if version is not None:
        try:
            version = int(version)
        except ValueError:
            raise exception.EC2Exception(_("version should be an integer"))

    current_version = db_version()
    repository = _find_migrate_repo()
    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) 
开发者ID:openstack,项目名称:ec2-api,代码行数:16,代码来源:migration.py

示例5: __init__

# 需要导入模块: from migrate.versioning import api [as 别名]
# 或者: from migrate.versioning.api import db_version [as 别名]
def __init__(self, file, repository, echoresults):

        # for backward compatibelity
        if re.match('^\w+://', file) == None:
            file = 'sqlite:///'+file

        self.version = 3
        self.dbfile = file
        self.repository = repository

        # migrate code
        try:
            dbversion = api.db_version(file, self.repository)
            logging.debug('Current DB version: "%d"' % dbversion)
        except:  # if no previous database found => first installing
            dbversion = 0
            api.version_control(file, self.repository, dbversion)

        versioningDone = False

        if dbversion < self.version:
            api.upgrade(file, self.repository, self.version)
            versioningDone = True
        elif dbversion > self.version:
            api.downgrade(file, self.repository, self.version)
            versioningDone = True

        # edit by hassan : echoresults to True
        engine = create_engine(file, echo=echoresults)
        self.engine = engine

        metadata = Base.metadata
        metadata.create_all(engine)

        Session = sessionmaker(engine)
        self.session = Session()
        if versioningDone:
            self.rebuild_nested_set(0, 0) 
开发者ID:Jooyeshgar,项目名称:amir,代码行数:40,代码来源:__init__.py

示例6: db_sync

# 需要导入模块: from migrate.versioning import api [as 别名]
# 或者: from migrate.versioning.api import db_version [as 别名]
def db_sync(engine, abs_path, version=None, init_version=0, sanity_check=True):
    """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 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
    :param sanity_check: Require schema sanity checking for all tables
    """

    if version is not None:
        try:
            version = int(version)
        except ValueError:
            raise exception.DBMigrationError(_("version should be an integer"))

    current_version = db_version(engine, abs_path, init_version)
    repository = _find_migrate_repo(abs_path)
    if sanity_check:
        _db_schema_sanity_check(engine)
    if version is None or version > current_version:
        try:
            migration = versioning_api.upgrade(engine, repository, version)
        except Exception as ex:
            raise exception.DBMigrationError(ex)
    else:
        migration = versioning_api.downgrade(engine, repository,
                                             version)
    if sanity_check:
        _db_schema_sanity_check(engine)

    return migration 
开发者ID:openstack,项目名称:oslo.db,代码行数:38,代码来源:migration.py


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