예제 #1
0
def sync_database_to_version(extension=None, version=None):
    if not extension:
        abs_path = find_migrate_repo()
        init_version = migrate_repo.DB_INIT_VERSION
    else:
        init_version = 0
        try:
            package_name = '.'.join((contrib.__name__, extension))
            package = importutils.import_module(package_name)
        except ImportError:
            raise ImportError(_("%s extension does not exist.")
                              % package_name)
        try:
            abs_path = find_migrate_repo(package)
            try:
                migration.db_version_control(sql.get_engine(), abs_path)
            # Register the repo with the version control API
            # If it already knows about the repo, it will throw
            # an exception that we can safely ignore
            except exceptions.DatabaseAlreadyControlledError:
                pass
        except exception.MigrationNotProvided as e:
            print(e)
            sys.exit(1)
    migration.db_sync(sql.get_engine(), abs_path, version=version,
                      init_version=init_version)
예제 #2
0
 def sync(self, version=None, current_version=None):
     """
     Place a database under migration control and upgrade/downgrade it,
     creating first if necessary.
     """
     if current_version not in (None, 'None'):
         migration.db_version_control(db_api.get_engine(),
                                      db_migration.MIGRATE_REPO_PATH,
                                      version=current_version)
     migration.db_sync(db_api.get_engine(), db_migration.MIGRATE_REPO_PATH,
                       version)
예제 #3
0
 def sync(self, version=None, current_version=None):
     """
     Place a database under migration control and upgrade/downgrade it,
     creating first if necessary.
     """
     if current_version not in (None, 'None'):
         migration.db_version_control(db_api.get_engine(),
                                      db_migration.MIGRATE_REPO_PATH,
                                      version=current_version)
     migration.db_sync(db_api.get_engine(),
                       db_migration.MIGRATE_REPO_PATH,
                       version)
예제 #4
0
def sync_database_to_version(extension=None, version=None):
    if not extension:
        abs_path = find_migrate_repo()
        init_version = migrate_repo.DB_INIT_VERSION
    else:
        init_version = 0
        try:
            package_name = '.'.join((contrib.__name__, extension))
            package = importutils.import_module(package_name)
        except ImportError:
            raise ImportError(_("%s extension does not exist.")
                              % package_name)
        try:
            abs_path = find_migrate_repo(package)
            try:
                migration.db_version_control(sql.get_engine(), abs_path)
            # Register the repo with the version control API
            # If it already knows about the repo, it will throw
            # an exception that we can safely ignore
            except exceptions.DatabaseAlreadyControlledError:
                pass
        except exception.MigrationNotProvided as e:
            print(e)
            sys.exit(1)

    engine = sql.get_engine()
    try:
        migration.db_sync(engine, abs_path, version=version,
                          init_version=init_version)
    except ValueError:
        # NOTE(morganfainberg): ValueError is raised from the sanity check (
        # verifies that tables are utf8 under mysql). The region table was not
        # initially built with InnoDB and utf8 as part of the table arguments
        # when the migration was initially created. Bug #1334779 is a scenario
        # where the deployer can get wedged, unable to upgrade or downgrade.
        # This is a workaround to "fix" that table if we're under MySQL.
        if (not extension and engine.name == 'mysql' and
                six.text_type(get_db_version()) == '37'):
            _fix_migration_37(engine)
            # Try the migration a second time now that we've done the
            # un-wedge work.
            migration.db_sync(engine, abs_path, version=version,
                              init_version=init_version)
        else:
            raise
예제 #5
0
    def test_db_version_control(self):
        with contextlib.nested(
                mock.patch.object(migration, '_find_migrate_repo'),
                mock.patch.object(versioning_api, 'version_control'),
        ) as (mock_find_repo, mock_version_control):
            mock_find_repo.return_value = self.return_value

            version = migration.db_version_control(self.engine, self.path,
                                                   self.test_version)

            self.assertEqual(version, self.test_version)
            mock_version_control.assert_called_once_with(
                self.engine, self.return_value, self.test_version)
예제 #6
0
def _sync_extension_repo(extension, version):
    init_version = 0
    try:
        package_name = '.'.join((contrib.__name__, extension))
        package = importutils.import_module(package_name)
    except ImportError:
        raise ImportError(_("%s extension does not exist.")
                          % package_name)
    try:
        abs_path = find_migrate_repo(package)
        try:
            migration.db_version_control(sql.get_engine(), abs_path)
        # Register the repo with the version control API
        # If it already knows about the repo, it will throw
        # an exception that we can safely ignore
        except exceptions.DatabaseAlreadyControlledError:
            pass
    except exception.MigrationNotProvided as e:
        print(e)
        sys.exit(1)
    migration.db_sync(sql.get_engine(), abs_path, version=version,
                      init_version=init_version)
예제 #7
0
    def test_db_version_control(self):
        with contextlib.nested(
            mock.patch.object(migration, '_find_migrate_repo'),
            mock.patch.object(versioning_api, 'version_control'),
        ) as (mock_find_repo, mock_version_control):
            mock_find_repo.return_value = self.return_value

            version = migration.db_version_control(
                self.engine, self.path, self.test_version)

            self.assertEqual(version, self.test_version)
            mock_version_control.assert_called_once_with(
                self.engine, self.return_value, self.test_version)
예제 #8
0
파일: manage.py 프로젝트: amoid/glance
 def version_control(self, version=None):
     """Place a database under migration control"""
     migration.db_version_control(db_api.get_engine(),
                                  db_migration.MIGRATE_REPO_PATH, version)
예제 #9
0
파일: manage.py 프로젝트: amoid/glance
 def version_control(self, version=None):
     """Place a database under migration control"""
     migration.db_version_control(db_api.get_engine(),
                                  db_migration.MIGRATE_REPO_PATH,
                                  version)
예제 #10
0
파일: migration.py 프로젝트: COSHPC/heat
def db_version_control(engine, version=None):
    path = os.path.join(os.path.abspath(os.path.dirname(__file__)),
                        'migrate_repo')
    return oslo_migration.db_version_control(engine, path, version)
예제 #11
0
def db_version_control(engine, version=None):
    path = os.path.join(os.path.abspath(os.path.dirname(__file__)),
                        'migrate_repo')
    return oslo_migration.db_version_control(engine, path, version)