Does this version work for you?
class AddDeletedAtToOptions < ActiveRecord::Migration
class Option < ActiveRecord::Base; end
# Add `deleted_at` column, set to Time.now if `is_deleted` is true,
# then remove `is_deleted`:
#
def self.up
add_column(:options, :deleted_at, :timestamp, :default => nil)
say "IN TABLE option: Setting `deleted_at` to now if `is_deleted`
set." do
Option.reset_column_information
Option.update_all(['deleted_at = ?', Time.now], ['is_deleted
= ?', true])
end
remove_column(:options, :is_deleted)
end
# Add `is_deleted` column, set to true if `deleted_at` isn't NULL,
# then remove `deleted_at`
#
def self.down
add_column(:options, :is_deleted, :boolean, :default =>
false, :null => false)
say "IN TABLE option: Setting `is_deleted` to true if
`deleted_at` set." do
Option.reset_column_information
Option.update_all(['is_deleted = ?', true], 'deleted_at IS NOT
NULL')
Sorry, I haven't tried it, but it is similar to some of the migrations
that I've had to created.
-Rob
Rob Biedenharn http://agileconsultingllc.com
R...@AgileConsultingLLC.com
In case anyone finds this which Googling the same problem (like I did)
this blog post has the answer:
http://espaceblogs.blogspot.com/2007/05/update-newly-added-column-in-migration.html
Essentially you need to call reset_column_information on your model. For
example
add_column 'my_models', 'new_column'
MyModel.reset_column_information
my_model = MyModel.first
my_model.new_column = 'this will save'
my_model.save
--
Posted via http://www.ruby-forum.com/.