From 1de6a0c9dcef4250babb380d5c18153cedf1f5ec Mon Sep 17 00:00:00 2001 From: Dan Rice Date: Tue, 4 Dec 2012 18:44:58 -0500 Subject: [PATCH 1/2] Reload columns before rendering notes during migration Fixes #1351 --- db/migrate/20120412072508_add_rendered_notes.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/db/migrate/20120412072508_add_rendered_notes.rb b/db/migrate/20120412072508_add_rendered_notes.rb index c458668c..34b2b499 100644 --- a/db/migrate/20120412072508_add_rendered_notes.rb +++ b/db/migrate/20120412072508_add_rendered_notes.rb @@ -2,6 +2,8 @@ class AddRenderedNotes < ActiveRecord::Migration def self.up add_column :todos, 'rendered_notes', :text + Todo.reset_column_information + puts "-- Clearing show_from dates from completed todos" # clear up completed todos that have show_from set. These could have been left over from before the AASM migration Todo.completed.find(:all, :conditions =>[ "NOT(show_from IS NULL)"]).each {|t| t.show_from=nil; t.save!} From c1f1fcb35bbb00a6d09c376251dc47d50ec4fab5 Mon Sep 17 00:00:00 2001 From: Dan Rice Date: Tue, 4 Dec 2012 19:04:01 -0500 Subject: [PATCH 2/2] Use say() instead of puts() in migrations --- db/migrate/20120412072508_add_rendered_notes.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/db/migrate/20120412072508_add_rendered_notes.rb b/db/migrate/20120412072508_add_rendered_notes.rb index 34b2b499..891dc28d 100644 --- a/db/migrate/20120412072508_add_rendered_notes.rb +++ b/db/migrate/20120412072508_add_rendered_notes.rb @@ -4,10 +4,10 @@ class AddRenderedNotes < ActiveRecord::Migration Todo.reset_column_information - puts "-- Clearing show_from dates from completed todos" + say "Clearing show_from dates from completed todos" # clear up completed todos that have show_from set. These could have been left over from before the AASM migration Todo.completed.find(:all, :conditions =>[ "NOT(show_from IS NULL)"]).each {|t| t.show_from=nil; t.save!} - puts "-- Generating new column values from notes. This may take a while." + say "Generating new column values from notes. This may take a while." # Call save! on each todo to force generation of rendered_todos i=0; max = Todo.all.count; start = Time.now Todo.all.each do |todo| @@ -16,10 +16,10 @@ class AddRenderedNotes < ActiveRecord::Migration if i%250==0 elapsed_sec = (Time.now-start) remaining = (elapsed_sec / i)*(max-i) - puts "Progress: #{i} / #{max} (#{(i.to_f/max.to_f*100.0).floor}%) ETA=#{remaining.floor}s" + say "Progress: #{i} / #{max} (#{(i.to_f/max.to_f*100.0).floor}%) ETA=#{remaining.floor}s" end end - puts "Done: #{i} / #{max}" + say "Done: #{i} / #{max}" end def self.down