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


Python api.upgrade函数代码示例

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


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

示例1: initialize_startup

def initialize_startup():
    """ Force DB tables create, in case no data is already found."""
    is_db_empty = False
    session = SA_SESSIONMAKER()
    inspector = reflection.Inspector.from_engine(session.connection())
    if len(inspector.get_table_names()) < 1:
        LOGGER.debug("Database access exception, maybe DB is empty")
        is_db_empty = True
    session.close()

    if is_db_empty:
        LOGGER.info("Initializing Database")
        if os.path.exists(cfg.DB_VERSIONING_REPO):
            shutil.rmtree(cfg.DB_VERSIONING_REPO)
        migratesqlapi.create(cfg.DB_VERSIONING_REPO, os.path.split(cfg.DB_VERSIONING_REPO)[1])
        _update_sql_scripts()
        migratesqlapi.version_control(cfg.DB_URL, cfg.DB_VERSIONING_REPO, version=cfg.DB_CURRENT_VERSION)
        session = SA_SESSIONMAKER()
        model.Base.metadata.create_all(bind=session.connection())
        session.commit()
        session.close()
        LOGGER.info("Database Default Tables created successfully!")
    else:
        _update_sql_scripts()
        migratesqlapi.upgrade(cfg.DB_URL, cfg.DB_VERSIONING_REPO, version=cfg.DB_CURRENT_VERSION)
        LOGGER.info("Database already has some data, will not be re-created!")
    return is_db_empty
开发者ID:HuifangWang,项目名称:the-virtual-brain-website,代码行数:27,代码来源:model_manager.py

示例2: __init__

 def __init__(self, file, repository, echoresults):
     
     #for backward compatibelity
     if re.match('^\w+://', file) == None:
         file = 'sqlite:///'+file   
     
     self.version = 2
     self.dbfile = file
     self.repository = repository
     
  
     
     #migrate code
     try:
         dbversion = api.db_version(file, self.repository)
         #print dbversion
     except :
         dbversion = 0
         api.version_control(file, self.repository, dbversion)
     
     if dbversion < self.version:
         api.upgrade(file, self.repository, self.version)
     elif  dbversion > self.version:
         api.downgrade(file, self.repository, self.version)
     
     engine = create_engine(file , echo=False)#edit by hassan : echoresults to True
     
     metadata = Base.metadata
     metadata.create_all(engine)
 
     Session = sessionmaker(engine)
     self.session = Session()            
开发者ID:AhmadHamzeei,项目名称:Amir-Accounting,代码行数:32,代码来源:__init__.py

示例3: _upgrade

 def _upgrade(self, version=None):
     if version:
         api.upgrade(self.sqlalchemy_database_uri,
             self.sqlalchemy_migration_path, version)
     else:
         api.upgrade(self.sqlalchemy_database_uri,
             self.sqlalchemy_migration_path)
开发者ID:akostyuk,项目名称:flask-dbmigrate,代码行数:7,代码来源:flask_dbmigrate.py

示例4: db_sync

def db_sync():
    repo_path = os.path.abspath(os.path.dirname(migrate_repo.__file__))
    try:
        versioning_api.upgrade(CONF.database.connection, repo_path)
    except versioning_exceptions.DatabaseNotControlledError:
        versioning_api.version_control(CONF.database.connection, repo_path)
        versioning_api.upgrade(CONF.database.connection, repo_path)
开发者ID:TimurNurlygayanov,项目名称:murano-api,代码行数:7,代码来源:session.py

示例5: upgrade_db

