"Fossies" - the Fresh Open Source Software Archive

Member "glance-24.1.0/glance/db/sqlalchemy/alembic_migrations/env.py" (8 Jun 2022, 2674 Bytes) of package /linux/misc/openstack/glance-24.1.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "env.py" see the Fossies "Dox" file reference documentation.

    1 # Copyright 2016 Rackspace
    2 # Copyright 2013 Intel Corporation
    3 #
    4 #    Licensed under the Apache License, Version 2.0 (the "License"); you may
    5 #    not use this file except in compliance with the License. You may obtain
    6 #    a copy of the License at
    7 #
    8 #         http://www.apache.org/licenses/LICENSE-2.0
    9 #
   10 #    Unless required by applicable law or agreed to in writing, software
   11 #    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
   12 #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
   13 #    License for the specific language governing permissions and limitations
   14 #    under the License.
   15 from logging import config as log_config
   16 
   17 from alembic import context
   18 from oslo_config import cfg
   19 from oslo_db.sqlalchemy import enginefacade
   20 
   21 from glance.db.sqlalchemy import models
   22 from glance.db.sqlalchemy import models_metadef
   23 
   24 # this is the Alembic Config object, which provides
   25 # access to the values within the .ini file in use.
   26 config = context.config
   27 CONF = cfg.CONF
   28 
   29 # other values from the config, defined by the needs of env.py,
   30 # can be acquired:
   31 # my_important_option = config.get_main_option("my_important_option")
   32 # ... etc.
   33 
   34 # Interpret the config file for Python logging.
   35 # This line sets up loggers basically.
   36 log_config.fileConfig(config.config_file_name)
   37 
   38 # add your model's MetaData object here
   39 # for 'autogenerate' support
   40 target_metadata = models.BASE.metadata
   41 for table in models_metadef.BASE_DICT.metadata.sorted_tables:
   42     target_metadata._add_table(table.name, table.schema, table)
   43 
   44 
   45 def run_migrations_offline():
   46     """Run migrations in 'offline' mode.
   47 
   48     This configures the context with just a URL
   49     and not an Engine, though an Engine is acceptable
   50     here as well.  By skipping the Engine creation
   51     we don't even need a DBAPI to be available.
   52 
   53     Calls to context.execute() here emit the given string to the
   54     script output.
   55 
   56     """
   57     url = CONF.database.connection
   58     context.configure(
   59         url=url, target_metadata=target_metadata, literal_binds=True)
   60 
   61     with context.begin_transaction():
   62         context.run_migrations()
   63 
   64 
   65 def run_migrations_online():
   66     """Run migrations in 'online' mode.
   67 
   68     In this scenario we need to create an Engine
   69     and associate a connection with the context.
   70 
   71     """
   72     engine = enginefacade.writer.get_engine()
   73 
   74     with engine.connect() as connection:
   75         context.configure(
   76             connection=connection,
   77             target_metadata=target_metadata
   78         )
   79 
   80         with context.begin_transaction():
   81             context.run_migrations()
   82 
   83 
   84 if context.is_offline_mode():
   85     run_migrations_offline()
   86 else:
   87     run_migrations_online()