title: Altering an Enum field using Alembic
body: <p>How can I add an element to an Enum field in an alembic migration when using a version of PostgreSQL older than 9.1 (which adds the ALTER TYPE for enums)? <a href="https://stackoverflow.com/questions/1771543/postgresql-updating-an-enum-type">This</a> SO question explains the direct process, but I'm not quite sure how best to translate that using alembic.</p>
  
  <p>This is what I have:</p>
  
  <pre><code>new_type = sa.Enum('nonexistent_executable', 'output_limit_exceeded',
                     'signal', 'success', 'timed_out', name='status')
  old_type = sa.Enum('nonexistent_executable', 'signal', 'success', 'timed_out',
                     name='status')
  tcr = sa.sql.table('testcaseresult',
                     sa.Column('status', new_type, nullable=False))
  
  
  def upgrade():
      op.alter_column('testcaseresult', u'status', type_=new_type,
                      existing_type=old_type)
  
  
  def downgrade():
      op.execute(tcr.update().where(tcr.c.status==u'output_limit_exceeded')
                 .values(status='timed_out'))
      op.alter_column('testcaseresult', u'status', type_=old_type,
                      existing_type=new_type)
  </code></pre>
  
  <p>The above unfortunately only produces <code>ALTER TABLE testcaseresult ALTER COLUMN status TYPE status</code> upon upgrade, which essentially does nothing.</p>