title: Update column content during Alembic migration
body: <p>Suppose my db model contains an object <code>User</code>:</p>
  
  <pre><code>Base = declarative_base() 
  
  class User(Base):                                                               
      __tablename__ = 'users'                                                     
  
      id = Column(String(32), primary_key=True, default=...) 
      name = Column(Unicode(100))                                             
  </code></pre>
  
  <p>and my database contains a <code>users</code> table with <em>n</em> rows. At some point I decide to split the <code>name</code> into <code>firstname</code> and <code>lastname</code>, and during <a href="http://alembic.zzzcomputing.com/en/latest/tutorial.html#running-our-first-migration" rel="noreferrer"><code>alembic upgrade head</code></a> I would like my data to be migrated as well.</p>
  
  <p>The auto-generated <a href="http://alembic.zzzcomputing.com/en/latest/ops.html" rel="noreferrer">Alembic</a> migration is as follows:</p>
  
  <pre><code>def upgrade():
      op.add_column('users', sa.Column('lastname', sa.Unicode(length=50), nullable=True))
      op.add_column('users', sa.Column('firstname', sa.Unicode(length=50), nullable=True))
  
      # Assuming that the two new columns have been committed and exist at
      # this point, I would like to iterate over all rows of the name column,
      # split the string, write it into the new firstname and lastname rows,
      # and once that has completed, continue to delete the name column.
  
      op.drop_column('users', 'name')                                             
  
  def downgrade():
      op.add_column('users', sa.Column('name', sa.Unicode(length=100), nullable=True))
  
      # Do the reverse of the above.
  
      op.drop_column('users', 'firstname')                                        
      op.drop_column('users', 'lastname')
  </code></pre>
  
  <p>There seem to be multiple and more or less hacky solutions to this problem. <a href="https://stackoverflow.com/questions/11970555/modify-data-as-part-of-an-alembic-upgrade#11995593">This one</a> and <a href="https://stackoverflow.com/questions/18726527/fetch-table-values-using-alembic-and-update-to-another-table#18739259">this one</a> both propose to use <a href="http://alembic.zzzcomputing.com/en/latest/ops.html?highlight=execute#alembic.operations.Operations.execute" rel="noreferrer"><code>execute()</code></a> and <a href="http://alembic.zzzcomputing.com/en/latest/ops.html#alembic.operations.Operations.bulk_insert" rel="noreferrer"><code>bulk_insert()</code></a> to execute raw SQL statements during a migration. <a href="https://stackoverflow.com/questions/18726527/fetch-table-values-using-alembic-and-update-to-another-table#21206292">This (incomplete) solution</a> imports the current db model but that approach is fragile when that model changes.</p>
  
  <p>How do I migrate and modify the <em>existing content</em> of column data during an Alembic migration? What is the recommended way, and where is it documented?</p>