From b87a9324823f36defd9bfa1b6ba9d56c206ca457 Mon Sep 17 00:00:00 2001 From: Jens Ulferts Date: Mon, 16 Sep 2013 14:09:53 +0200 Subject: [PATCH 1/2] adds data migration from legacy_issues to work_packages --- ...16094339_legacy_issues_to_work_packages.rb | 181 ++++++++++++++++++ 1 file changed, 181 insertions(+) create mode 100644 db/migrate/20130916094339_legacy_issues_to_work_packages.rb diff --git a/db/migrate/20130916094339_legacy_issues_to_work_packages.rb b/db/migrate/20130916094339_legacy_issues_to_work_packages.rb new file mode 100644 index 0000000000..336cd8f5a5 --- /dev/null +++ b/db/migrate/20130916094339_legacy_issues_to_work_packages.rb @@ -0,0 +1,181 @@ +#-- copyright +# OpenProject is a project management system. +# +# Copyright (C) 2012-2013 the OpenProject Team +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License version 3. +# +# See doc/COPYRIGHT.rdoc for more details. +#++ + +class LegacyIssuesToWorkPackages < ActiveRecord::Migration + + class ExistingWorkPackagesError < ::StandardError + end + + class ExistingLegacyIssuesError < ::StandardError + end + + def up + raise_on_existing_work_package_entries + + copy_legacy_issues_to_work_packages + end + + def down + raise_on_existing_legacy_issue_entries + + copy_work_packages_to_legacy_issues + end + + private + + def raise_on_existing_work_package_entries + existing_work_packages = select_all <<-SQL + SELECT * + FROM work_packages + SQL + + if existing_work_packages.size > 0 + raise ExistingWorkPackagesError, <<-MESSAGE.split("\n").map(&:strip!).join(" ") + "\n" + There are already entries in the work_packages table. + This migration assumes that there are none. + MESSAGE + end + end + + def copy_legacy_issues_to_work_packages + execute <<-SQL + INSERT INTO work_packages + ( + id, + type_id, + project_id, + subject, + description, + due_date, + category_id, + status_id, + assigned_to_id, + priority_id, + fixed_version_id, + author_id, + lock_version, + done_ratio, + estimated_hours, + created_at, + updated_at, + start_date, + planning_element_status_comment, + deleted_at, + parent_id, + responsible_id, + planning_element_status_id, + sti_type, + root_id, + lft, + rgt + ) + SELECT + id, + tracker_id, + project_id, + subject, + description, + due_date, + category_id, + status_id, + assigned_to_id, + priority_id, + fixed_version_id, + author_id, + lock_version, + done_ratio, + estimated_hours, + created_on, + updated_on, + start_date, + '', + NULL, + parent_id, + NULL, + NULL, + NULL, + root_id, + lft, + rgt + FROM legacy_issues + SQL + + end + + def raise_on_existing_legacy_issue_entries + existing_legacy_issues = select_all <<-SQL + SELECT * + FROM legacy_issues + SQL + + if existing_legacy_issues.size > 0 + raise ExistingLegacyIssuesError, <<-MESSAGE.split("\n").map(&:strip!).join(" ") + "\n" + There are already entries in the legacy_issues table. + This migration assumes that there are none. + MESSAGE + end + end + + def copy_work_packages_to_legacy_issues + execute <<-SQL + INSERT INTO legacy_issues + ( + id, + tracker_id, + project_id, + subject, + description, + due_date, + category_id, + status_id, + assigned_to_id, + priority_id, + fixed_version_id, + author_id, + lock_version, + done_ratio, + estimated_hours, + created_on, + updated_on, + start_date, + parent_id, + root_id, + lft, + rgt + ) + SELECT + id, + type_id, + project_id, + subject, + description, + due_date, + category_id, + status_id, + assigned_to_id, + priority_id, + fixed_version_id, + author_id, + lock_version, + done_ratio, + estimated_hours, + created_at, + updated_at, + start_date, + parent_id, + root_id, + lft, + rgt + FROM work_packages + SQL + + end +end From 36237293c088eca3fe3f3fb95cfd1c60f9804413 Mon Sep 17 00:00:00 2001 From: Jens Ulferts Date: Mon, 16 Sep 2013 14:11:02 +0200 Subject: [PATCH 2/2] adds changelog --- doc/CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/CHANGELOG.md b/doc/CHANGELOG.md index 6ffa70e3d4..efe9eb9998 100644 --- a/doc/CHANGELOG.md +++ b/doc/CHANGELOG.md @@ -12,7 +12,8 @@ See doc/COPYRIGHT.rdoc for more details. # Changelog -* `#1913` [Timelines] Enable drag&drop for select2 items in order to rearrange the order of the columns +* `#1913` [Timelines] Enable drag&drop for select2 items in order to rearrange the order of the columns +* `#1978` Migrate legacy issues * `#2019` Migrate auto completes controller tests ## 3.0.0pre16