Asterisk - The Open Source Telephony Project GIT-master-f36a736
Functions | Variables
env Namespace Reference

Functions

def run_migrations_offline ()
 
def run_migrations_online ()
 

Variables

 Base = declarative_base(metadata=meta)
 
 config = context.config
 
 logger = logging.getLogger('alembic.runtime.setup')
 
 meta
 below block is needed for mssql More...
 
 target_metadata = None
 

Function Documentation

◆ run_migrations_offline()

def run_migrations_offline ( )
Run migrations in 'offline' mode.

This configures the context with just a URL
and not an Engine, though an Engine is acceptable
here as well.  By skipping the Engine creation
we don't even need a DBAPI to be available.

Calls to context.execute() here emit the given string to the
script output.

Definition at line 45 of file cdr/env.py.

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 = config.get_main_option("sqlalchemy.url")
58 context.configure(url=url,target_metadata=target_metadata)
59
60 with context.begin_transaction():
61 context.run_migrations()
62
def run_migrations_offline()
Definition: cdr/env.py:45

Referenced by run_migrations_online().

◆ run_migrations_online()

def run_migrations_online ( )
Run migrations in 'online' mode.

In this scenario we need to create an Engine
and associate a connection with the context.

Definition at line 63 of file cdr/env.py.

64 """Run migrations in 'online' mode.
65
66 In this scenario we need to create an Engine
67 and associate a connection with the context.
68
69 """
70 script_location = config.get_main_option('script_location')
71
72 engine = engine_from_config(
73 config.get_section(config.config_ini_section),
74 prefix='sqlalchemy.',
75 poolclass=pool.NullPool)
76
77 logger.info('Testing for an old alembic_version table.')
78
79 with engine.connect() as connection:
80 context.configure(
81 connection=connection,
82 target_metadata=target_metadata
83 )
84
85 found = False
86 mc = context.get_context()
87 current_db_revision = mc.get_current_revision()
88 script = ScriptDirectory.from_config(config)
89 """ If there was an existing alembic_version table, we need to
90 check that it's current revision is in the history for the tree
91 we're working with.
92 """
93 for x in script.iterate_revisions('head', 'base'):
94 if x.revision == current_db_revision:
95 """ An alembic_versions table was found and it belongs to
96 this alembic tree
97 """
98 logger.info(
99 ('An old alembic_version table at revision %s was '
100 'found for %s. Renaming to alembic_version_%s.'),
101 current_db_revision, script_location,
102 script_location)
103 op = Operations(mc)
104 try:
105 with context.begin_transaction():
106 op.rename_table(
107 'alembic_version', 'alembic_version_%s'
108 % script_location)
109 found = True
110 except:
111 logger.error(('Unable to rename alembic_version to '
112 'alembic_version_%s.'),
113 script_location)
114 connection.close()
115 return
116
117 break
118
119 if not found:
120 logger.info('Didn\'t find an old alembic_version table.')
121 logger.info('Trying alembic_version_%s.' % script_location)
122
123 """ We MAY have an alembic_version table that doesn't belong to
124 this tree but if we still don't have an alembic_version_<tree>
125 table, alembic will create it.
126 """
127 with engine.connect() as connection:
128 context.configure(
129 connection=connection,
130 target_metadata=target_metadata,
131 version_table='alembic_version_' + script_location
132 )
133 mc = context.get_context()
134 current_db_revision = mc.get_current_revision()
135 if current_db_revision:
136 logger.info(
137 'Using the alembic_version_%s table at revision %s.',
138 script_location, current_db_revision)
139 else:
140 logger.info('Creating new alembic_version_%s table.',
141 script_location)
142
143 with context.begin_transaction():
144 context.run_migrations()
145
146
def run_migrations_online()
Definition: cdr/env.py:63

References run_migrations_offline(), and run_migrations_online().

Referenced by run_migrations_online().

Variable Documentation

◆ Base

Base = declarative_base(metadata=meta)

Definition at line 29 of file cdr/env.py.

◆ config

config = context.config

Definition at line 12 of file cdr/env.py.

◆ logger

logger = logging.getLogger('alembic.runtime.setup')

Definition at line 31 of file cdr/env.py.

◆ meta

meta

below block is needed for mssql

Definition at line 22 of file cdr/env.py.

Referenced by nroot(), send_trunk(), socket_process_helper(), and socket_process_meta().

◆ target_metadata

target_metadata = None

Definition at line 36 of file cdr/env.py.