示例#1
0
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)
示例#2
0
文件: api.py 项目: wendy-king/x7_venv
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)
示例#3
0
 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)
示例#4
0
 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)