def upgrade_db(*opts):
    '''
    Upgrades the Database to current.
    '''
    api.upgrade(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
    print 'Current database version: ' + str(api.db_version(SQLALCHEMY_DATABASE_URI, 
                                                            SQLALCHEMY_MIGRATE_REPO))
开发者ID:irishjack,项目名称:Concord,代码行数:7,代码来源:dbmngr.py

示例6: _setup

def _setup(config):
    # disable delayed execution
    # config['adhocracy.amqp.host'] = None
    # FIXME: still do this with rq instead of rabbitmq
    # NOTE: this is called from tests so it may have side effects

    # Create the tables if they don't already exist
    url = config.get('sqlalchemy.url')
    migrate_repo = os.path.join(os.path.dirname(__file__), 'migration')
    repo_version = migrateapi.version(migrate_repo)

    if config.get('adhocracy.setup.drop', "OH_NOES") == "KILL_EM_ALL":
        meta.data.drop_all(bind=meta.engine)
        meta.engine.execute("DROP TABLE IF EXISTS migrate_version")

    try:
        db_version = migrateapi.db_version(url, migrate_repo)
        if db_version < repo_version:
            migrateapi.upgrade(url, migrate_repo)
        initial_setup = False
    except DatabaseNotControlledError:
        meta.data.create_all(bind=meta.engine)
        migrateapi.version_control(url, migrate_repo, version=repo_version)
        initial_setup = True

    install.setup_entities(config, initial_setup)
开发者ID:whausen,项目名称:part,代码行数:26,代码来源:websetup.py

示例7: _memorydb_migrate_db

def _memorydb_migrate_db(**kwargs):
    """
    This is crazy crackheaded, and abusive to sqlalchemy.

    We'll take out dispose so the migrate stuff doesn't kill it,
    and push through the migrate.  This makes a bunch of assumptions
    that are likely stupid, but since this is done on a memory-backed
    db for testing, it's probably okay.

    Just don't run this on a real db.
    """
    def dispose_patch(*args, **kwargs):
        pass

    global engine

    Base.metadata.create_all(bind=engine)
    for table in reversed(Base.metadata.sorted_tables):
        session.execute(table.delete())
        session.commit()

    old_dispose = engine.dispose
    engine.dispose = dispose_patch

    repo_path = repo.Repository(
        os.path.abspath(os.path.dirname(opencenter_repo.__file__)))
    migrate_api.version_control(engine, repo_path)
    migrate_api.upgrade(engine, repo_path)
    engine.dispose = old_dispose
开发者ID:BATYD-Turksat,项目名称:opencenter,代码行数:29,代码来源:database.py

示例8: check_database

    def check_database(self):
        if not self.engine.has_table(SchemaVersion.__tablename__):
            log.info("Creating database schema table")
            SchemaVersion.__table__.create(bind=self.engine)

        repository = Repository(upgrades.__path__[0])

        session = self.session()
        if not session.query(SchemaVersion).first():
            session.add(SchemaVersion(
                "Network Audio Monitor Schema Version Control",
                path.abspath(path.expanduser(repository.path)), 0)
            )
            session.commit()



        schema_version = session.query(SchemaVersion).first()
        if schema_version.version >= repository.latest:
            log.info("No database upgrade required")
            return
        component.get("EventManager").emit(DatabaseUpgradeRequired())
        log.warn("Upgrading database (from -> to...)")
        component.get("EventManager").emit(DatabaseUpgradeStart())
        upgrade(self.engine, repository)
        log.warn("Upgrade complete.")
        component.get("EventManager").emit(DatabaseUpgradeComplete())
开发者ID:UfSoft,项目名称:GtkNAM,代码行数:27,代码来源:databasemanager.py

示例9: sync

    def sync(self, version=None):
        url = cfg.CONF['storage:sqlalchemy'].database_connection

        if not os.path.exists(REPOSITORY):
            raise Exception('Migration Repository Not Found')

        try:
            target_version = int(version) if version else None

            current_version = versioning_api.db_version(url=url,
                                                        repository=REPOSITORY)
        except DatabaseNotControlledError:
            raise Exception('Database not yet initialized')

        LOG.info("Attempting to synchronize database from version "
                 "'%s' to '%s'",
                 current_version,
                 target_version if target_version is not None else "latest")

        if target_version and target_version < current_version:
            versioning_api.downgrade(url=url, repository=REPOSITORY,
                                     version=version)
        else:
            versioning_api.upgrade(url=url, repository=REPOSITORY,
                                   version=version)

        LOG.info('Database synchronized successfully')
开发者ID:gvnkd,项目名称:designate,代码行数:27,代码来源:database.py

示例10: db_sync

def db_sync(engine):
    db_version(engine)  # This is needed to create a version stamp in empty DB
    repository = _find_migrate_repo()
    versioning_api.upgrade(engine, repository)
    config = _alembic_config()
    config._engine = engine
    alembic.command.upgrade(config, "head")
开发者ID:bishnoink,项目名称:ceilometer,代码行数:7,代码来源:migration.py

示例11: _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)
开发者ID:FYJen,项目名称:website,代码行数:25,代码来源:db_script.py

