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/20130620082322_create_work_...

91 lines
2.9 KiB

12 years ago
class CreateWorkPackages < ActiveRecord::Migration
def up
12 years ago
create_table "work_packages" do |t|
# Issue
t.column :tracker_id, :integer, :default => 0, :null => false
t.column :project_id, :integer
t.column :subject, :string, :default => "", :null => false
t.column :description, :text
t.column :due_date, :date
t.column :category_id, :integer
t.column :status_id, :integer, :default => 0, :null => false
t.column :assigned_to_id, :integer
t.column :priority_id, :integer, :default => 0, :null => false
t.column :fixed_version_id, :integer
t.column :author_id, :integer, :default => 0, :null => false
t.column :lock_version, :integer, :default => 0, :null => false
t.column :done_ratio, :integer, :default => 0, :null => false
t.column :estimated_hours, :float
t.column :created_at, :timestamp
t.column :updated_at, :timestamp
# Planning Element
t.column :start_date, :date
t.column :end_date, :date
t.column :planning_element_status_comment, :text
t.column :deleted_at, :datetime
t.belongs_to :parent
t.belongs_to :project
t.belongs_to :responsible
t.belongs_to :planning_element_type
t.belongs_to :planning_element_status
# STI
t.column :type, :string
# Nested Set
t.column :parent_id, :integer, :default => nil
t.column :root_id, :integer, :default => nil
t.column :lft, :integer, :default => nil
t.column :rgt, :integer, :default => nil
end
# Issue compatibility
# Because of 't.belongs_to :project' (see above) column 'project_id'
# becomes nullable. That breaks compatibility with issue behavior.
12 years ago
change_table "work_packages" do |t|
t.change :project_id, :integer, :default => 0, :null => false
end
# Planning Elements
12 years ago
add_index :work_packages, :parent_id
add_index :work_packages, :project_id
add_index :work_packages, :responsible_id
add_index :work_packages, :planning_element_type_id
add_index :work_packages, :planning_element_status_id
# Nested Set
12 years ago
add_index :work_packages, [:root_id, :lft, :rgt]
change_table(:projects) do |t|
12 years ago
t.belongs_to :work_packages_responsible
12 years ago
t.index :work_packages_responsible_id
end
# Time Entry
12 years ago
rename_column :time_entries, :issue_id, :work_package_id
# Rename legacy tables 'issues' and 'planning_elements'
rename_table :issues, :legacy_issues
rename_table :planning_elements, :legacy_planning_elements
end
def down
12 years ago
# Nested Set
change_table(:projects) do |t|
12 years ago
t.remove_belongs_to :work_packages_responsible
end
# Time Entry
12 years ago
rename_column :time_entries, :work_package_id, :issue_id
12 years ago
drop_table(:work_packages)
# Revert renaming of legacy tables 'issues' and 'planning_elements'
rename_table :legacy_issues, :issues
rename_table :legacy_planning_elements, :planning_elements
end
end