From 031d1ad31a086bcd82598da42ffffc193101975f Mon Sep 17 00:00:00 2001 From: Hagen Schink Date: Mon, 11 Nov 2013 08:49:17 +0100 Subject: [PATCH 1/5] Reorder customizable migration --- ...journals.rb => 20131018134530_repair_customizable_journals.rb} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename db/migrate/{20131108122428_repair_customizable_journals.rb => 20131018134530_repair_customizable_journals.rb} (100%) diff --git a/db/migrate/20131108122428_repair_customizable_journals.rb b/db/migrate/20131018134530_repair_customizable_journals.rb similarity index 100% rename from db/migrate/20131108122428_repair_customizable_journals.rb rename to db/migrate/20131018134530_repair_customizable_journals.rb From d0e60106825f55d205e502d3f68939237579dc6d Mon Sep 17 00:00:00 2001 From: Hagen Schink Date: Mon, 11 Nov 2013 08:51:44 +0100 Subject: [PATCH 2/5] Improves customizable utils implementation --- db/migrate/migration_utils/customizable_utils.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/db/migrate/migration_utils/customizable_utils.rb b/db/migrate/migration_utils/customizable_utils.rb index 8c9cd75b13..2feb92b757 100644 --- a/db/migrate/migration_utils/customizable_utils.rb +++ b/db/migrate/migration_utils/customizable_utils.rb @@ -141,7 +141,7 @@ module Migration end def missing_initial_customizable_journals(legacy_journal_type, journal_id, journaled_id, version, changed_data) - removed_customvalues = parse_customvalues_changes(changed_data) + removed_customvalues = parse_custom_value_changes(changed_data) missing_entries = missing_initial_custom_value_entries(legacy_journal_type, journaled_id, @@ -162,9 +162,9 @@ module Migration # - "" # # - "" # ############################################# - CUSTOM_VALUE_CHANGE_REGEX = /custom_values(?\d+): \n-\s"(?.+)"\n-\s"(?.*)"$/ + CUSTOM_VALUE_CHANGE_REGEX = /custom_values(?\d+): \n-\s"(?.*)"\n-\s"(?.*)"$/ - def parse_customvalues_changes(changed_data) + def parse_custom_value_changes(changed_data) matches = changed_data.scan(CUSTOM_VALUE_CHANGE_REGEX) matches.each_with_object([]) { |m, l| l << { id: m[0], value: m[1] } } @@ -179,7 +179,7 @@ module Migration AND type = '#{legacy_journal_type}' AND version < #{version} AND changed_data LIKE '%custom_values#{c[:id]}:%' - AND changed_data LIKE '%- "#{c[:filename]}%"' + AND changed_data LIKE '%- "#{c[:value]}%"' ORDER BY version SQL From cd51e02f9386212babcd0205d14d80f365062352 Mon Sep 17 00:00:00 2001 From: Hagen Schink Date: Mon, 11 Nov 2013 08:52:05 +0100 Subject: [PATCH 3/5] Fixes customizable migration --- .../migration_utils/customizable_utils.rb | 60 +++++++++---------- 1 file changed, 28 insertions(+), 32 deletions(-) diff --git a/db/migrate/migration_utils/customizable_utils.rb b/db/migrate/migration_utils/customizable_utils.rb index 2feb92b757..4d6a6fec73 100644 --- a/db/migrate/migration_utils/customizable_utils.rb +++ b/db/migrate/migration_utils/customizable_utils.rb @@ -68,43 +68,39 @@ module Migration def missing_custom_values result = select_all <<-SQL - SELECT * FROM - ( - SELECT customized_id, - customized_type, - custom_value_journal.custom_field_id, - custom_value_journal.value, - last_version, - MAX(cj.id) AS cj_id FROM - -- get all existing custom values and all journal entries for the customized thing - ( - SELECT c.customized_id, - c.customized_type, - c.custom_field_id, - c.value AS value, - j.id AS journal_id, - MAX(j.version) AS last_version - FROM custom_values AS c JOIN journals AS j - ON c.customized_id = j.journable_id - WHERE c.value <> '' - GROUP BY c.customized_id, c.customized_type, c.custom_field_id, c.value, j.id, c.custom_field_id - ) AS custom_value_journal - -- join it with the customizable_journals and select the custom values that have no entry in that table - LEFT JOIN customizable_journals AS cj - ON custom_value_journal.journal_id = cj.journal_id - GROUP BY customized_id, - customized_type, - custom_value_journal.custom_field_id, - custom_value_journal.value, - last_version - ) AS custom_value_customizable_journal - WHERE cj_id IS NULL; + SELECT tmp.customized_id, + tmp.customized_type, + tmp.custom_field_id, + tmp.current_value, + tmp.last_version, + tmp.journal_value + FROM ( + SELECT cv.customized_id, + cv.customized_type, + cv.custom_field_id, + cv.value AS current_value, + MAX(j.version) AS last_version, + cj.value AS journal_value + FROM custom_values AS cv + JOIN journals AS j ON (cv.customized_id = j.journable_id AND cv.customized_type = j.journable_type AND cv.value <> '') + LEFT JOIN customizable_journals AS cj ON (j.id = cj.journal_id AND cv.custom_field_id = cj.custom_field_id) + GROUP BY cv.customized_id, + cv.customized_type, + cv.custom_field_id, + cv.value, + cj.value + ) AS tmp + WHERE tmp.last_version = (SELECT MAX(version) AS last_version + FROM journals AS j + WHERE j.journable_id = tmp.customized_id AND j.journable_type = tmp.customized_type + GROUP BY j.journable_id, j.journable_type) + AND tmp.journal_value IS NULL SQL result.collect { |row| MissingCustomValue.new(row['customized_id'], row['customized_type'], row['custom_field_id'], - row['value'], + row['current_value'], row['last_version']) } end From 8f786966306a5c4a1b3036bf1e848bca2e0ea3fe Mon Sep 17 00:00:00 2001 From: Hagen Schink Date: Mon, 11 Nov 2013 09:08:02 +0100 Subject: [PATCH 4/5] Adds changelog entry --- doc/CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/CHANGELOG.md b/doc/CHANGELOG.md index b277c446f8..546527ed16 100644 --- a/doc/CHANGELOG.md +++ b/doc/CHANGELOG.md @@ -29,6 +29,8 @@ See doc/COPYRIGHT.rdoc for more details. # Changelog +* `#2721` Fix: Fix: Fix: Missing journal entries for customizable_journals + ## 3.0.0pre28 * `#1910` New menu structure for pages of timelines module From 0523c9370fa6accfd35cf5ba91d3cf02389dd346 Mon Sep 17 00:00:00 2001 From: Sebastian Schuster Date: Mon, 11 Nov 2013 10:10:30 +0100 Subject: [PATCH 5/5] Fixed module namespacing --- ...7064039_repair_work_packages_initial_attachable_journal.rb | 1 + ...131018134525_repair_messages_initial_attachable_journal.rb | 1 + db/migrate/20131018134530_repair_customizable_journals.rb | 1 + db/migrate/20131018134545_add_missing_attachable_journals.rb | 1 + .../20131018134590_add_missing_customizable_journals.rb | 1 + db/migrate/migration_utils/attachable_utils.rb | 4 ++-- db/migrate/migration_utils/customizable_utils.rb | 4 ++-- 7 files changed, 9 insertions(+), 4 deletions(-) diff --git a/db/migrate/20131017064039_repair_work_packages_initial_attachable_journal.rb b/db/migrate/20131017064039_repair_work_packages_initial_attachable_journal.rb index cca8f73d57..ad0883ac01 100644 --- a/db/migrate/20131017064039_repair_work_packages_initial_attachable_journal.rb +++ b/db/migrate/20131017064039_repair_work_packages_initial_attachable_journal.rb @@ -13,6 +13,7 @@ require_relative 'migration_utils/attachable_utils' class RepairWorkPackagesInitialAttachableJournal < ActiveRecord::Migration include Migration::Utils + include Migration::Utils::AttachableUtils LEGACY_JOURNAL_TYPE = 'IssueJournal' JOURNAL_TYPE = 'WorkPackage' diff --git a/db/migrate/20131018134525_repair_messages_initial_attachable_journal.rb b/db/migrate/20131018134525_repair_messages_initial_attachable_journal.rb index eea0a5874a..daba523496 100644 --- a/db/migrate/20131018134525_repair_messages_initial_attachable_journal.rb +++ b/db/migrate/20131018134525_repair_messages_initial_attachable_journal.rb @@ -13,6 +13,7 @@ require_relative 'migration_utils/attachable_utils' class RepairMessagesInitialAttachableJournal < ActiveRecord::Migration include Migration::Utils + include Migration::Utils::AttachableUtils JOURNAL_TYPE = 'Message' diff --git a/db/migrate/20131018134530_repair_customizable_journals.rb b/db/migrate/20131018134530_repair_customizable_journals.rb index 0ef2eb5a9f..9f56c023fa 100644 --- a/db/migrate/20131018134530_repair_customizable_journals.rb +++ b/db/migrate/20131018134530_repair_customizable_journals.rb @@ -13,6 +13,7 @@ require_relative 'migration_utils/customizable_utils' class RepairCustomizableJournals < ActiveRecord::Migration include Migration::Utils + include Migration::Utils::CustomizableUtils LEGACY_JOURNAL_TYPE = 'IssueJournal' JOURNAL_TYPE = 'WorkPackage' diff --git a/db/migrate/20131018134545_add_missing_attachable_journals.rb b/db/migrate/20131018134545_add_missing_attachable_journals.rb index e3472f2cf5..11376242df 100644 --- a/db/migrate/20131018134545_add_missing_attachable_journals.rb +++ b/db/migrate/20131018134545_add_missing_attachable_journals.rb @@ -13,6 +13,7 @@ require_relative 'migration_utils/attachable_utils' class AddMissingAttachableJournals < ActiveRecord::Migration include Migration::Utils + include Migration::Utils::AttachableUtils def up say_with_time_silently "Add missing attachable journals" do diff --git a/db/migrate/20131018134590_add_missing_customizable_journals.rb b/db/migrate/20131018134590_add_missing_customizable_journals.rb index de11ebbd98..86ec00146e 100644 --- a/db/migrate/20131018134590_add_missing_customizable_journals.rb +++ b/db/migrate/20131018134590_add_missing_customizable_journals.rb @@ -13,6 +13,7 @@ require_relative 'migration_utils/customizable_utils' class AddMissingCustomizableJournals < ActiveRecord::Migration include Migration::Utils + include Migration::Utils::CustomizableUtils def up say_with_time_silently "Add missing customizable journals" do diff --git a/db/migrate/migration_utils/attachable_utils.rb b/db/migrate/migration_utils/attachable_utils.rb index 67bf7b9c62..7766d0c9f0 100644 --- a/db/migrate/migration_utils/attachable_utils.rb +++ b/db/migrate/migration_utils/attachable_utils.rb @@ -10,8 +10,8 @@ require_relative 'utils' -module Migration - module Utils +module Migration::Utils + module AttachableUtils MissingAttachment = Struct.new(:journaled_id, :journaled_type, :attachment_id, diff --git a/db/migrate/migration_utils/customizable_utils.rb b/db/migrate/migration_utils/customizable_utils.rb index 4d6a6fec73..1b5993c5f9 100644 --- a/db/migrate/migration_utils/customizable_utils.rb +++ b/db/migrate/migration_utils/customizable_utils.rb @@ -10,8 +10,8 @@ require_relative 'utils' -module Migration - module Utils +module Migration::Utils + module CustomizableUtils MissingCustomValue = Struct.new(:journaled_id, :journaled_type, :custom_field_id,