|
@ -14,17 +14,19 @@ config = context.config |
|
|
# Interpret the config file for Python logging. |
|
|
# Interpret the config file for Python logging. |
|
|
# This line sets up loggers basically. |
|
|
# This line sets up loggers basically. |
|
|
fileConfig(config.config_file_name) |
|
|
fileConfig(config.config_file_name) |
|
|
logger = logging.getLogger('alembic.env') |
|
|
logger = logging.getLogger("alembic.env") |
|
|
|
|
|
|
|
|
# add your model's MetaData object here |
|
|
# add your model's MetaData object here |
|
|
# for 'autogenerate' support |
|
|
# for 'autogenerate' support |
|
|
# from myapp import mymodel |
|
|
# from myapp import mymodel |
|
|
# target_metadata = mymodel.Base.metadata |
|
|
# target_metadata = mymodel.Base.metadata |
|
|
config.set_main_option( |
|
|
config.set_main_option( |
|
|
'sqlalchemy.url', |
|
|
"sqlalchemy.url", |
|
|
str(current_app.extensions['migrate'].db.get_engine().url).replace( |
|
|
str(current_app.extensions["migrate"].db.get_engine().url).replace( |
|
|
'%', '%%')) |
|
|
"%", "%%" |
|
|
target_metadata = current_app.extensions['migrate'].db.metadata |
|
|
), |
|
|
|
|
|
) |
|
|
|
|
|
target_metadata = current_app.extensions["migrate"].db.metadata |
|
|
|
|
|
|
|
|
# other values from the config, defined by the needs of env.py, |
|
|
# other values from the config, defined by the needs of env.py, |
|
|
# can be acquired: |
|
|
# can be acquired: |
|
@ -65,20 +67,20 @@ def run_migrations_online(): |
|
|
# when there are no changes to the schema |
|
|
# when there are no changes to the schema |
|
|
# reference: http://alembic.zzzcomputing.com/en/latest/cookbook.html |
|
|
# reference: http://alembic.zzzcomputing.com/en/latest/cookbook.html |
|
|
def process_revision_directives(context, revision, directives): |
|
|
def process_revision_directives(context, revision, directives): |
|
|
if getattr(config.cmd_opts, 'autogenerate', False): |
|
|
if getattr(config.cmd_opts, "autogenerate", False): |
|
|
script = directives[0] |
|
|
script = directives[0] |
|
|
if script.upgrade_ops.is_empty(): |
|
|
if script.upgrade_ops.is_empty(): |
|
|
directives[:] = [] |
|
|
directives[:] = [] |
|
|
logger.info('No changes in schema detected.') |
|
|
logger.info("No changes in schema detected.") |
|
|
|
|
|
|
|
|
connectable = current_app.extensions['migrate'].db.get_engine() |
|
|
connectable = current_app.extensions["migrate"].db.get_engine() |
|
|
|
|
|
|
|
|
with connectable.connect() as connection: |
|
|
with connectable.connect() as connection: |
|
|
context.configure( |
|
|
context.configure( |
|
|
connection=connection, |
|
|
connection=connection, |
|
|
target_metadata=target_metadata, |
|
|
target_metadata=target_metadata, |
|
|
process_revision_directives=process_revision_directives, |
|
|
process_revision_directives=process_revision_directives, |
|
|
**current_app.extensions['migrate'].configure_args |
|
|
**current_app.extensions["migrate"].configure_args, |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
with context.begin_transaction(): |
|
|
with context.begin_transaction(): |
|
|