<s> from migrate import UniqueConstraint <EOL> from sqlalchemy import Column <EOL> from sqlalchemy . engine import reflection <EOL> from sqlalchemy import Index <EOL> from sqlalchemy import MetaData <EOL> from sqlalchemy import String <EOL> from sqlalchemy import Table <EOL> from sqlalchemy import Text <EOL> def upgrade ( migrate_engine ) : <EOL> meta = MetaData ( ) <EOL> meta . bind = migrate_engine <EOL> build_requests = Table ( '<STR_LIT>' , meta , autoload = True ) <EOL> columns_to_add = [ <EOL> ( '<STR_LIT>' , <EOL> Column ( '<STR_LIT>' , String ( length = <NUM_LIT> ) ) ) , <EOL> ( '<STR_LIT>' , <EOL> Column ( '<STR_LIT>' , Text ( ) ) ) , <EOL> ] <EOL> for ( col_name , column ) in columns_to_add : <EOL> if not hasattr ( build_requests . c , col_name ) : <EOL> build_requests . create_column ( column ) <EOL> for index in build_requests . indexes : <EOL> if [ c . name for c in index . columns ] == [ '<STR_LIT>' ] : <EOL> break <EOL> else : <EOL> index = Index ( '<STR_LIT>' , <EOL> build_requests . c . instance_uuid ) <EOL> index . create ( ) <EOL> inspector = reflection . Inspector . from_engine ( migrate_engine ) <EOL> constrs = inspector . get_unique_constraints ( '<STR_LIT>' ) <EOL> constr_names = [ constr [ '<STR_LIT:name>' ] for constr in constrs ] <EOL> if '<STR_LIT>' not in constr_names : <EOL> UniqueConstraint ( '<STR_LIT>' , table = build_requests , <EOL> name = '<STR_LIT>' ) . create ( ) </s>
