title: How do I execute inserts and updates in an Alembic upgrade script?
body: <p>I need to alter data during an Alembic upgrade.</p>
  
  <p>I currently have a 'players' table in a first revision:</p>
  
  <pre><code>def upgrade():
      op.create_table('player',
          sa.Column('id', sa.Integer(), nullable=False),
          sa.Column('name', sa.Unicode(length=200), nullable=False),
          sa.Column('position', sa.Unicode(length=200), nullable=True),
          sa.Column('team', sa.Unicode(length=100), nullable=True)
          sa.PrimaryKeyConstraint('id')
      )
  </code></pre>
  
  <p>I want to introduce a 'teams' table.  I've created a second revision:</p>
  
  <pre><code>def upgrade():
      op.create_table('teams',
          sa.Column('id', sa.Integer(), nullable=False),
          sa.Column('name', sa.String(length=80), nullable=False)
      )
      op.add_column('players', sa.Column('team_id', sa.Integer(), nullable=False))
  </code></pre>
  
  <p>I would like the second migration to also add the following data:</p>
  
  <ol>
  <li><p>Populate teams table:</p>
  
  <pre><code>INSERT INTO teams (name) SELECT DISTINCT team FROM players;
  </code></pre></li>
  <li><p>Update players.team_id based on players.team name:</p>
  
  <pre><code>UPDATE players AS p JOIN teams AS t SET p.team_id = t.id WHERE p.team = t.name;
  </code></pre></li>
  </ol>
  
  <p>How do I execute inserts and updates inside the upgrade script?</p>