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