From 6bc68bcf6cbc148733e61f9fa53b6c849741b490 Mon Sep 17 00:00:00 2001 From: mike Date: Mon, 19 Jan 2009 01:22:35 +0800 Subject: [PATCH] Added migration to fix incorrectly hidden todos Signed-off-by: Reinier Balt --- db/migrate/046_fix_incorrectly_hidden_todos.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 db/migrate/046_fix_incorrectly_hidden_todos.rb diff --git a/db/migrate/046_fix_incorrectly_hidden_todos.rb b/db/migrate/046_fix_incorrectly_hidden_todos.rb new file mode 100644 index 00000000..7ce294a9 --- /dev/null +++ b/db/migrate/046_fix_incorrectly_hidden_todos.rb @@ -0,0 +1,18 @@ +class FixIncorrectlyHiddenTodos < ActiveRecord::Migration + def self.up + hidden_todos_without_project = + Todo.find(:all, :conditions => "state='project_hidden' AND project_id IS NULL") + + active_projects = Project.find(:all, :conditions => "state='active'") + hidden_todos_in_active_projects = + Todo.find(:all, :conditions => ["state='project_hidden' AND project_id IN (?)", active_projects]) + + todos_to_fix = hidden_todos_without_project + hidden_todos_in_active_projects + todos_to_fix.each do |todo| + todo.update_attribute :state, 'active' + end + end + + def self.down + end +end