Ejemplo n.º 1
0
 def _migrate_up(self, engine, version):
     migration_api.upgrade(engine,
                           TestMigrations.REPOSITORY,
                           version)
     self.assertEqual(version,
             migration_api.db_version(engine,
                                      TestMigrations.REPOSITORY))
Ejemplo n.º 2
0
 def _migrate_up(self, engine, version):
     migration_api.upgrade(engine,
                           TestMigrations.REPOSITORY,
                           version)
     self.assertEqual(version,
             migration_api.db_version(engine,
                                      TestMigrations.REPOSITORY))
Ejemplo n.º 3
0
    def _migrate_up(self, engine, version, with_data=False):
        """migrate up to a new version of the db.

        We allow for data insertion and post checks at every
        migration version with special _prerun_### and
        _check_### functions in the main test.
        """
        # NOTE(sdague): try block is here because it's impossible to debug
        # where a failed data migration happens otherwise
        try:
            if with_data:
                data = None
                prerun = getattr(self, "_prerun_%d" % version, None)
                if prerun:
                    data = prerun(engine)

                migration_api.upgrade(engine,
                                          TestMigrations.REPOSITORY,
                                          version)
                self.assertEqual(
                    version,
                    migration_api.db_version(engine,
                                             TestMigrations.REPOSITORY))

            if with_data:
                check = getattr(self, "_check_%d" % version, None)
                if check:
                    check(engine, data)
        except Exception:
            LOG.error("Failed to migrate to version %s on engine %s" %
                      (version, engine))
            raise
Ejemplo n.º 4
0
    def _migrate_up(self, engine, version, with_data=False):
        """migrate up to a new version of the db.

        We allow for data insertion and post checks at every
        migration version with special _prerun_### and
        _check_### functions in the main test.
        """
        # NOTE(sdague): try block is here because it's impossible to debug
        # where a failed data migration happens otherwise
        try:
            if with_data:
                data = None
                prerun = getattr(self, "_prerun_%d" % version, None)
                if prerun:
                    data = prerun(engine)

                migration_api.upgrade(engine, TestMigrations.REPOSITORY,
                                      version)
                self.assertEqual(
                    version,
                    migration_api.db_version(engine,
                                             TestMigrations.REPOSITORY))

            if with_data:
                check = getattr(self, "_check_%d" % version, None)
                if check:
                    check(engine, data)
        except Exception:
            LOG.error("Failed to migrate to version %s on engine %s" %
                      (version, engine))
            raise
Ejemplo n.º 5
0
    def _walk_versions(self, engine=None, snake_walk=False, downgrade=True):
        # Determine latest version script from the repo, then
        # upgrade from 1 through to the latest, with no data
        # in the databases. This just checks that the schema itself
        # upgrades successfully.

        # Place the database under version control
        migration_api.version_control(engine, TestMigrations.REPOSITORY, migration.INIT_VERSION)
        self.assertEqual(migration.INIT_VERSION, migration_api.db_version(engine, TestMigrations.REPOSITORY))

        migration_api.upgrade(engine, TestMigrations.REPOSITORY, migration.INIT_VERSION + 1)

        LOG.debug("latest version is %s" % TestMigrations.REPOSITORY.latest)

        for version in xrange(migration.INIT_VERSION + 2, TestMigrations.REPOSITORY.latest + 1):
            # upgrade -> downgrade -> upgrade
            self._migrate_up(engine, version)
            if snake_walk:
                self._migrate_down(engine, version - 1)
                self._migrate_up(engine, version)

        if downgrade:
            # Now walk it back down to 0 from the latest, testing
            # the downgrade paths.
            for version in reversed(xrange(migration.INIT_VERSION + 1, TestMigrations.REPOSITORY.latest)):
                # downgrade -> upgrade -> downgrade
                self._migrate_down(engine, version)
                if snake_walk:
                    self._migrate_up(engine, version + 1)
                    self._migrate_down(engine, version)
Ejemplo n.º 6
0
    def _walk_versions(self, engine=None, snake_walk=False):
        # Determine latest version script from the repo, then
        # upgrade from 1 through to the latest, with no data
        # in the databases. This just checks that the schema itself
        # upgrades successfully.

        # Place the database under version control
        migration_api.version_control(engine, TestMigrations.REPOSITORY)
        self.assertEqual(0,
                migration_api.db_version(engine,
                                         TestMigrations.REPOSITORY))

        LOG.debug('latest version is %s' % TestMigrations.REPOSITORY.latest)

        for version in xrange(1, TestMigrations.REPOSITORY.latest + 1):
            # upgrade -> downgrade -> upgrade
            migration_api.upgrade(engine, TestMigrations.REPOSITORY, version)
            self.assertEqual(version,
                    migration_api.db_version(engine,
                                             TestMigrations.REPOSITORY))
            if snake_walk:
                migration_api.downgrade(engine,
                                        TestMigrations.REPOSITORY,
                                        version - 1)
                self.assertEqual(version - 1,
                        migration_api.db_version(engine,
                                                 TestMigrations.REPOSITORY))
                migration_api.upgrade(engine,
                                      TestMigrations.REPOSITORY,
                                      version)
                self.assertEqual(version,
                        migration_api.db_version(engine,
                                                 TestMigrations.REPOSITORY))

        # Now walk it back down to 0 from the latest, testing
        # the downgrade paths.
        for version in reversed(
            xrange(0, TestMigrations.REPOSITORY.latest)):
            # downgrade -> upgrade -> downgrade
            migration_api.downgrade(engine, TestMigrations.REPOSITORY, version)
            self.assertEqual(version,
                    migration_api.db_version(engine,
                                             TestMigrations.REPOSITORY))
            if snake_walk:
                migration_api.upgrade(engine,
                                      TestMigrations.REPOSITORY,
                                      version + 1)
                self.assertEqual(version + 1,
                        migration_api.db_version(engine,
                                                 TestMigrations.REPOSITORY))
                migration_api.downgrade(engine,
                                        TestMigrations.REPOSITORY,
                                        version)
                self.assertEqual(version,
                        migration_api.db_version(engine,
                                                 TestMigrations.REPOSITORY))
