def configure_db(conf): """ Establish the database, create an engine if needed, and register the models. :param conf: Mapping of configuration options """ global _ENGINE, sa_logger, logger if not _ENGINE: conf.register_opts(db_opts) timeout = conf.sql_idle_timeout sql_connection = conf.sql_connection try: _ENGINE = create_engine(sql_connection, pool_recycle=timeout) except Exception, err: msg = _("Error configuring registry database with supplied " "sql_connection '%(sql_connection)s'. " "Got error:\n%(err)s") % locals() logger.error(msg) raise sa_logger = logging.getLogger('sqlalchemy.engine') if conf.debug: sa_logger.setLevel(logging.DEBUG) elif conf.verbose: sa_logger.setLevel(logging.INFO) models.register_models(_ENGINE)
def destroy_fixtures(self): # Easiest to just drop the models and re-create them... db_models.unregister_models(db_api._ENGINE) db_models.register_models(db_api._ENGINE)