Пример #1
0
 def upgrade(self, conf, dburl=None, version=None):
     """Process the 'upgrade' Alembic command."""
     if dburl is None:
         commands.upgrade(to_version=str(version),
                          sql_url=CONF.sql_connection)
     else:
         commands.upgrade(to_version=str(version), sql_url=str(dburl))
Пример #2
0
 def upgrade(self, dburl=None, version=None):
     """Process the 'upgrade' Alembic command."""
     if dburl is None:
         commands.upgrade(to_version=str(version),
                          sql_url=CONF.sql_connection)
     else:
         commands.upgrade(to_version=str(version), sql_url=str(dburl))
Пример #3
0
def get_engine():
    """Return a SQLAlchemy engine."""
    """May assign _ENGINE if not already assigned"""
    global _ENGINE, sa_logger, _CONNECTION, _IDLE_TIMEOUT, _MAX_RETRIES, \
        _RETRY_INTERVAL

    if not _ENGINE:
        if not _CONNECTION:
            raise exception.BarbicanException('No _CONNECTION configured')

    #TODO(jfwood) connection_dict = sqlalchemy.engine.url.make_url(_CONNECTION)

        engine_args = {
            'pool_recycle': _IDLE_TIMEOUT,
            'echo': False,
            'convert_unicode': True
        }

        try:
            LOG.debug("Sql connection: {0}; Args: {1}".format(
                _CONNECTION, engine_args))
            _ENGINE = sqlalchemy.create_engine(_CONNECTION, **engine_args)

            #TODO(jfwood): if 'mysql' in connection_dict.drivername:
            #TODO(jfwood): sqlalchemy.event.listen(_ENGINE, 'checkout',
            #TODO(jfwood):                         ping_listener)

            _ENGINE.connect = wrap_db_error(_ENGINE.connect)
            _ENGINE.connect()
        except Exception as err:
            msg = u._("Error configuring registry database with supplied "
                      "sql_connection. Got error: %s") % err
            LOG.exception(msg)
            raise

        sa_logger = logging.getLogger('sqlalchemy.engine')
        if CONF.debug:
            sa_logger.setLevel(logging.DEBUG)

        if CONF.db_auto_create:
            meta = sqlalchemy.MetaData()
            meta.reflect(bind=_ENGINE)
            tables = meta.tables
            if tables and 'alembic_version' in tables:
                # Upgrade the database to the latest version.
                LOG.info(u._('Updating schema to latest version'))
                commands.upgrade()
            else:
                # Create database tables from our models.
                LOG.info(u._('Auto-creating barbican registry DB'))
                models.register_models(_ENGINE)

                # Sync the alembic version 'head' with current models.
                commands.stamp()

        else:
            LOG.info(u._('not auto-creating barbican registry DB'))

    return _ENGINE
Пример #4
0
def get_engine():
    """Return a SQLAlchemy engine."""
    """May assign _ENGINE if not already assigned"""
    global _ENGINE, sa_logger, _CONNECTION, _IDLE_TIMEOUT, _MAX_RETRIES, \
        _RETRY_INTERVAL

    if not _ENGINE:
        if not _CONNECTION:
            raise exception.BarbicanException('No _CONNECTION configured')

    #TODO(jfwood) connection_dict = sqlalchemy.engine.url.make_url(_CONNECTION)

        engine_args = {
            'pool_recycle': _IDLE_TIMEOUT,
            'echo': False,
            'convert_unicode': True}

        try:
            LOG.debug("Sql connection: {0}; Args: {1}".format(_CONNECTION,
                                                              engine_args))
            _ENGINE = sqlalchemy.create_engine(_CONNECTION, **engine_args)

        #TODO(jfwood): if 'mysql' in connection_dict.drivername:
        #TODO(jfwood): sqlalchemy.event.listen(_ENGINE, 'checkout',
        #TODO(jfwood):                         ping_listener)

            _ENGINE.connect = wrap_db_error(_ENGINE.connect)
            _ENGINE.connect()
        except Exception as err:
            msg = u._("Error configuring registry database with supplied "
                      "sql_connection. Got error: %s") % err
            LOG.exception(msg)
            raise

        sa_logger = logging.getLogger('sqlalchemy.engine')
        if CONF.debug:
            sa_logger.setLevel(logging.DEBUG)

        if CONF.db_auto_create:
            meta = sqlalchemy.MetaData()
            meta.reflect(bind=_ENGINE)
            tables = meta.tables
            if tables and 'alembic_version' in tables:
                # Upgrade the database to the latest version.
                LOG.info(u._('Updating schema to latest version'))
                commands.upgrade()
            else:
                # Create database tables from our models.
                LOG.info(u._('Auto-creating barbican registry DB'))
                models.register_models(_ENGINE)

                # Sync the alembic version 'head' with current models.
                commands.stamp()

        else:
            LOG.info(u._('not auto-creating barbican registry DB'))

    return _ENGINE
