def _walk_versions(self, 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
        alembic_cfg = migration._alembic_config()
        script_directory = script.ScriptDirectory.from_config(alembic_cfg)

        self.assertIsNone(self.migration_api.version())

        versions = [ver for ver in script_directory.walk_revisions()]

        LOG.debug('latest version is %s', versions[0].revision)

        for version in reversed(versions):
            self._migrate_up(version.revision, with_data=True)
            if snake_walk:
                downgraded = self._migrate_down(
                    version, with_data=True)
                if downgraded:
                    self._migrate_up(version.revision)

        if downgrade:
            for version in versions:
                downgraded = self._migrate_down(version)
                if snake_walk and downgraded:
                    self._migrate_up(version.revision)
                    self._migrate_down(version)
    def test_single_branch(self):
        alembic_cfg = migration._alembic_config()
        script_directory = script.ScriptDirectory.from_config(alembic_cfg)

        actual_result = script_directory.get_heads()

        self.assertEqual(1, len(actual_result),
                         "Db migrations should have only one branch.")