From c05ad6840f539c15375ab7658b55075153367372 Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Mon, 3 Mar 2014 14:31:37 +0100 Subject: [PATCH] SONAR-4923 Fix migration when rule_notes or active_rule_notes are linked to not existing rules or active_rules --- .../migrate/481_copy_rule_notes_to_rules.rb | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/481_copy_rule_notes_to_rules.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/481_copy_rule_notes_to_rules.rb index 331fabc2f0e..517f7aac50a 100644 --- a/sonar-server/src/main/webapp/WEB-INF/db/migrate/481_copy_rule_notes_to_rules.rb +++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/481_copy_rule_notes_to_rules.rb @@ -20,6 +20,7 @@ # # Sonar 4.2 +# SONAR-4923 # Copy rule_notes (resp. active_rule_notes) contents to rules (resp. active_rules) # class CopyRuleNotesToRules < ActiveRecord::Migration @@ -49,11 +50,13 @@ class CopyRuleNotesToRules < ActiveRecord::Migration RuleNote.all.each do |note| rule = rules[note.rule_id] - rule.note_created_at = note.created_at - rule.note_updated_at = note.updated_at - rule.note_user_login = note.user_login - rule.note_data = note.data - rule.save + if rule + rule.note_created_at = note.created_at + rule.note_updated_at = note.updated_at + rule.note_user_login = note.user_login + rule.note_data = note.data + rule.save + end end active_rules = {} @@ -62,12 +65,14 @@ class CopyRuleNotesToRules < ActiveRecord::Migration end ActiveRuleNote.all.each do |note| - rule = active_rules[note.active_rule_id] - rule.note_created_at = note.created_at - rule.note_updated_at = note.updated_at - rule.note_user_login = note.user_login - rule.note_data = note.data - rule.save + active_rule = active_rules[note.active_rule_id] + if active_rule + active_rule.note_created_at = note.created_at + active_rule.note_updated_at = note.updated_at + active_rule.note_user_login = note.user_login + active_rule.note_data = note.data + active_rule.save + end end end -- 2.39.5