From 06d5b65b5ef22119ee9e48216c211bbb8832c53e Mon Sep 17 00:00:00 2001 From: David Gageot Date: Fri, 25 May 2012 10:14:58 +0200 Subject: [PATCH] Split large migration file in two --- .../core/persistence/DatabaseVersion.java | 2 +- .../org/sonar/core/persistence/rows-derby.sql | 1 + .../db/migrate/304_add_key_to_filters.rb | 23 +--------- .../db/migrate/305_ignore_loaded_filters.rb | 44 +++++++++++++++++++ ...rds.rb => 306_ignore_loaded_dashboards.rb} | 0 5 files changed, 47 insertions(+), 23 deletions(-) create mode 100644 sonar-server/src/main/webapp/WEB-INF/db/migrate/305_ignore_loaded_filters.rb rename sonar-server/src/main/webapp/WEB-INF/db/migrate/{305_ignore_loaded_dashboards.rb => 306_ignore_loaded_dashboards.rb} (100%) diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java b/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java index 53221061679..0014a466638 100644 --- a/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java +++ b/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java @@ -35,7 +35,7 @@ import java.util.List; */ public class DatabaseVersion implements BatchComponent, ServerComponent { - public static final int LAST_VERSION = 305; + public static final int LAST_VERSION = 306; public static enum Status { UP_TO_DATE, REQUIRES_UPGRADE, REQUIRES_DOWNGRADE, FRESH_INSTALL diff --git a/sonar-core/src/main/resources/org/sonar/core/persistence/rows-derby.sql b/sonar-core/src/main/resources/org/sonar/core/persistence/rows-derby.sql index 07abf09b976..681838d3d8b 100644 --- a/sonar-core/src/main/resources/org/sonar/core/persistence/rows-derby.sql +++ b/sonar-core/src/main/resources/org/sonar/core/persistence/rows-derby.sql @@ -161,6 +161,7 @@ INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('302'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('303'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('304'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('305'); +INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('306'); INSERT INTO USERS(ID, LOGIN, NAME, EMAIL, CRYPTED_PASSWORD, SALT, CREATED_AT, UPDATED_AT, REMEMBER_TOKEN, REMEMBER_TOKEN_EXPIRES_AT) VALUES (1, 'admin', 'Administrator', '', 'a373a0e667abb2604c1fd571eb4ad47fe8cc0878', '48bc4b0d93179b5103fd3885ea9119498e9d161b', '2011-09-26 22:27:48.0', '2011-09-26 22:27:48.0', null, null); ALTER TABLE USERS ALTER COLUMN ID RESTART WITH 2; 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 a4d81c632ec..69a89eebfcf 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 @@ -22,39 +22,18 @@ # Sonar 3.1 # class AddKeyToFilters < ActiveRecord::Migration - class Filter < ActiveRecord::Base - end - class WidgetProperty < ActiveRecord::Base end - class LoadedTemplate < ActiveRecord::Base - end - def self.up - mark_default_filters_as_loaded() keys = add_key_column_to_filters() use_key_in_widget_properties(keys) end - def self.mark_default_filters_as_loaded - mark_filter_as_loaded('Projects') - mark_filter_as_loaded('Treemap') - mark_filter_as_loaded('My favourites') - end - - def self.mark_filter_as_loaded(name) - if Filter.find(:first, :conditions => {:name => name, :user_id => nil}) - unless LoadedTemplate.find(:first, :conditions => {:kee => name, :template_type => 'FILTER'}) - LoadedTemplate.create(:kee => name, :template_type => 'FILTER').save - end - end - end - def self.add_key_column_to_filters keys = {} - begin + begin add_column 'filters', 'kee', :string, :null => true, :limit => 100 rescue # Assume the column was already added by a previous migration diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/305_ignore_loaded_filters.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/305_ignore_loaded_filters.rb new file mode 100644 index 00000000000..ed780281c1b --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/305_ignore_loaded_filters.rb @@ -0,0 +1,44 @@ +# +# Sonar, open source software quality management 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 3.1 +# +class IgnoreLoadedFilters < ActiveRecord::Migration + class Filter < ActiveRecord::Base + end + + class LoadedTemplate < ActiveRecord::Base + end + + def self.up + mark_filter_as_loaded('Projects') + mark_filter_as_loaded('Treemap') + mark_filter_as_loaded('My favourites') + end + + def self.mark_filter_as_loaded(name) + if Filter.find(:first, :conditions => {:name => name, :user_id => nil}) + unless LoadedTemplate.find(:first, :conditions => {:kee => name, :template_type => 'FILTER'}) + LoadedTemplate.create(:kee => name, :template_type => 'FILTER').save + end + end + end +end diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/305_ignore_loaded_dashboards.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/306_ignore_loaded_dashboards.rb similarity index 100% rename from sonar-server/src/main/webapp/WEB-INF/db/migrate/305_ignore_loaded_dashboards.rb rename to sonar-server/src/main/webapp/WEB-INF/db/migrate/306_ignore_loaded_dashboards.rb -- 2.39.5