Merge pull request #632 from opf/fix/custom_value_migration

[FIX] Custom value migration
pull/634/head
sschu 11 years ago
commit 31d311fae6
  1. 1
      db/migrate/20131017064039_repair_work_packages_initial_attachable_journal.rb
  2. 1
      db/migrate/20131018134525_repair_messages_initial_attachable_journal.rb
  3. 1
      db/migrate/20131018134530_repair_customizable_journals.rb
  4. 1
      db/migrate/20131018134545_add_missing_attachable_journals.rb
  5. 1
      db/migrate/20131018134590_add_missing_customizable_journals.rb
  6. 4
      db/migrate/migration_utils/attachable_utils.rb
  7. 72
      db/migrate/migration_utils/customizable_utils.rb
  8. 2
      doc/CHANGELOG.md

@ -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'

@ -13,6 +13,7 @@ require_relative 'migration_utils/attachable_utils'
class RepairMessagesInitialAttachableJournal < ActiveRecord::Migration
include Migration::Utils
include Migration::Utils::AttachableUtils
JOURNAL_TYPE = 'Message'

@ -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'

@ -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

@ -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

@ -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,

@ -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,
@ -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
@ -141,7 +137,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 +158,9 @@ module Migration
# - "<old_value>" #
# - "<new_value>" #
#############################################
CUSTOM_VALUE_CHANGE_REGEX = /custom_values(?<id>\d+): \n-\s"(?<old_value>.+)"\n-\s"(?<new_value>.*)"$/
CUSTOM_VALUE_CHANGE_REGEX = /custom_values(?<id>\d+): \n-\s"(?<old_value>.*)"\n-\s"(?<new_value>.*)"$/
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 +175,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

@ -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

Loading…
Cancel
Save