#NEWLINE# def diff_map( self , inconstrs ) : #NEWLINE# #INDENT# 'Generate SQL to transform existing constraints\n\n        :param inconstrs: a YAML map defining the new constraints\n        :return: list of SQL statements\n\n        Compares the existing constraint definitions, as fetched from\n        the catalogs, to the input map and generates SQL statements to\n        transform the constraints accordingly.\n        ' #NEWLINE# stmts = [ ] #NEWLINE# for turn in ( 1 , 2 ) : #NEWLINE# #INDENT# for ( sch , tbl , cns ) in self : #NEWLINE# #INDENT# constr = self [ ( sch , tbl , cns ) ] #NEWLINE# if getattr ( constr , 'inherited' , False ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# if isinstance ( constr , ForeignKey ) : #NEWLINE# #INDENT# if ( turn == 1 ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( turn == 2 ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# #UNINDENT# if ( ( ( sch , tbl , cns ) not in inconstrs ) and ( not hasattr ( constr , 'target' ) ) ) : #NEWLINE# #INDENT# stmts . append ( constr . drop ( ) ) #NEWLINE# #UNINDENT# #UNINDENT# for ( sch , tbl , cns ) in inconstrs : #NEWLINE# #INDENT# inconstr = inconstrs [ ( sch , tbl , cns ) ] #NEWLINE# if getattr ( inconstr , 'inherited' , False ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# if hasattr ( inconstr , 'target' ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# if isinstance ( inconstr , ForeignKey ) : #NEWLINE# #INDENT# if ( turn == 1 ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( turn == 2 ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# #UNINDENT# if ( ( sch , tbl , cns ) not in self ) : #NEWLINE# #INDENT# stmts . append ( inconstr . add ( ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# stmts . append ( self [ ( sch , tbl , cns ) ] . diff_map ( inconstr ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# return stmts