1 |
1 |
class AddIssuesNestedSetsColumns < ActiveRecord::Migration
|
2 |
2 |
def self.up
|
3 |
|
add_column :issues, :parent_id, :integer, :default => nil
|
4 |
|
add_column :issues, :root_id, :integer, :default => nil
|
5 |
|
add_column :issues, :lft, :integer, :default => nil
|
6 |
|
add_column :issues, :rgt, :integer, :default => nil
|
7 |
|
|
8 |
|
Issue.update_all("parent_id = NULL, root_id = id, lft = 1, rgt = 2")
|
|
3 |
# when the database already used redmine_subtasks plugin
|
|
4 |
if ['parent_id','lft','rgt'].all? {|c| Issue.column_names.include?(c) }
|
|
5 |
add_column :issues, :root_id, :integer, :default => nil
|
|
6 |
Issue.reset_column_information
|
|
7 |
|
|
8 |
Issue.update_all("parent_id = NULL, root_id = id, lft = 1, rgt = 2", "parent_id IS NULL")
|
|
9 |
Issue.find(:all,:conditions=>"parent_id IS NOT NULL",:order => "parent_id").each do |issue|
|
|
10 |
issue.update_attribute(:parent_issue_id, issue.parent_id)
|
|
11 |
end
|
|
12 |
else
|
|
13 |
add_column :issues, :parent_id, :integer, :default => nil
|
|
14 |
add_column :issues, :root_id, :integer, :default => nil
|
|
15 |
add_column :issues, :lft, :integer, :default => nil
|
|
16 |
add_column :issues, :rgt, :integer, :default => nil
|
|
17 |
|
|
18 |
Issue.update_all("parent_id = NULL, root_id = id, lft = 1, rgt = 2")
|
|
19 |
end
|
9 |
20 |
end
|
10 |
21 |
|
11 |
22 |
def self.down
|