示例12: 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

示例13: execute

    def execute(self, parsed_args):
        url = cfg.CONF['storage:sqlalchemy'].database_connection

        if not os.path.exists(REPOSITORY):
            raise Exception('Migration Respository Not Found')

        try:
            target_version = int(parsed_args.to_version) \
                if parsed_args.to_version else None

            current_version = versioning_api.db_version(url=url,
                                                        repository=REPOSITORY)
        except DatabaseNotControlledError:
            raise Exception('Database not yet initialized')

        LOG.info("Attempting to synchronize database from version '%s' to '%s'"
                 % (current_version, target_version))

        if target_version and target_version < current_version:
            versioning_api.downgrade(url=url, repository=REPOSITORY,
                                     version=parsed_args.to_version)
        else:
            versioning_api.upgrade(url=url, repository=REPOSITORY,
                                   version=parsed_args.to_version)

        LOG.info('Database synchronized sucessfully')
开发者ID:appliedcode,项目名称:moniker,代码行数:26,代码来源:database.py

示例14: setup_db

def setup_db(settings):
    """ We need to create the test sqlite database to run our tests against

    If the db exists, remove it
    We're using the SA-Migrations API to create the db and catch it up to the
    latest migration level for testing

    In theory, we could use this API to do version specific testing as well if
    we needed to.

    If we want to run any tests with a fresh db we can call this function

    """
    from migrate.versioning import api as mig
    sa_url = settings['sqlalchemy.url']
    migrate_repository = 'migrations'

    # we're hackish here since we're going to assume the test db is whatever is
    # after the last slash of the SA url sqlite:///somedb.db
    db_name = sa_url[sa_url.rindex('/') + 1:]
    try:
        os.remove(db_name)
    except:
        pass

    open(db_name, 'w').close()

    mig.version_control(sa_url, migrate_repository)
    mig.upgrade(sa_url, migrate_repository)
开发者ID:briangershon,项目名称:Bookie,代码行数:29,代码来源:__init__.py

示例15: execute

    def execute(self, parsed_args):
        url = cfg.CONF['backend:powerdns'].database_connection

        if not os.path.exists(REPOSITORY):
            raise Exception('Migration Repository Not Found')

        try:
            target_version = int(parsed_args.to_version) \
                if parsed_args.to_version else None

            current_version = versioning_api.db_version(url=url,
                                                        repository=REPOSITORY)
        except DatabaseNotControlledError:
            raise Exception('PowerDNS database not yet initialized')

        LOG.info("Attempting to synchronize PowerDNS database from version "
                 "'%s' to '%s'",
                 current_version,
                 target_version if target_version is not None else "latest")

        if target_version and target_version < current_version:
            versioning_api.downgrade(url=url, repository=REPOSITORY,
                                     version=parsed_args.to_version)
        else:
            versioning_api.upgrade(url=url, repository=REPOSITORY,
                                   version=parsed_args.to_version)

        LOG.info('PowerDNS database synchronized successfully')
开发者ID:arjunpola,项目名称:designate,代码行数:28,代码来源:powerdns.py


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