#NEWLINE# def _compare_indexes_and_uniques( schema , tname , object_filters , conn_table , metadata_table , diffs , autogen_context , inspector ) : #NEWLINE# #INDENT# is_create_table = ( conn_table is None ) #NEWLINE# metadata_unique_constraints = set ( ( uq for uq in metadata_table . constraints if isinstance ( uq , sa_schema . UniqueConstraint ) ) ) #NEWLINE# metadata_indexes = set ( metadata_table . indexes ) #NEWLINE# if ( ( conn_table is not None ) and hasattr ( inspector , 'get_unique_constraints' ) ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# conn_uniques = inspector . get_unique_constraints ( tname ) #NEWLINE# #UNINDENT# except ( NotImplementedError , NoSuchTableError ) : #NEWLINE# #INDENT# conn_uniques = [ ] #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# conn_uniques = [ ] #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# conn_indexes = inspector . get_indexes ( tname ) #NEWLINE# #UNINDENT# except NoSuchTableError : #NEWLINE# #INDENT# conn_indexes = [ ] #NEWLINE# #UNINDENT# conn_uniques = set ( ( _make_unique_constraint ( uq_def , conn_table ) for uq_def in conn_uniques ) ) #NEWLINE# conn_indexes = set ( ( _make_index ( ix , conn_table ) for ix in conn_indexes ) ) #NEWLINE# autogen_context [ 'context' ] . impl . correct_for_autogen_constraints ( conn_uniques , conn_indexes , metadata_unique_constraints , metadata_indexes ) #NEWLINE# metadata_unique_constraints = set ( ( _uq_constraint_sig ( uq ) for uq in metadata_unique_constraints ) ) #NEWLINE# metadata_indexes = set ( ( _ix_constraint_sig ( ix ) for ix in metadata_indexes ) ) #NEWLINE# conn_unique_constraints = set ( ( _uq_constraint_sig ( uq ) for uq in conn_uniques ) ) #NEWLINE# conn_indexes = set ( ( _ix_constraint_sig ( ix ) for ix in conn_indexes ) ) #NEWLINE# metadata_names = dict ( ( ( c . name , c ) for c in metadata_unique_constraints . union ( metadata_indexes ) if ( c . name is not None ) ) ) #NEWLINE# conn_uniques_by_name = dict ( ( ( c . name , c ) for c in conn_unique_constraints ) ) #NEWLINE# conn_indexes_by_name = dict ( ( ( c . name , c ) for c in conn_indexes ) ) #NEWLINE# conn_names = dict ( ( ( c . name , c ) for c in conn_unique_constraints . union ( conn_indexes ) if ( c . name is not None ) ) ) #NEWLINE# doubled_constraints = dict ( ( ( name , ( conn_uniques_by_name [ name ] , conn_indexes_by_name [ name ] ) ) for name in set ( conn_uniques_by_name ) . intersection ( conn_indexes_by_name ) ) ) #NEWLINE# conn_uniques_by_sig = dict ( ( ( uq . sig , uq ) for uq in conn_unique_constraints ) ) #NEWLINE# metadata_uniques_by_sig = dict ( ( ( uq . sig , uq ) for uq in metadata_unique_constraints ) ) #NEWLINE# metadata_indexes_by_sig = dict ( ( ( ix . sig , ix ) for ix in metadata_indexes ) ) #NEWLINE# unnamed_metadata_uniques = dict ( ( ( uq . sig , uq ) for uq in metadata_unique_constraints if ( uq . name is None ) ) ) #NEWLINE# def obj_added( obj ) : #NEWLINE# #INDENT# if obj . is_index : #NEWLINE# #INDENT# diffs . append ( ( 'add_index' , obj . const ) ) #NEWLINE# log . info ( "Detected added index '%s' on %s" , obj . name , ', ' . join ( [ ( "'%s'" % obj . column_names ) ] ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if is_create_table : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# diffs . append ( ( 'add_constraint' , obj . const ) ) #NEWLINE# log . info ( "Detected added unique constraint '%s' on %s" , obj . name , ', ' . join ( [ ( "'%s'" % obj . column_names ) ] ) ) #NEWLINE# #UNINDENT# #UNINDENT# def obj_removed( obj ) : #NEWLINE# #INDENT# if obj . is_index : #NEWLINE# #INDENT# diffs . append ( ( 'remove_index' , obj . const ) ) #NEWLINE# log . info ( "Detected removed index '%s' on '%s'" , obj . name , tname ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# diffs . append ( ( 'remove_constraint' , obj . const ) ) #NEWLINE# log . info ( "Detected removed unique constraint '%s' on '%s'" , obj . name , tname ) #NEWLINE# #UNINDENT# #UNINDENT# def obj_changed( old , new , msg ) : #NEWLINE# #INDENT# if old . is_index : #NEWLINE# #INDENT# log . info ( "Detected changed index '%s' on '%s':%s" , old . name , tname , ', ' . join ( msg ) ) #NEWLINE# diffs . append ( ( 'remove_index' , old . const ) ) #NEWLINE# diffs . append ( ( 'add_index' , new . const ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# log . info ( "Detected changed unique constraint '%s' on '%s':%s" , old . name , tname , ', ' . join ( msg ) ) #NEWLINE# diffs . append ( ( 'remove_constraint' , old . const ) ) #NEWLINE# diffs . append ( ( 'add_constraint' , new . const ) ) #NEWLINE# #UNINDENT# #UNINDENT# for added_name in sorted ( set ( metadata_names ) . difference ( conn_names ) ) : #NEWLINE# #INDENT# obj = metadata_names [ added_name ] #NEWLINE# obj_added ( obj ) #NEWLINE# #UNINDENT# for existing_name in sorted ( set ( metadata_names ) . intersection ( conn_names ) ) : #NEWLINE# #INDENT# metadata_obj = metadata_names [ existing_name ] #NEWLINE# if ( existing_name in doubled_constraints ) : #NEWLINE# #INDENT# ( conn_uq , conn_idx ) = doubled_constraints [ existing_name ] #NEWLINE# if metadata_obj . is_index : #NEWLINE# #INDENT# conn_obj = conn_idx #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# conn_obj = conn_uq #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# conn_obj = conn_names [ existing_name ] #NEWLINE# #UNINDENT# if ( conn_obj . is_index != metadata_obj . is_index ) : #NEWLINE# #INDENT# obj_removed ( conn_obj ) #NEWLINE# obj_added ( metadata_obj ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# msg = [ ] #NEWLINE# if ( conn_obj . is_unique != metadata_obj . is_unique ) : #NEWLINE# #INDENT# msg . append ( ( ' unique=%r to unique=%r' % ( conn_obj . is_unique , metadata_obj . is_unique ) ) ) #NEWLINE# #UNINDENT# if ( conn_obj . sig != metadata_obj . sig ) : #NEWLINE# #INDENT# msg . append ( ( ' columns %r to %r' % ( conn_obj . sig , metadata_obj . sig ) ) ) #NEWLINE# #UNINDENT# if msg : #NEWLINE# #INDENT# obj_changed ( conn_obj , metadata_obj , msg ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# for removed_name in sorted ( set ( conn_names ) . difference ( metadata_names ) ) : #NEWLINE# #INDENT# conn_obj = conn_names [ removed_name ] #NEWLINE# if ( ( not conn_obj . is_index ) and ( conn_obj . sig in unnamed_metadata_uniques ) ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( removed_name in doubled_constraints ) : #NEWLINE# #INDENT# if ( ( conn_obj . sig not in metadata_indexes_by_sig ) and ( conn_obj . sig not in metadata_uniques_by_sig ) ) : #NEWLINE# #INDENT# ( conn_uq , conn_idx ) = doubled_constraints [ removed_name ] #NEWLINE# obj_removed ( conn_uq ) #NEWLINE# obj_removed ( conn_idx ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# obj_removed ( conn_obj ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# for uq_sig in unnamed_metadata_uniques : #NEWLINE# #INDENT# if ( uq_sig not in conn_uniques_by_sig ) : #NEWLINE# #INDENT# obj_added ( unnamed_metadata_uniques [ uq_sig ] )