From 24aba2834b1625ef224690821cc5e8c4f836b362 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Wed, 15 Feb 2012 13:50:23 +0100 Subject: Refactor existing db migrations to apply recommendations --- .../migrate/134_delete_checkstyle_translations.rb | 8 +++--- .../db/migrate/135_add_rules_enabled_column.rb | 4 +++ .../db/migrate/137_add_rules_cardinality.rb | 2 ++ .../db/migrate/139_add_characteristic_enabled.rb | 1 - .../db/migrate/142_delete_active_rules_orphans.rb | 3 ++ ...0_add_plugins_child_first_classloader_column.rb | 33 ---------------------- .../db/migrate/160_add_rule_failures_columns.rb | 1 - .../db/migrate/162_delete_iso_rule_categories.rb | 1 - .../db/migrate/163_add_variation_columns.rb | 16 ++++++----- .../db/migrate/165_set_nullable_rule_config_key.rb | 6 ++-- .../166_set_nullable_rule_parameter_description.rb | 6 ++-- .../db/migrate/168_add_periods_to_filters.rb | 5 ---- .../169_add_columns_for_profiles_inheritance.rb | 3 -- .../170_delete_unvalid_project_snapshots.rb | 4 +++ .../db/migrate/180_add_profiles_disabled.rb | 7 +++-- .../WEB-INF/db/migrate/181_add_plugin_base.rb | 32 --------------------- .../WEB-INF/db/migrate/202_create_rule_changes.rb | 8 ++++-- 17 files changed, 45 insertions(+), 95 deletions(-) delete mode 100644 sonar-server/src/main/webapp/WEB-INF/db/migrate/150_add_plugins_child_first_classloader_column.rb delete mode 100644 sonar-server/src/main/webapp/WEB-INF/db/migrate/181_add_plugin_base.rb (limited to 'sonar-server') diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/134_delete_checkstyle_translations.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/134_delete_checkstyle_translations.rb index 9c11cd53304..c3cd356fcb0 100644 --- a/sonar-server/src/main/webapp/WEB-INF/db/migrate/134_delete_checkstyle_translations.rb +++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/134_delete_checkstyle_translations.rb @@ -23,12 +23,12 @@ # class DeleteCheckstyleTranslations < ActiveRecord::Migration - def self.up - delete_rule('com.puppycrawl.tools.checkstyle.checks.TranslationCheck') + class Rule < ActiveRecord::Base end - def self.down - + def self.up + Rule.reset_column_information + delete_rule('com.puppycrawl.tools.checkstyle.checks.TranslationCheck') end private diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/135_add_rules_enabled_column.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/135_add_rules_enabled_column.rb index 24cec40d6fd..1c2eb969036 100644 --- a/sonar-server/src/main/webapp/WEB-INF/db/migrate/135_add_rules_enabled_column.rb +++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/135_add_rules_enabled_column.rb @@ -23,8 +23,12 @@ # class AddRulesEnabledColumn < ActiveRecord::Migration + class Rule < ActiveRecord::Base + end + def self.up add_column 'rules', 'enabled', :boolean, :null => true + Rule.reset_column_information Rule.update_all(Rule.sanitize_sql_for_assignment({:enabled=>true})) end diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/137_add_rules_cardinality.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/137_add_rules_cardinality.rb index f3cfa03284f..1aac1ec548d 100644 --- a/sonar-server/src/main/webapp/WEB-INF/db/migrate/137_add_rules_cardinality.rb +++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/137_add_rules_cardinality.rb @@ -22,6 +22,8 @@ # Sonar 2.3 # class AddRulesCardinality < ActiveRecord::Migration + class Rule < ActiveRecord::Base + end def self.up add_column 'rules', 'cardinality', :string, :null => true, :limit => 10 diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/139_add_characteristic_enabled.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/139_add_characteristic_enabled.rb index 15cc5ff890c..4db175d8e19 100644 --- a/sonar-server/src/main/webapp/WEB-INF/db/migrate/139_add_characteristic_enabled.rb +++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/139_add_characteristic_enabled.rb @@ -25,7 +25,6 @@ class AddCharacteristicEnabled < ActiveRecord::Migration def self.up add_column 'characteristics', 'enabled', :boolean, :null => true - Characteristic.reset_column_information end end diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/142_delete_active_rules_orphans.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/142_delete_active_rules_orphans.rb index bfb488453bd..783967bf80e 100644 --- a/sonar-server/src/main/webapp/WEB-INF/db/migrate/142_delete_active_rules_orphans.rb +++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/142_delete_active_rules_orphans.rb @@ -22,9 +22,12 @@ # Sonar 2.3.1 # class DeleteActiveRulesOrphans < ActiveRecord::Migration + class ActiveRule < ActiveRecord::Base + end def self.up # see http://jira.codehaus.org/browse/SONAR-1881 + ActiveRule.reset_column_information orphans=ActiveRule.find_by_sql "SELECT ar.* FROM active_rules ar WHERE NOT EXISTS (SELECT * FROM rules_profiles pr WHERE pr.id=ar.profile_id)" orphans.each do |orphan| orphan.destroy diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/150_add_plugins_child_first_classloader_column.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/150_add_plugins_child_first_classloader_column.rb deleted file mode 100644 index 2597e36be64..00000000000 --- a/sonar-server/src/main/webapp/WEB-INF/db/migrate/150_add_plugins_child_first_classloader_column.rb +++ /dev/null @@ -1,33 +0,0 @@ -# -# Sonar, entreprise quality control tool. -# Copyright (C) 2008-2012 SonarSource -# mailto:contact AT sonarsource DOT com -# -# Sonar is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 3 of the License, or (at your option) any later version. -# -# Sonar is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with Sonar; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 -# - -# -# Sonar 2.4 -# -class AddPluginsChildFirstClassloaderColumn < ActiveRecord::Migration - - def self.up - # this table has been removed in 2.9 (see migration 203) - #add_column 'plugins', 'child_first_classloader', :boolean, :null => true - #Plugin.reset_column_information - #Plugin.update_all(Plugin.sanitize_sql_for_assignment({:child_first_classloader=>false})) - end - -end diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/160_add_rule_failures_columns.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/160_add_rule_failures_columns.rb index 770d87215cc..e6fcf03a6df 100644 --- a/sonar-server/src/main/webapp/WEB-INF/db/migrate/160_add_rule_failures_columns.rb +++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/160_add_rule_failures_columns.rb @@ -26,7 +26,6 @@ class AddRuleFailuresColumns < ActiveRecord::Migration def self.up add_column 'rule_failures', 'created_at', :datetime, :null => true add_column 'rule_failures', 'checksum', :string , :null => true, :limit => 1000 - RuleFailure.reset_column_information() end end diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/162_delete_iso_rule_categories.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/162_delete_iso_rule_categories.rb index e0661553be3..a072f28dcbb 100644 --- a/sonar-server/src/main/webapp/WEB-INF/db/migrate/162_delete_iso_rule_categories.rb +++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/162_delete_iso_rule_categories.rb @@ -26,7 +26,6 @@ class DeleteIsoRuleCategories < ActiveRecord::Migration def self.up begin remove_column('rules', 'rules_category_id') - Rule.reset_column_information() rescue # already removed end diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/163_add_variation_columns.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/163_add_variation_columns.rb index 7a09fb67627..62735d89269 100644 --- a/sonar-server/src/main/webapp/WEB-INF/db/migrate/163_add_variation_columns.rb +++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/163_add_variation_columns.rb @@ -23,7 +23,16 @@ # class AddVariationColumns < ActiveRecord::Migration + class ProjectMeasure < ActiveRecord::Base + end + + class Snapshot < ActiveRecord::Base + end + def self.up + ProjectMeasure.reset_column_information + Snapshot.reset_column_information + dialect = ActiveRecord::Base.configurations[ ENV['RAILS_ENV'] ]["dialect"] say "Detected dialect: #{dialect}" @@ -49,9 +58,6 @@ class AddVariationColumns < ActiveRecord::Migration add_snapshots_columns() end - - ProjectMeasure.reset_column_information() - Snapshot.reset_column_information() end private @@ -195,7 +201,6 @@ class AddVariationColumns < ActiveRecord::Migration def self.remove_measures_column(colname) begin remove_column :project_measures, colname - ProjectMeasure.reset_column_information() rescue # already removed end @@ -204,13 +209,10 @@ class AddVariationColumns < ActiveRecord::Migration def self.add_measures_column(colname) unless ProjectMeasure.column_names.include?(name) add_column(:project_measures, colname, :decimal, :null => true, :precision => 30, :scale => 20) - ProjectMeasure.reset_column_information() end end def self.add_snapshots_columns() - Snapshot.reset_column_information() - add_period_column('period1_mode', :string, :null => true, :limit => 100) add_period_column('period1_param', :string, :null => true, :limit => 100) add_period_column('period1_date', :datetime, :null => true) diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/165_set_nullable_rule_config_key.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/165_set_nullable_rule_config_key.rb index c7f50c1cce1..66f188c5663 100644 --- a/sonar-server/src/main/webapp/WEB-INF/db/migrate/165_set_nullable_rule_config_key.rb +++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/165_set_nullable_rule_config_key.rb @@ -23,15 +23,17 @@ # class SetNullableRuleConfigKey < ActiveRecord::Migration + class Rule < ActiveRecord::Base + end + def self.up add_column(:rules, :temp_plugin_config_key, :string, :limit => 500, :null => true) - Rule.reset_column_information + Rule.reset_column_information Rule.update_all('temp_plugin_config_key=plugin_config_key') remove_column(:rules, :plugin_config_key) rename_column(:rules, :temp_plugin_config_key, :plugin_config_key) - Rule.reset_column_information end end diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/166_set_nullable_rule_parameter_description.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/166_set_nullable_rule_parameter_description.rb index 02b5b0f2d8f..032ea75c199 100644 --- a/sonar-server/src/main/webapp/WEB-INF/db/migrate/166_set_nullable_rule_parameter_description.rb +++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/166_set_nullable_rule_parameter_description.rb @@ -23,15 +23,17 @@ # class SetNullableRuleParameterDescription < ActiveRecord::Migration + class RulesParameter < ActiveRecord::Base + end + def self.up add_column(:rules_parameters, :temp_description, :string, :limit => 4000, :null => true) - RulesParameter.reset_column_information + RulesParameter.reset_column_information RulesParameter.update_all('temp_description=description') remove_column(:rules_parameters, :description) rename_column(:rules_parameters, :temp_description, :description) - RulesParameter.reset_column_information end end diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/168_add_periods_to_filters.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/168_add_periods_to_filters.rb index 602df07e04f..48f4d189467 100644 --- a/sonar-server/src/main/webapp/WEB-INF/db/migrate/168_add_periods_to_filters.rb +++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/168_add_periods_to_filters.rb @@ -25,13 +25,8 @@ class AddPeriodsToFilters < ActiveRecord::Migration def self.up add_column :filters, :period_index, :integer, :null => true - Filter.reset_column_information - add_column :filter_columns, :variation, :boolean, :null => true - FilterColumn.reset_column_information - add_column :criteria, :variation, :boolean, :null => true - Criterion.reset_column_information end end diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/169_add_columns_for_profiles_inheritance.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/169_add_columns_for_profiles_inheritance.rb index 9d22be503cf..873b4143442 100644 --- a/sonar-server/src/main/webapp/WEB-INF/db/migrate/169_add_columns_for_profiles_inheritance.rb +++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/169_add_columns_for_profiles_inheritance.rb @@ -25,10 +25,7 @@ class AddColumnsForProfilesInheritance < ActiveRecord::Migration def self.up add_column 'active_rules', 'inheritance', :string, :limit => 10, :null => true - ActiveRule.reset_column_information - add_column 'rules_profiles', 'parent_name', :string, :limit => 100, :null => true - Profile.reset_column_information end end diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/170_delete_unvalid_project_snapshots.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/170_delete_unvalid_project_snapshots.rb index 81e86eb1dcb..55d5cca813f 100644 --- a/sonar-server/src/main/webapp/WEB-INF/db/migrate/170_delete_unvalid_project_snapshots.rb +++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/170_delete_unvalid_project_snapshots.rb @@ -23,7 +23,11 @@ # class DeleteUnvalidProjectSnapshots < ActiveRecord::Migration + class Snapshot < ActiveRecord::Base + end + def self.up + Snapshot.reset_column_information snapshots=select_snapshots_without_measures delete_snapshots(snapshots) end diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/180_add_profiles_disabled.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/180_add_profiles_disabled.rb index 09652819aaa..cb8d89e6da4 100644 --- a/sonar-server/src/main/webapp/WEB-INF/db/migrate/180_add_profiles_disabled.rb +++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/180_add_profiles_disabled.rb @@ -23,11 +23,14 @@ # class AddProfilesDisabled < ActiveRecord::Migration + class RulesProfile < ActiveRecord::Base + end + def self.up add_column 'rules_profiles', 'enabled', :boolean, :null => false, :default => true - Profile.reset_column_information - Profile.find(:all).each do |profile| + RulesProfile.reset_column_information + RulesProfile.find(:all).each do |profile| profile.enabled=true profile.save end diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/181_add_plugin_base.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/181_add_plugin_base.rb deleted file mode 100644 index b76263cfd4c..00000000000 --- a/sonar-server/src/main/webapp/WEB-INF/db/migrate/181_add_plugin_base.rb +++ /dev/null @@ -1,32 +0,0 @@ -# -# Sonar, entreprise quality control tool. -# Copyright (C) 2008-2012 SonarSource -# mailto:contact AT sonarsource DOT com -# -# Sonar is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 3 of the License, or (at your option) any later version. -# -# Sonar is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with Sonar; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 -# - -# -# Sonar 2.6 -# -class AddPluginBase < ActiveRecord::Migration - - def self.up - # this table has been removed in 2.9 (see migration 203) - #add_column 'plugins', 'base_plugin', :string, :limit => 100, :null => true - #Plugin.reset_column_information - end - -end diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/202_create_rule_changes.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/202_create_rule_changes.rb index 55b080984eb..f16558d3587 100644 --- a/sonar-server/src/main/webapp/WEB-INF/db/migrate/202_create_rule_changes.rb +++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/202_create_rule_changes.rb @@ -23,6 +23,9 @@ # class CreateRuleChanges < ActiveRecord::Migration + class RulesProfile < ActiveRecord::Base + end + def self.up create_table :active_rule_changes do |t| t.column :user_name, :string, :limit => 200, :null => false @@ -46,8 +49,9 @@ class CreateRuleChanges < ActiveRecord::Migration add_column 'rules_profiles', 'version', :integer, :default => 1 add_column 'rules_profiles', 'used_profile', :boolean, :default => false - Profile.reset_column_information - Profile.update_all(Profile.sanitize_sql_for_assignment({:used_profile => false, :version => 1})) + + RulesProfile.reset_column_information + RulesProfile.update_all(RulesProfile.sanitize_sql_for_assignment({:used_profile => false, :version => 1})) end end -- cgit v1.2.3