<s> from sqlalchemy import * <EOL> meta = MetaData ( ) <EOL> team_users = Table ( '<STR_LIT>' , meta , <EOL> Column ( '<STR_LIT>' , Integer , ForeignKey ( '<STR_LIT>' ) ) , <EOL> Column ( '<STR_LIT>' , Integer , ForeignKey ( '<STR_LIT>' ) ) ) <EOL> def upgrade ( migrate_engine ) : <EOL> meta . bind = migrate_engine <EOL> team = Table ( '<STR_LIT>' , meta , autoload = True ) <EOL> user = Table ( '<STR_LIT:user>' , meta , autoload = True ) <EOL> try : <EOL> team_users . drop ( ) <EOL> except : <EOL> pass <EOL> team_users . create ( ) <EOL> result = user . select ( ) . execute ( ) . fetchall ( ) <EOL> for row in result : <EOL> if row . team_id : <EOL> values = { '<STR_LIT>' : row . team_id , '<STR_LIT>' : row . id } <EOL> team_users . insert ( values = values ) . execute ( ) <EOL> user . c . team_id . drop ( ) <EOL> def downgrade ( migrate_engine ) : <EOL> meta . bind = migrate_engine <EOL> team = Table ( '<STR_LIT>' , meta , autoload = True ) <EOL> user = Table ( '<STR_LIT:user>' , meta , autoload = True ) <EOL> team_id = Column ( '<STR_LIT>' , Integer , ForeignKey ( '<STR_LIT>' ) ) <EOL> team_id . create ( user ) <EOL> result = team_users . select ( ) . execute ( ) . fetchall ( ) <EOL> for row in result : <EOL> values = { '<STR_LIT>' : row . team_id } <EOL> user . update ( values = values ) . where ( user . c . id == row . user_id ) . execute ( ) <EOL> team_users . drop ( ) </s>
