<s> from __future__ import with_statement <EOL> from alembic import context <EOL> from logging . config import fileConfig <EOL> from subunit2sql . db import api as db_api <EOL> config = context . config <EOL> subunit2sql_config = config . subunit2sql_config <EOL> fileConfig ( config . config_file_name ) <EOL> target_metadata = None <EOL> def run_migrations_offline ( ) : <EOL> """<STR_LIT>""" <EOL> kwargs = dict ( ) <EOL> if subunit2sql_config . database . connection : <EOL> kwargs [ '<STR_LIT:url>' ] = subunit2sql_config . database . connection <EOL> elif subunit2sql_config . database . engine : <EOL> kwargs [ '<STR_LIT>' ] = subunit2sql_config . database . engine <EOL> else : <EOL> kwargs [ '<STR_LIT:url>' ] = config . get_main_option ( "<STR_LIT>" ) <EOL> kwargs [ '<STR_LIT>' ] = target_metadata <EOL> kwargs [ '<STR_LIT>' ] = True <EOL> context . configure ( ** kwargs ) <EOL> with context . begin_transaction ( ) : <EOL> context . run_migrations ( ) <EOL> def run_migrations_online ( ) : <EOL> """<STR_LIT>""" <EOL> facade = db_api . _create_facade_lazily ( ) <EOL> engine = facade . get_engine ( ) <EOL> connection = engine . connect ( ) <EOL> facade . _session_maker . configure ( bind = connection ) <EOL> context . configure ( connection = connection , <EOL> target_metadata = target_metadata , <EOL> render_as_batch = True ) <EOL> try : <EOL> with context . begin_transaction ( ) : <EOL> context . run_migrations ( ) <EOL> finally : <EOL> connection . close ( ) <EOL> facade . _session_maker . configure ( bind = engine ) <EOL> if context . is_offline_mode ( ) : <EOL> run_migrations_offline ( ) <EOL> else : <EOL> run_migrations_online ( ) </s>
