From 264efca66065be97933f1085885168dea3d3c727 Mon Sep 17 00:00:00 2001 From: David Gageot Date: Thu, 24 May 2012 09:20:47 +0200 Subject: [PATCH] Fix Filter migration --- .../main/webapp/WEB-INF/db/migrate/115_create_filters.rb | 7 ++++--- .../db/migrate/302_create_global_dashboards_for_filter.rb | 7 +++++-- .../webapp/WEB-INF/db/migrate/304_add_key_to_filters.rb | 6 +++++- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/115_create_filters.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/115_create_filters.rb index b5e1903b555..afe9a2b7f50 100644 --- a/sonar-server/src/main/webapp/WEB-INF/db/migrate/115_create_filters.rb +++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/115_create_filters.rb @@ -39,6 +39,7 @@ class CreateFilters < ActiveRecord::Migration t.column 'resource_id', :integer, :null => true t.column 'default_view', :string, :limit => 20, :null => true t.column 'page_size', :integer, :null => true + t.column 'kee', :string, :limit => 100, :null => true end create_table 'filter_columns' do |t| @@ -86,7 +87,7 @@ class CreateFilters < ActiveRecord::Migration end def self.create_projects_filter - projects_filter=::Filter.new(:name => 'Projects', :shared => true, :favourites => false, :default_view => ::Filter::VIEW_LIST) + projects_filter=::Filter.new(:name => 'Projects', :kee => 'Projects', :shared => true, :favourites => false, :default_view => ::Filter::VIEW_LIST) projects_filter.criteria< 'metric', :kee => 'alert_status', :order_index => 1) projects_filter.columns.build(:family => 'name', :order_index => 2, :sort_direction => 'ASC') @@ -130,7 +131,7 @@ class CreateFilters < ActiveRecord::Migration size_metric=property_value('sonar.core.treemap.sizemetric', 'ncloc') color_metric=property_value('sonar.core.treemap.colormetric', 'violations_density') - treemap_filter=::Filter.new(:name => 'Treemap', :shared => true, :favourites => false, :default_view => ::Filter::VIEW_TREEMAP) + treemap_filter=::Filter.new(:name => 'Treemap', :kee => 'Treemap', :shared => true, :favourites => false, :default_view => ::Filter::VIEW_TREEMAP) treemap_filter.criteria< 'name', :order_index => 1) treemap_filter.columns.build(:family => 'metric', :kee => size_metric, :order_index => 2) @@ -143,7 +144,7 @@ class CreateFilters < ActiveRecord::Migration end def self.create_favourites_filter - favourites_filter=::Filter.new(:name => 'My favourites', :shared => true, :favourites => true, :default_view => ::Filter::VIEW_LIST) + favourites_filter=::Filter.new(:name => 'My favourites', :kee => 'My favourites', :shared => true, :favourites => true, :default_view => ::Filter::VIEW_LIST) favourites_filter.criteria< 'metric', :kee => 'alert_status', :order_index => 1) favourites_filter.columns.build(:family => 'name', :order_index => 2, :sort_direction => 'ASC') diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/302_create_global_dashboards_for_filter.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/302_create_global_dashboards_for_filter.rb index acd85806e6a..4fb90f9926e 100644 --- a/sonar-server/src/main/webapp/WEB-INF/db/migrate/302_create_global_dashboards_for_filter.rb +++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/302_create_global_dashboards_for_filter.rb @@ -37,6 +37,9 @@ class CreateGlobalDashboardsForFilter < ActiveRecord::Migration class WidgetProperty < ActiveRecord::Base end + class Filter < ActiveRecord::Base + end + def self.up dashboard_per_filter = create_global_dahboards() activate_dashboards(dashboard_per_filter) @@ -46,7 +49,7 @@ class CreateGlobalDashboardsForFilter < ActiveRecord::Migration def self.create_global_dahboards dashboards = {} - ::Filter.find(:all).each do |filter| + Filter.find(:all).each do |filter| dashboard = Dashboard.create(:user_id => filter.user_id, :name => filter.name, :description => '', @@ -73,7 +76,7 @@ class CreateGlobalDashboardsForFilter < ActiveRecord::Migration def self.activate_dashboards(dashboard_per_filter) ActiveFilter.find(:all).each do |activeFilter| - filter = ::Filter.find(activeFilter.filter_id) + filter = Filter.find(activeFilter.filter_id) dashboard = dashboard_per_filter[filter.id] diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/304_add_key_to_filters.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/304_add_key_to_filters.rb index 9dcbb4adb07..997b44f7d9c 100644 --- a/sonar-server/src/main/webapp/WEB-INF/db/migrate/304_add_key_to_filters.rb +++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/304_add_key_to_filters.rb @@ -54,7 +54,11 @@ class AddKeyToFilters < ActiveRecord::Migration def self.add_key_column_to_filters keys = {} - add_column 'filters', 'kee', :string, :null => true, :limit => 100 + begin + add_column 'filters', 'kee', :string, :null => true, :limit => 100 + rescue + # Assume the column was already added by a previous migration + end Filter.reset_column_information Filter.find(:all).each do |filter| -- 2.39.5