From 217728d515945fa61565a297b5a09a761bff9e47 Mon Sep 17 00:00:00 2001 From: simonbrandhof Date: Fri, 23 Dec 2011 23:50:02 +0100 Subject: Delete resource orphans in order to not index them This issue will be fixed in v2.14 (see SONAR-3120) --- .../java/org/sonar/jpa/entity/SchemaMigration.java | 4 +-- .../org/sonar/core/persistence/rows-derby.sql | 1 + .../db/migrate/240_delete_resource_orphans.rb | 41 ++++++++++++++++++++++ 3 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 sonar-server/src/main/webapp/WEB-INF/db/migrate/240_delete_resource_orphans.rb diff --git a/sonar-core/src/main/java/org/sonar/jpa/entity/SchemaMigration.java b/sonar-core/src/main/java/org/sonar/jpa/entity/SchemaMigration.java index 31b4b9338b2..13360df8748 100644 --- a/sonar-core/src/main/java/org/sonar/jpa/entity/SchemaMigration.java +++ b/sonar-core/src/main/java/org/sonar/jpa/entity/SchemaMigration.java @@ -34,8 +34,8 @@ public class SchemaMigration { public final static int VERSION_UNKNOWN = -1; - public static final int LAST_VERSION = 239; - public static final int VERSION_2_13 = 230; + public static final int LAST_VERSION = 240; + public static final int VERSION_2_13 = 240; public final static String TABLE_NAME = "schema_migrations"; 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 11579c6ed00..ac666f114d5 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 @@ -166,6 +166,7 @@ INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('236'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('237'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('238'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('239'); +INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('240'); 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/240_delete_resource_orphans.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/240_delete_resource_orphans.rb new file mode 100644 index 00000000000..5390a86bc96 --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/240_delete_resource_orphans.rb @@ -0,0 +1,41 @@ +# +# Sonar, entreprise quality control tool. +# Copyright (C) 2008-2011 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 +# + +# +# Delete the resource orphans that are automatically deleted as long as +# SONAR-3120 is not fixed. +# +# Sonar 2.13 +# +class DeleteResourceOrphans < ActiveRecord::Migration + + def self.up + ids=Project.find_by_sql(["select id from projects p where qualifier<>'LIB' and not exists (select * from snapshots s where s.project_id = p.id and s.islast=?)", true]) + say_with_time "Delete #{ids.size} resources" do + # partition ids because of the Oracle limitation on IN statements + ids.each_slice(999) do |partition_of_ids| + unless partition_of_ids.empty? + Project.delete_all(["id in (?)", partition_of_ids]) + end + end + end + end + +end -- cgit v1.2.3