예제 #1
0
def init(database_url=None):
    """Initialize database.

    :param database_url: string, database url.
    """
    global ENGINE
    global SCOPED_SESSION
    if not database_url:
        database_url = config.get_connection_url()
    logging.info('init database %s', database_url)
    #print database_url
    #root_logger = logging.getLogger()
    #fine_debug = root_logger.isEnabledFor(logsetting.LOGLEVEL_MAPPING['fine'])
    #if fine_debug:
    #    logging.getLogger('sqlalchemy.engine').setLevel(logging.INFO)
    #finest_debug = root_logger.isEnabledFor(
    #    logsetting.LOGLEVEL_MAPPING['finest']
    #)
    #if finest_debug:
    #    logging.getLogger('sqlalchemy.dialects').setLevel(logging.INFO)
    #    logging.getLogger('sqlalchemy.pool').setLevel(logging.INFO)
    #    logging.getLogger('sqlalchemy.orm').setLevel(logging.INFO)
    poolclass = POOL_MAPPING[config.get_database_pool_type()]
    ENGINE = create_engine(
        database_url,
        convert_unicode=True,
        poolclass=poolclass,
        echo=False,
    )
    SESSION.configure(bind=ENGINE)
    SCOPED_SESSION = scoped_session(SESSION)
    models.Base.query = SCOPED_SESSION.query_property()
예제 #2
0
def init(database_url=None):
    """Initialize database.

    :param database_url: string, database url.
    """
    global ENGINE
    global SCOPED_SESSION
    if not database_url:
        database_url = config.get_connection_url()
    logging.info('init database %s', database_url)
    #print database_url
    #root_logger = logging.getLogger()
    #fine_debug = root_logger.isEnabledFor(logsetting.LOGLEVEL_MAPPING['fine'])
    #if fine_debug:
    #    logging.getLogger('sqlalchemy.engine').setLevel(logging.INFO)
    #finest_debug = root_logger.isEnabledFor(
    #    logsetting.LOGLEVEL_MAPPING['finest']
    #)
    #if finest_debug:
    #    logging.getLogger('sqlalchemy.dialects').setLevel(logging.INFO)
    #    logging.getLogger('sqlalchemy.pool').setLevel(logging.INFO)
    #    logging.getLogger('sqlalchemy.orm').setLevel(logging.INFO)
    poolclass = POOL_MAPPING[config.get_database_pool_type()]
    ENGINE = create_engine(
        database_url, convert_unicode=True,
        poolclass=poolclass
    )
    SESSION.configure(bind=ENGINE)
    SCOPED_SESSION = scoped_session(SESSION)
    models.Base.query = SCOPED_SESSION.query_property()
예제 #3
0
def new_database():
    engine = config.get_connection_url()
    if not database_exists(engine):
        print "Create database " + engine
        create_database(engine)
        return True
    elif not database.check_tables():
        print "Check tables and incomplete tables."
        return True
    return False
예제 #4
0
def new_database():
    engine = config.get_connection_url()
    if not database_exists(engine):
        print "Create database " + engine
        create_database(engine)
        return True
    elif not database.check_tables():
        print "Check tables and incomplete tables."
        return True
    return False