예제 #1
0
    def _walk_versions(self, engine=None, snake_walk=False, downgrade=True, initial_version=None):
        # 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
        init_version = migration.INIT_VERSION
        if initial_version is not None:
            init_version = initial_version
        migration_api.version_control(engine, TestMigrations.REPOSITORY, init_version)
        self.assertEqual(init_version, migration_api.db_version(engine, TestMigrations.REPOSITORY))

        migration_api.upgrade(engine, TestMigrations.REPOSITORY, init_version + 1)

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

        for version in xrange(init_version + 2, TestMigrations.REPOSITORY.latest + 1):
            # upgrade -> downgrade -> upgrade
            self._migrate_up(engine, version, with_data=True)
            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(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)
예제 #2
0
 def _migrate_down(self, engine, version):
     migration_api.downgrade(engine,
                             TestMigrations.REPOSITORY,
                             version)
     self.assertEqual(version,
                      migration_api.db_version(engine,
                                               TestMigrations.REPOSITORY))
예제 #3
0
    def _migrate_down(self, engine, version, with_data=False):
        migration_api.downgrade(engine, TestMigrations.REPOSITORY, version)
        self.assertEqual(
            version, migration_api.db_version(engine,
                                              TestMigrations.REPOSITORY))

        # NOTE(sirp): `version` is what we're downgrading to (i.e. the 'target'
        # version). So if we have any downgrade checks, they need to be run for
        # the previous (higher numbered) migration.
        if with_data:
            post_downgrade = getattr(self,
                                     "_post_downgrade_%03d" % (version + 1),
                                     None)
            if post_downgrade:
                post_downgrade(engine)
예제 #4
0
    def _migrate_down(self, engine, version, with_data=False):
        migration_api.downgrade(engine,
                                TestMigrations.REPOSITORY,
                                version)
        self.assertEqual(version,
                         migration_api.db_version(engine,
                                                  TestMigrations.REPOSITORY))

        # NOTE(sirp): `version` is what we're downgrading to (i.e. the 'target'
        # version). So if we have any downgrade checks, they need to be run for
        # the previous (higher numbered) migration.
        if with_data:
            post_downgrade = getattr(self, "_post_downgrade_%03d" %
                                           (version + 1), None)
            if post_downgrade:
                post_downgrade(engine)
예제 #5
0
    def _walk_versions(self,
                       engine=None,
                       snake_walk=False,
                       downgrade=True,
                       initial_version=None):
        # 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
        init_version = migration.INIT_VERSION
        if initial_version is not None:
            init_version = initial_version
        migration_api.version_control(engine, TestMigrations.REPOSITORY,
                                      init_version)
        self.assertEqual(
            init_version,
            migration_api.db_version(engine, TestMigrations.REPOSITORY))

        migration_api.upgrade(engine, TestMigrations.REPOSITORY,
                              init_version + 1)

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

        for version in xrange(init_version + 2,
                              TestMigrations.REPOSITORY.latest + 1):
            # upgrade -> downgrade -> upgrade
            self._migrate_up(engine, version, with_data=True)
            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(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)
예제 #6
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_%3.3d" % 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_%3.3d" % version, None)
            if check:
                check(engine, data)
예제 #7
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 _pre_upgrade_### and
        _check_### functions in the main test.
        """
        if with_data:
            data = None
            pre_upgrade = getattr(self, "_pre_upgrade_%3.3d" % version, None)
            if pre_upgrade:
                data = pre_upgrade(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_%3.3d" % version, None)
            if check:
                check(engine, data)
예제 #8
0
 def db_version():
     return migration_api.db_version(engine, TestMigrations.REPOSITORY)
예제 #9
0
 def db_version():
     return migration_api.db_version(engine, TestMigrations.REPOSITORY)
예제 #10
0
 def _migrate_down(self, engine, version):
     migration_api.downgrade(engine, TestMigrations.REPOSITORY, version)
     self.assertEqual(
         version, migration_api.db_version(engine,
                                           TestMigrations.REPOSITORY))