2019-05-13 18:42:57 +02:00
|
|
|
class AddRenderedNotes < ActiveRecord::Migration[5.2]
|
2012-04-12 11:34:08 +02:00
|
|
|
def self.up
|
|
|
|
|
add_column :todos, 'rendered_notes', :text
|
|
|
|
|
|
2012-12-04 18:44:58 -05:00
|
|
|
Todo.reset_column_information
|
|
|
|
|
|
2012-12-04 19:04:01 -05:00
|
|
|
say "Clearing show_from dates from completed todos"
|
2012-04-12 11:34:08 +02:00
|
|
|
# clear up completed todos that have show_from set. These could have been left over from before the AASM migration
|
2013-09-13 16:44:59 +02:00
|
|
|
Todo.completed.where( "NOT(show_from IS NULL)" ).each {|t| t.show_from=nil; t.save!}
|
|
|
|
|
|
2012-12-04 19:04:01 -05:00
|
|
|
say "Generating new column values from notes. This may take a while."
|
2012-04-12 11:34:08 +02:00
|
|
|
# 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|
|
2012-07-08 21:10:54 +02:00
|
|
|
todo.save(:validate => false)
|
2012-04-12 11:34:08 +02:00
|
|
|
i = i + 1
|
|
|
|
|
if i%250==0
|
|
|
|
|
elapsed_sec = (Time.now-start)
|
|
|
|
|
remaining = (elapsed_sec / i)*(max-i)
|
2012-12-04 19:04:01 -05:00
|
|
|
say "Progress: #{i} / #{max} (#{(i.to_f/max.to_f*100.0).floor}%) ETA=#{remaining.floor}s"
|
2012-04-12 11:34:08 +02:00
|
|
|
end
|
|
|
|
|
end
|
2012-12-04 19:04:01 -05:00
|
|
|
say "Done: #{i} / #{max}"
|
2012-04-12 11:34:08 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def self.down
|
|
|
|
|
remove_column :todos, 'rendered_notes'
|
|
|
|
|
end
|
|
|
|
|
end
|