Ejemplo n.º 7
0
    def _walk_versions(self, engine=None, snake_walk=False):
        # Determine latest version script from the repo, then
        # upgrade from 1 through to the latest, with no data
        # in the databases. This just checks that the schema itself
        # upgrades successfully.

        # Place the database under version control
        migration_api.version_control(engine, TestMigrations.REPOSITORY)
        self.assertEqual(
            0, migration_api.db_version(engine, TestMigrations.REPOSITORY))

        LOG.debug('latest version is %s' % TestMigrations.REPOSITORY.latest)

        for version in xrange(1, TestMigrations.REPOSITORY.latest + 1):
            # upgrade -> downgrade -> upgrade
            migration_api.upgrade(engine, TestMigrations.REPOSITORY, version)
            self.assertEqual(
                version,
                migration_api.db_version(engine, TestMigrations.REPOSITORY))
            if snake_walk:
                migration_api.downgrade(engine, TestMigrations.REPOSITORY,
                                        version - 1)
                self.assertEqual(
                    version - 1,
                    migration_api.db_version(engine,
                                             TestMigrations.REPOSITORY))
                migration_api.upgrade(engine, TestMigrations.REPOSITORY,
                                      version)
                self.assertEqual(
                    version,
                    migration_api.db_version(engine,
                                             TestMigrations.REPOSITORY))

        # Now walk it back down to 0 from the latest, testing
        # the downgrade paths.
        for version in reversed(xrange(0, TestMigrations.REPOSITORY.latest)):
            # downgrade -> upgrade -> downgrade
            migration_api.downgrade(engine, TestMigrations.REPOSITORY, version)
            self.assertEqual(
                version,
                migration_api.db_version(engine, TestMigrations.REPOSITORY))
            if snake_walk:
                migration_api.upgrade(engine, TestMigrations.REPOSITORY,
                                      version + 1)
                self.assertEqual(
                    version + 1,
                    migration_api.db_version(engine,
                                             TestMigrations.REPOSITORY))
                migration_api.downgrade(engine, TestMigrations.REPOSITORY,
                                        version)
                self.assertEqual(
                    version,
                    migration_api.db_version(engine,
                                             TestMigrations.REPOSITORY))
Ejemplo n.º 8
0
    def _walk_versions(self, engine=None, snake_walk=False, downgrade=True):
        # Determine latest version script from the repo, then
        # upgrade from 1 through to the latest, with no data
        # in the databases. This just checks that the schema itself
        # upgrades successfully.

        # Place the database under version control
        migration_api.version_control(engine, TestMigrations.REPOSITORY,
                                      migration.INIT_VERSION)
        self.assertEqual(
            migration.INIT_VERSION,
            migration_api.db_version(engine, TestMigrations.REPOSITORY))

        migration_api.upgrade(engine, TestMigrations.REPOSITORY,
                              migration.INIT_VERSION + 1)

        LOG.debug('latest version is %s' % TestMigrations.REPOSITORY.latest)

        for version in xrange(migration.INIT_VERSION + 2,
                              TestMigrations.REPOSITORY.latest + 1):
            # upgrade -> downgrade -> upgrade
            self._migrate_up(engine, version)
            if snake_walk:
                self._migrate_down(engine, version)
                self._migrate_up(engine, version)

        if downgrade:
            # Now walk it back down to 0 from the latest, testing
            # the downgrade paths.
            for version in reversed(
                    xrange(migration.INIT_VERSION + 2,
                           TestMigrations.REPOSITORY.latest + 1)):
                # downgrade -> upgrade -> downgrade
                self._migrate_down(engine, version)
                if snake_walk:
                    self._migrate_up(engine, version)
                    self._migrate_down(engine, version)
Ejemplo n.º 9
0
    def _migrate_up(self, engine, version, with_data=False):
        """migrate up to a new version of the db.

        We allow for data insertion and post checks at every
        migration version with special _prerun_### and
        _check_### functions in the main test.
        """
        if with_data:
            data = None
            prerun = getattr(self, "_prerun_%d" % version, None)
            if prerun:
                data = prerun(engine)

        migration_api.upgrade(engine,
                              TestMigrations.REPOSITORY,
                              version)
        self.assertEqual(version,
                migration_api.db_version(engine,
                                         TestMigrations.REPOSITORY))

        if with_data:
            check = getattr(self, "_check_%d" % version, None)
            if check:
                check(engine, data)