cdr/env.py

Go to the documentation of this file.
00001 from __future__ import with_statement
00002 from alembic import context
00003 from sqlalchemy import engine_from_config, pool
00004 from logging.config import fileConfig
00005 
00006 # this is the Alembic Config object, which provides
00007 # access to the values within the .ini file in use.
00008 config = context.config
00009 
00010 # Interpret the config file for Python logging.
00011 # This line sets up loggers basically.
00012 try:
00013     fileConfig(config.config_file_name)
00014 except:
00015     pass
00016 
00017 # add your model's MetaData object here
00018 # for 'autogenerate' support
00019 # from myapp import mymodel
00020 # target_metadata = mymodel.Base.metadata
00021 target_metadata = None
00022 
00023 # other values from the config, defined by the needs of env.py,
00024 # can be acquired:
00025 # my_important_option = config.get_main_option("my_important_option")
00026 # ... etc.
00027 
00028 def run_migrations_offline():
00029     """Run migrations in 'offline' mode.
00030 
00031     This configures the context with just a URL
00032     and not an Engine, though an Engine is acceptable
00033     here as well.  By skipping the Engine creation
00034     we don't even need a DBAPI to be available.
00035 
00036     Calls to context.execute() here emit the given string to the
00037     script output.
00038 
00039     """
00040     url = config.get_main_option("sqlalchemy.url")
00041     context.configure(url=url)
00042 
00043     with context.begin_transaction():
00044         context.run_migrations()
00045 
00046 def run_migrations_online():
00047     """Run migrations in 'online' mode.
00048 
00049     In this scenario we need to create an Engine
00050     and associate a connection with the context.
00051 
00052     """
00053     engine = engine_from_config(
00054                 config.get_section(config.config_ini_section),
00055                 prefix='sqlalchemy.',
00056                 poolclass=pool.NullPool)
00057 
00058     connection = engine.connect()
00059     context.configure(
00060                 connection=connection,
00061                 target_metadata=target_metadata
00062                 )
00063 
00064     try:
00065         with context.begin_transaction():
00066             context.run_migrations()
00067     finally:
00068         connection.close()
00069 
00070 if context.is_offline_mode():
00071     run_migrations_offline()
00072 else:
00073     run_migrations_online()
00074 

Generated on Thu Apr 16 06:27:33 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6