OpenProject is the leading open source project management software.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
openproject/db/migrate/015_order_tasks_using_tree.rb

21 lines
603 B

class OrderTasksUsingTree < ActiveRecord::Migration
def self.up
last_task = {}
ActiveRecord::Base.transaction do
Task.find(:all, :conditions => "not parent_id is NULL", :order => "project_id ASC, parent_id ASC, position ASC").each do |t|
begin
t.move_after last_task[t.parent_id] if last_task[t.parent_id]
rescue
# nested tasks break this migrations. Task order not that
# big a deal, proceed
end
last_task[t.parent_id] = t.id
end
end
end
def self.down
raise ActiveRecord::IrreversibleMigration
end
end