2019-05-13 18:42:57 +02:00
|
|
|
class ChangeDatesToDatetimes < ActiveRecord::Migration[5.2]
|
2008-09-13 13:33:48 -07:00
|
|
|
def self.up
|
|
|
|
|
change_column :todos, :show_from, :datetime
|
|
|
|
|
change_column :todos, :due, :datetime
|
|
|
|
|
change_column :recurring_todos, :start_from, :datetime
|
|
|
|
|
change_column :recurring_todos, :end_date, :datetime
|
2008-09-20 17:34:22 -07:00
|
|
|
|
2013-09-13 16:44:59 +02:00
|
|
|
User.includes(:todos, :recurring_todos).each do |user|
|
2008-10-09 10:14:26 -04:00
|
|
|
if !user.prefs ## ugly hack for strange edge-case of not having preferences object
|
|
|
|
|
user.instance_eval do
|
|
|
|
|
def at_midnight(date)
|
|
|
|
|
return Time.zone.local(date.year, date.month, date.day, 0, 0, 0)
|
|
|
|
|
end
|
|
|
|
|
def time
|
|
|
|
|
Time.zone.now
|
|
|
|
|
end
|
2008-10-04 13:41:37 -04:00
|
|
|
end
|
2008-10-09 10:14:26 -04:00
|
|
|
end
|
|
|
|
|
user.todos.each do |todo|
|
|
|
|
|
todo[:show_from] = user.at_midnight(todo.show_from) unless todo.show_from.nil?
|
|
|
|
|
todo[:due] = user.at_midnight(todo.due) unless todo.due.nil?
|
|
|
|
|
todo.save_with_validation(false)
|
|
|
|
|
end
|
2008-10-04 13:41:37 -04:00
|
|
|
|
2008-10-09 10:14:26 -04:00
|
|
|
user.recurring_todos.each do |todo|
|
|
|
|
|
todo[:start_from] = user.at_midnight(todo.start_from) unless todo.start_from.nil?
|
|
|
|
|
todo[:end_date] = user.at_midnight(todo.end_date) unless todo.end_date.nil?
|
|
|
|
|
todo.save_with_validation(false)
|
2008-10-08 23:47:59 -04:00
|
|
|
end
|
2008-09-13 13:33:48 -07:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def self.down
|
|
|
|
|
change_column :todos, :show_from, :date
|
|
|
|
|
change_column :todos, :due, :date
|
|
|
|
|
change_column :recurring_todos, :start_from, :date
|
|
|
|
|
change_column :recurring_todos, :end_date, :date
|
|
|
|
|
end
|
|
|
|
|
end
|