title: Rails 4 migration to change columns data type from string to integer and back preserving data (postgres)
body: <p>I need to convert <code>string</code> fields into <code>integer</code> and use <code>enum</code> instead.
  What is the best way to do this without losing data?</p>
  
  <p>This is current migration:</p>
  
  <pre><code>class CreateSystems &lt; ActiveRecord::Migration
    def change
      create_table :systems do |t|
        t.string :operation
        t.string :status
  
        t.timestamps null: false
      end
    end
  end
  </code></pre>
  
  <p>Then I change type of the fields like so:</p>
  
  <pre><code>class ChangeColumnsForSystems &lt; ActiveRecord::Migration
    def change
      change_column :systems, :operation, :integer
      change_column :systems, :status, :integer
    end
  end
  </code></pre>
  
  <p>And update model file. </p>
  
  <p>/app/models/system.rb</p>
  
  <pre><code>...
  enum operation { start: 0, stop: 1 }
  enum status { init: 0, working: 1, complete: 2 }
  ...
  </code></pre>
  
  <p>How can I update old data?</p>