Пример #5
0
def _auto_generate_tables(engine, tables):
    if tables and 'alembic_version' in tables:
        # Upgrade the database to the latest version.
        LOG.info(u._LI('Updating schema to latest version'))
        commands.upgrade()
    else:
        # Create database tables from our models.
        LOG.info(u._LI('Auto-creating barbican registry DB'))
        models.register_models(engine)

        # Sync the alembic version 'head' with current models.
        commands.stamp()
Пример #6
0
def get_engine():
    """Return a SQLAlchemy engine."""
    """May assign _ENGINE if not already assigned"""
    global _ENGINE, sa_logger, _CONNECTION, _IDLE_TIMEOUT, _MAX_RETRIES, \
        _RETRY_INTERVAL

    if not _ENGINE:
        if not _CONNECTION:
            raise exception.BarbicanException('No _CONNECTION configured')


#TODO:        connection_dict = sqlalchemy.engine.url.make_url(_CONNECTION)

        engine_args = {
            'pool_recycle': _IDLE_TIMEOUT,
            'echo': False,
            'convert_unicode': True
        }

        try:
            LOG.debug("Sql connection: {0}; Args: {1}".format(
                _CONNECTION, engine_args))
            _ENGINE = sqlalchemy.create_engine(_CONNECTION, **engine_args)

            #TODO:          if 'mysql' in connection_dict.drivername:
            #TODO:          sqlalchemy.event.listen(_ENGINE, 'checkout', ping_listener)

            _ENGINE.connect = wrap_db_error(_ENGINE.connect)
            _ENGINE.connect()
        except Exception as err:
            msg = _("Error configuring registry database with supplied "
                    "sql_connection. Got error: %s") % err
            LOG.exception(msg)
            raise

        sa_logger = logging.getLogger('sqlalchemy.engine')
        if CONF.debug:
            sa_logger.setLevel(logging.DEBUG)

        if CONF.db_auto_create:
            LOG.info(_('auto-creating barbican registry DB'))
            models.register_models(_ENGINE)

            # Upgrade the database to the latest version.
            commands.upgrade()
        else:
            LOG.info(_('not auto-creating barbican registry DB'))

    return _ENGINE
Пример #7
0
def get_engine():
    """Return a SQLAlchemy engine."""
    """May assign _ENGINE if not already assigned"""
    global _ENGINE, sa_logger, _CONNECTION, _IDLE_TIMEOUT, _MAX_RETRIES, \
        _RETRY_INTERVAL

    if not _ENGINE:
        if not _CONNECTION:
            raise exception.BarbicanException('No _CONNECTION configured')

#TODO:        connection_dict = sqlalchemy.engine.url.make_url(_CONNECTION)

        engine_args = {
            'pool_recycle': _IDLE_TIMEOUT,
            'echo': False,
            'convert_unicode': True}

        try:
            LOG.debug("Sql connection: {0}; Args: {1}".format(_CONNECTION,
                                                              engine_args))
            _ENGINE = sqlalchemy.create_engine(_CONNECTION, **engine_args)

#TODO:          if 'mysql' in connection_dict.drivername:
#TODO:          sqlalchemy.event.listen(_ENGINE, 'checkout', ping_listener)

            _ENGINE.connect = wrap_db_error(_ENGINE.connect)
            _ENGINE.connect()
        except Exception as err:
            msg = _("Error configuring registry database with supplied "
                    "sql_connection. Got error: %s") % err
            LOG.exception(msg)
            raise

        sa_logger = logging.getLogger('sqlalchemy.engine')
        if CONF.debug:
            sa_logger.setLevel(logging.DEBUG)

        if CONF.db_auto_create:
            LOG.info(_('auto-creating barbican registry DB'))
            models.register_models(_ENGINE)

            # Upgrade the database to the latest version.
            commands.upgrade()
        else:
            LOG.info(_('not auto-creating barbican registry DB'))

    return _ENGINE
Пример #8
0
 def upgrade(self, args):
     """Process the 'upgrade' Alembic command."""
     commands.upgrade(to_version=args.version, sql_url=args.dburl)
Пример #9
0
 def upgrade(self, args):
     """Process the 'upgrade' Alembic command."""
     commands.upgrade(to_version=args.version, sql_url=args.dburl)
Пример #10
0
 def upgrade(self, args):
     """Process the 'upgrade' Alembic command."""
     LOG.debug("Performing database schema migration...")
     commands.upgrade(to_version=args.version, sql_url=args.dburl)
Пример #11
0
 def upgrade(self, args):
     """Process the 'upgrade' Alembic command."""
     LOG.debug("Performing database schema migration...")
     commands.upgrade(to_version=args.version, sql_url=args.dburl)