ruby on rails - What is the best way to update data post migration? -
ruby on rails - What is the best way to update data post migration? -
in rails / activerecord have changed field create required; want run
appversion.where('content_rating null').each {|av| av.update_column('content_rating', 7) }
to ensure content_rating not null.
from read, migrations not place alter records. there "do once" way run code within rails structure?
yes, can create rake task:
http://railsguides.net/2012/03/14/how-to-generate-rake-task/
$ rails g task update_version update_rating_column $ create lib/tasks/update_version.rake namespace :update_version desc "update content_rating" task :update_rating_column => :environment appversion.where('content_rating null').each {|av| av.update_column('content_rating', 7) } end end
you can run task in migration if needed:
execute rake task within migration?
ruby-on-rails
Comments
Post a Comment