summaryrefslogtreecommitdiffstats
path: root/db
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2013-02-16 09:38:01 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2013-02-16 09:38:01 +0000
commita45c0dc55057e8c10c2d17f8dc26be5d9b771f8d (patch)
tree93fa80fd96d6c404515d23d3ce1662c2ef7ee517 /db
parent723e21243e8df3cbb8937c32410797fa84c9cb79 (diff)
downloadredmine-a45c0dc55057e8c10c2d17f8dc26be5d9b771f8d.tar.gz
redmine-a45c0dc55057e8c10c2d17f8dc26be5d9b771f8d.zip
Adds closed_on column that stores the time of the last closing (#824).
The value is preserved when reopening the issue. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@11402 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'db')
-rw-r--r--db/migrate/20130215111127_add_issues_closed_on.rb9
-rw-r--r--db/migrate/20130215111141_populate_issues_closed_on.rb25
2 files changed, 34 insertions, 0 deletions
diff --git a/db/migrate/20130215111127_add_issues_closed_on.rb b/db/migrate/20130215111127_add_issues_closed_on.rb
new file mode 100644
index 000000000..2670deba5
--- /dev/null
+++ b/db/migrate/20130215111127_add_issues_closed_on.rb
@@ -0,0 +1,9 @@
+class AddIssuesClosedOn < ActiveRecord::Migration
+ def up
+ add_column :issues, :closed_on, :datetime, :default => nil
+ end
+
+ def down
+ remove_column :issues, :closed_on
+ end
+end
diff --git a/db/migrate/20130215111141_populate_issues_closed_on.rb b/db/migrate/20130215111141_populate_issues_closed_on.rb
new file mode 100644
index 000000000..b2a828be4
--- /dev/null
+++ b/db/migrate/20130215111141_populate_issues_closed_on.rb
@@ -0,0 +1,25 @@
+class PopulateIssuesClosedOn < ActiveRecord::Migration
+ def up
+ closed_status_ids = IssueStatus.where(:is_closed => true).pluck(:id)
+ if closed_status_ids.any?
+ # First set closed_on for issues that have been closed once
+ closed_status_values = closed_status_ids.map {|status_id| "'#{status_id}'"}.join(',')
+ subselect = "SELECT MAX(#{Journal.table_name}.created_on)" +
+ " FROM #{Journal.table_name}, #{JournalDetail.table_name}" +
+ " WHERE #{Journal.table_name}.id = #{JournalDetail.table_name}.journal_id" +
+ " AND #{Journal.table_name}.journalized_type = 'Issue' AND #{Journal.table_name}.journalized_id = #{Issue.table_name}.id" +
+ " AND #{JournalDetail.table_name}.property = 'attr' AND #{JournalDetail.table_name}.prop_key = 'status_id'" +
+ " AND #{JournalDetail.table_name}.old_value NOT IN (#{closed_status_values})" +
+ " AND #{JournalDetail.table_name}.value IN (#{closed_status_values})"
+ Issue.update_all "closed_on = (#{subselect})"
+
+ # Then set closed_on for closed issues that weren't up updated by the above UPDATE
+ # No journal was found so we assume that they were closed on creation
+ Issue.update_all "closed_on = created_on", {:status_id => closed_status_ids, :closed_on => nil}
+ end
+ end
+
+ def down
+ Issue.update_all :closed_on => nil
+ end
+end