tracks/db/migrate/20130227205845_add_state_to_context.rb

23 lines
565 B
Ruby
Raw Normal View History

class AddStateToContext < ActiveRecord::Migration
class Context < ActiveRecord::Base
end
def up
add_column :contexts, :state, :string, :limit => 20, :null => false
Context.reset_column_information
Context.all.each do |c|
c.state = c.hide ? 'hidden' : 'active'
c.save!
end
remove_column :contexts, :hide
end
def down
add_column :contexts, :hide, :boolean, :default => false
Context.reset_column_information
2013-03-01 16:48:52 +01:00
Context.all.each { |c| c.hide = ( c.state == 'hidden' ); c.save! }
remove_column :contexts, :state
end
end