Esempio n. 1
0
    def _migrate_up(self, engine, config, 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.
        """
        # NOTE(sdague): try block is here because it's impossible to debug
        # where a failed data migration happens otherwise
        try:
            data = None
            pre_upgrade = getattr(
                self, "_pre_upgrade_%s" % version, None)
            if pre_upgrade:
                data = pre_upgrade(engine)

            sync.do_alembic_command(config, 'upgrade', version)
            self.assertEqual(version, sync._version(config))
            check = getattr(self, "_check_%s" % version, None)
            if check:
                check(engine, data)
        except Exception:
            LOG.error("Failed to migrate to version %(version)s on engine "
                      "%(engine)s", {'version': version, 'engine': engine})
            raise
Esempio n. 2
0
 def _cache_schema(self):
     global DB_SCHEMA
     if not DB_SCHEMA:
         engine = self.get_engine()
         conn = engine.connect()
         alemb_conf = db_sync.get_alembic_config()
         db_sync.do_alembic_command(alemb_conf, 'upgrade', revision='head')
         DB_SCHEMA = "".join(line for line in conn.connection.iterdump())
Esempio n. 3
0
 def db_sync(self, engine):
     with patch_with_engine(engine):
         alemb_conf = sync.get_alembic_config()
         sync.do_alembic_command(alemb_conf, 'upgrade', revision='head')