aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsimonbrandhof <simon.brandhof@gmail.com>2011-12-23 23:50:02 +0100
committersimonbrandhof <simon.brandhof@gmail.com>2011-12-23 23:50:02 +0100
commit217728d515945fa61565a297b5a09a761bff9e47 (patch)
treec3f45587d11c88912da54993e4e18e5c2f3cdda5
parent5683b43c4c61953c67a05699aea95e1082d9a7a9 (diff)
downloadsonarqube-217728d515945fa61565a297b5a09a761bff9e47.tar.gz
sonarqube-217728d515945fa61565a297b5a09a761bff9e47.zip
Delete resource orphans in order to not index them
This issue will be fixed in v2.14 (see SONAR-3120)
-rw-r--r--sonar-core/src/main/java/org/sonar/jpa/entity/SchemaMigration.java4
-rw-r--r--sonar-core/src/main/resources/org/sonar/core/persistence/rows-derby.sql1
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/db/migrate/240_delete_resource_orphans.rb41
3 files changed, 44 insertions, 2 deletions
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