#NEWLINE# def upgrade( ) : #NEWLINE# #INDENT# op . add_column ( 'project' , sa . Column ( 'updated' , sa . DateTime ) ) #NEWLINE# conn = op . get_bind ( ) #NEWLINE# res = conn . execute ( 'select "key", name from project' ) #NEWLINE# for ( key , name ) in res . fetchall ( ) : #NEWLINE# #INDENT# q = sa . text ( 'select max(updated) from change where project_key=:key' ) #NEWLINE# res = conn . execute ( q , key = key ) #NEWLINE# for ( updated , ) in res . fetchall ( ) : #NEWLINE# #INDENT# q = sa . text ( 'update project set updated=:updated where "key"=:key' ) #NEWLINE# conn . execute ( q , key = key , updated = updated ) #NEWLINE# #UNINDENT# #UNINDENT# op . create_index ( op . f ( 'ix_project_updated' ) , 'project' , [ 'updated' ] , unique = False )