]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-3755 Add action_plans_issues table and add purge of all issues tables
authorJulien Lancelot <julien.lancelot@gmail.com>
Thu, 2 May 2013 10:18:29 +0000 (12:18 +0200)
committerJulien Lancelot <julien.lancelot@gmail.com>
Thu, 2 May 2013 10:18:29 +0000 (12:18 +0200)
12 files changed:
sonar-core/src/main/java/org/sonar/core/persistence/DatabaseUtils.java
sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java
sonar-core/src/main/java/org/sonar/core/purge/PurgeCommands.java
sonar-core/src/main/java/org/sonar/core/purge/PurgeMapper.java
sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql
sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl
sonar-core/src/main/resources/org/sonar/core/purge/PurgeMapper.xml
sonar-core/src/test/java/org/sonar/core/purge/PurgeCommandsTest.java
sonar-core/src/test/java/org/sonar/core/purge/PurgeDaoTest.java
sonar-core/src/test/resources/org/sonar/core/purge/PurgeCommandsTest/shouldDeleteResource.xml
sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldDeleteProject.xml
sonar-server/src/main/webapp/WEB-INF/db/migrate/393_create_action_plans_issues.rb [new file with mode: 0644]

index b2ed5c6be766e19da43de21ec65481c3aac1c13a..df03d50584396cc271aec8c9a9cdc38432b11fd1 100644 (file)
@@ -42,6 +42,7 @@ public final class DatabaseUtils {
    */
   static final String[] TABLE_NAMES = {
     "action_plans",
+    "action_plans_issues",
     "action_plans_reviews",
     "active_dashboards",
     "active_rules",
index e5fd64348f01bcda15ef3d342867167b51c158a0..7b6db8321bf9a256bea3a99a6667ac1849a2a242 100644 (file)
@@ -32,7 +32,7 @@ import java.util.List;
  */
 public class DatabaseVersion implements BatchComponent, ServerComponent {
 
-  public static final int LAST_VERSION = 392;
+  public static final int LAST_VERSION = 393;
 
   public static enum Status {
     UP_TO_DATE, REQUIRES_UPGRADE, REQUIRES_DOWNGRADE, FRESH_INSTALL
index 1ef2b7839826e5e9cf38db964dc70b4f5e68b01f..67d65e69b0dc3177a5ea1c9c23ad71e60bbeed8c 100644 (file)
@@ -121,6 +121,27 @@ class PurgeCommands {
     session.commit();
     profiler.stop();
 
+    profiler.start("deleteResourceIssueChanges (issue_changes)");
+    for (Long resourceId : resourceIds) {
+      purgeMapper.deleteResourceIssueChanges(resourceId);
+    }
+    session.commit();
+    profiler.stop();
+
+    profiler.start("deleteResourceActionPlansIssues (action_plans_issues)");
+    for (Long resourceId : resourceIds) {
+      purgeMapper.deleteResourceActionPlansIssues(resourceId);
+    }
+    session.commit();
+    profiler.stop();
+
+    profiler.start("deleteResourceIssues (issues)");
+    for (Long resourceId : resourceIds) {
+      purgeMapper.deleteResourceIssues(resourceId);
+    }
+    session.commit();
+    profiler.stop();
+
     profiler.start("deleteResourceActionPlans (action_plans)");
     for (Long resourceId : resourceIds) {
       purgeMapper.deleteResourceActionPlans(resourceId);
index 3db4683fc7fbcbb64e45eda3b92b621760a93795..41632dabe16332275582e39805b61bf015a6929d 100644 (file)
@@ -100,4 +100,11 @@ public interface PurgeMapper {
   void deleteResourceActionPlansReviews(long resourceId);
 
   void deleteSnapshotData(long snapshotId);
+
+  void deleteResourceActionPlansIssues(long resourceId);
+
+  void deleteResourceIssueChanges(long resourceId);
+
+  void deleteResourceIssues(long resourceId);
+
 }
index 2618646ea537383ca8683cc9dd10544df2bf777f..1ea246041f596f4d82c58064a5dde17d81c5ce00 100644 (file)
@@ -160,6 +160,7 @@ INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('389');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('390');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('391');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('392');
+INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('393');
 
 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;
index 51ea3f16086ad104f599e951e7988c8141f37bc1..34f3fd55b10ee351bb0466341f48751a09808b50 100644 (file)
@@ -550,6 +550,11 @@ CREATE TABLE "ISSUE_CHANGES" (
   "UPDATED_AT" TIMESTAMP,
 );
 
+CREATE TABLE "ACTION_PLANS_ISSUES" (
+  "ACTION_PLAN_ID" INTEGER,
+  "ISSUE_ID" INTEGER
+);
+
 CREATE TABLE "SNAPSHOT_DATA" (
   "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
   "SNAPSHOT_ID" INTEGER,
@@ -674,6 +679,10 @@ CREATE UNIQUE INDEX "GRAPHS_PERSPECTIVES" ON "GRAPHS" ("SNAPSHOT_ID", "PERSPECTI
 
 CREATE INDEX "ISSUES_RESOURCE_ID" ON "ISSUES" ("RESOURCE_ID");
 
+CREATE INDEX "INDEX_ACTION_PLANS_ISSUES_ON_ACTION_PLAN_ID" ON "ACTION_PLANS_ISSUES" ("ACTION_PLAN_ID");
+
+CREATE INDEX "INDEX_ACTION_PLANS_ISSUES_ON_ISSUE_ID" ON "ACTION_PLANS_ISSUES" ("ISSUE_ID");
+
 --CREATE INDEX "ISSUES_RULE_ID" ON "ISSUES" ("RULE_ID");
 
 --CREATE INDEX "SNAPSHOT_DATA_SNAPSHOT_ID" ON "SNAPSHOT_DATA" ("SNAPSHOT_ID");
index 9e9d09df62334de68bbb0537ee3a9fb5b7bd963f..19234980e1dd10b97aaeb78ba8e853b047516f21 100644 (file)
     delete apr from action_plans_reviews as apr, action_plans as ap where ap.id=apr.action_plan_id and ap.project_id=#{id}
   </delete>
 
+  <delete id="deleteResourceActionPlansIssues" parameterType="long">
+    delete from action_plans_issues api where exists (select * from action_plans ap where ap.id=api.action_plan_id and ap.project_id=#{id})
+  </delete>
+
+  <delete id="deleteResourceIssueChanges" parameterType="long">
+    delete from issue_changes ic where exists (select * from issues i where ic.issue_key=i.kee and i.resource_id=#{id})
+  </delete>
+
+  <delete id="deleteResourceIssues" parameterType="long">
+    delete from issues where resource_id=#{id}
+  </delete>
+
 </mapper>
 
index 0faf10d96ac1f9ae4d742a9e83f8f42a127cb6bb..ba7a7208d6b3074f48cdc1d40dc1dbce809b7b50 100644 (file)
@@ -92,7 +92,7 @@ public class PurgeCommandsTest extends AbstractDaoTestCase {
     } finally {
       MyBatis.closeQuietly(session);
     }
-    assertEmptyTables("projects", "snapshots", "events", "reviews", "review_comments", "authors");
+    assertEmptyTables("projects", "snapshots", "events", "reviews", "review_comments", "issues", "issue_changes", "authors");
   }
 
 }
index 83bb049c0e7968513746037b3c0c125578d700b9..038cc711685f1a5d0634c97febf5cfaaf678400b 100644 (file)
@@ -111,7 +111,7 @@ public class PurgeDaoTest extends AbstractDaoTestCase {
   public void shouldDeleteProject() {
     setupData("shouldDeleteProject");
     dao.deleteResourceTree(1L);
-    assertEmptyTables("projects", "snapshots", "action_plans", "action_plans_reviews", "reviews", "review_comments");
+    assertEmptyTables("projects", "snapshots", "action_plans", "action_plans_reviews", "reviews", "review_comments", "issues", "issue_changes", "action_plans_issues");
   }
 
   static final class SnapshotMatcher extends BaseMatcher<PurgeableSnapshotDto> {
index ff3b37a56eac269856cd42d5a2d3c39b53ff73f4..f603e893826f0f87b2130d358608ddb780edfa0b 100644 (file)
 
   <review_comments id="1" created_at="[null]" updated_at="[null]" review_id="1" user_id="1223" review_text="abc"/>
 
+  <issues id="1" kee="ABCDE" resource_id="1" status="CLOSED" resolution="[null]" created_at="[null]" line="200" severity="BLOCKER"
+          user_login="perceval" assignee_login="arthur" rule_id="500" manual_issue="[true]" manual_severity="[false]" description="[null]"/>
+
+  <issue_changes id="1" issue_key="ABCDE" created_at="[null]" updated_at="[null]" user_login="admin" message="abc"/>
+
   <authors id="1" person_id="1" login="tartanpion" created_at="[null]" updated_at="[null]" />
   <authors id="2" person_id="1" login="fanfoue" created_at="[null]" updated_at="[null]" />
 </dataset>
\ No newline at end of file
index 8888c64bb0fcea9f7bff68221109178f73ac1116..3df0470a044cc570350190a0e736b883d18a4c26 100644 (file)
@@ -21,6 +21,8 @@
 
   <action_plans_reviews action_plan_id="1" review_id="250" />
 
+  <action_plans_issues action_plan_id="1" issue_id="250" />
+
   <reviews id="1" project_id="1" resource_id="1" status="CLOSED"
         rule_failure_permanent_id="1" resolution="[null]" created_at="[null]" resource_line="200" severity="BLOCKER"
         user_id="300" assignee_id="300" rule_id="500" manual_violation="[true]" manual_severity="[false]" title="[null]"/>
 
   <review_comments id="1" created_at="[null]" updated_at="[null]" review_id="2" user_id="1223" review_text="abc"/>
 
+  <issues id="1" kee="ABCDE" resource_id="1" status="CLOSED" resolution="[null]" created_at="[null]" line="200" severity="BLOCKER"
+          user_login="perceval" assignee_login="arthur" rule_id="500" manual_issue="[true]" manual_severity="[false]" description="[null]"/>
+
+  <issues id="2" kee="ABCDF" resource_id="1" status="CLOSED" resolution="[null]" created_at="[null]" line="200" severity="BLOCKER"
+          user_login="perceval" assignee_login="arthur" rule_id="500" manual_issue="[true]" manual_severity="[false]" description="[null]"/>
+
+  <issue_changes id="1" issue_key="ABCDF" created_at="[null]" updated_at="[null]" user_login="admin" message="abc"/>
+
   <!-- modules -->
   <projects id="2" enabled="[true]" root_id="1"
             long_name="[null]" scope="PRJ" qualifier="BRC" kee="module1" name="module1"
diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/393_create_action_plans_issues.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/393_create_action_plans_issues.rb
new file mode 100644 (file)
index 0000000..b2a8233
--- /dev/null
@@ -0,0 +1,37 @@
+#
+# Sonar, entreprise quality control tool.
+# Copyright (C) 2008-2013 SonarSource
+# mailto:contact AT sonarsource DOT com
+#
+# SonarQube 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.
+#
+# SonarQube 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 this program; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+#
+
+#
+# Sonar 3.6
+#
+class CreateActionPlansIssues < ActiveRecord::Migration
+
+  def self.up
+    create_table :action_plans_issues, :id => false do |t|
+      t.integer :action_plan_id
+      t.integer :issue_id
+    end
+
+    add_index "action_plans_issues", "action_plan_id", :name => 'I_ACT_PLA_ISSUE_ACT_PLA_ID'
+    add_index "action_plans_issues", "issue_id", :name => 'I_ACT_PLA_ISSUE_ISSUE_ID'
+  end
+
+end
+