def heal(): # This is needed else the heal script will start spewing # a lot of pointless warning messages from alembic. LOG.setLevel(logging.INFO) if context.is_offline_mode(): return models_metadata = frozen_models.get_metadata() # Compare metadata from models and metadata from migrations # Diff example: # [ ( 'add_table', # Table('bat', MetaData(bind=None), # Column('info', String(), table=<bat>), schema=None)), # ( 'remove_table', # Table(u'bar', MetaData(bind=None), # Column(u'data', VARCHAR(), table=<bar>), schema=None)), # ( 'add_column', # None, # 'foo', # Column('data', Integer(), table=<foo>)), # ( 'remove_column', # None, # 'foo', # Column(u'old_data', VARCHAR(), table=None)), # [ ( 'modify_nullable', # None, # 'foo', # u'x', # { 'existing_server_default': None, # 'existing_type': INTEGER()}, # True, # False)]] opts = { 'compare_type': _compare_type, 'compare_server_default': _compare_server_default, } mc = alembic.migration.MigrationContext.configure(op.get_bind(), opts=opts) set_storage_engine(op.get_bind(), "InnoDB") diff1 = autogen.compare_metadata(mc, models_metadata) # Alembic does not contain checks for foreign keys. Because of that it # checks separately. added_fks, dropped_fks = check_foreign_keys(models_metadata) diff = dropped_fks + diff1 + added_fks # For each difference run command for el in diff: execute_alembic_command(el)
def heal(): # This is needed else the heal script will start spewing # a lot of pointless warning messages from alembic. LOG.setLevel(logging.INFO) if context.is_offline_mode(): return models_metadata = frozen_models.get_metadata() # Compare metadata from models and metadata from migrations # Diff example: # [ ( 'add_table', # Table('bat', MetaData(bind=None), # Column('info', String(), table=<bat>), schema=None)), # ( 'remove_table', # Table(u'bar', MetaData(bind=None), # Column(u'data', VARCHAR(), table=<bar>), schema=None)), # ( 'add_column', # None, # 'foo', # Column('data', Integer(), table=<foo>)), # ( 'remove_column', # None, # 'foo', # Column(u'old_data', VARCHAR(), table=None)), # [ ( 'modify_nullable', # None, # 'foo', # u'x', # { 'existing_server_default': None, # 'existing_type': INTEGER()}, # True, # False)]] opts = { 'compare_type': _compare_type, 'compare_server_default': _compare_server_default, } mc = alembic.migration.MigrationContext.configure(op.get_bind(), opts=opts) diff1 = autogen.compare_metadata(mc, models_metadata) # Alembic does not contain checks for foreign keys. Because of that it # checks separately. diff2 = check_foreign_keys(models_metadata) diff = diff1 + diff2 # For each difference run command for el in diff: execute_alembic_command(el)