From 1b714ecf1d3bb0930b3724d177d3d0de18d0ef3c Mon Sep 17 00:00:00 2001 From: simonbrandhof Date: Mon, 13 Feb 2012 16:04:24 +0100 Subject: [PATCH] SONAR-3248 purge REVIEW_COMMENTS and ACTION_PLANS This commit includes the new index on REVIEWS.RESOURCE_ID and the renaming of ACTION_PLANS.DEAD_LINE to DEADLINE --- .../java/org/sonar/core/purge/PurgeDao.java | 3 ++ .../org/sonar/core/purge/PurgeMapper.java | 6 ++++ .../org/sonar/jpa/entity/SchemaMigration.java | 2 +- .../org/sonar/core/persistence/rows-derby.sql | 2 ++ .../sonar/core/persistence/schema-derby.ddl | 4 ++- .../org/sonar/core/purge/PurgeMapper.xml | 12 +++++++ .../org/sonar/core/purge/PurgeDaoTest.java | 2 +- .../PurgeDaoTest/shouldDeleteProject.xml | 13 +++++++ .../WEB-INF/db/migrate/191_create_review.rb | 2 +- .../258_add_index_on_review_resource_id.rb | 34 +++++++++++++++++++ .../259_rename_action_plans_columns.rb | 30 ++++++++++++++++ 11 files changed, 106 insertions(+), 4 deletions(-) create mode 100644 sonar-server/src/main/webapp/WEB-INF/db/migrate/258_add_index_on_review_resource_id.rb create mode 100644 sonar-server/src/main/webapp/WEB-INF/db/migrate/259_rename_action_plans_columns.rb diff --git a/sonar-core/src/main/java/org/sonar/core/purge/PurgeDao.java b/sonar-core/src/main/java/org/sonar/core/purge/PurgeDao.java index fbf5f663e79..8a7bbf5f9a5 100644 --- a/sonar-core/src/main/java/org/sonar/core/purge/PurgeDao.java +++ b/sonar-core/src/main/java/org/sonar/core/purge/PurgeDao.java @@ -140,6 +140,9 @@ public class PurgeDao { mapper.deleteResourceUserRoles(resourceId); mapper.deleteResourceManualMeasures(resourceId); mapper.deleteResourceReviews(resourceId); + mapper.deleteResourceReviewComments(resourceId); + mapper.deleteResourceActionPlansReviews(resourceId); + mapper.deleteResourceActionPlans(resourceId); mapper.deleteResourceEvents(resourceId); mapper.deleteResource(resourceId); } diff --git a/sonar-core/src/main/java/org/sonar/core/purge/PurgeMapper.java b/sonar-core/src/main/java/org/sonar/core/purge/PurgeMapper.java index 3eb54da5b9b..964b734aac6 100644 --- a/sonar-core/src/main/java/org/sonar/core/purge/PurgeMapper.java +++ b/sonar-core/src/main/java/org/sonar/core/purge/PurgeMapper.java @@ -71,8 +71,14 @@ public interface PurgeMapper { void deleteResourceReviews(long resourceId); + void deleteResourceReviewComments(long resourceId); + void deleteResourceEvents(long resourceId); + void deleteResourceActionPlans(long resourceId); + + void deleteResourceActionPlansReviews(long resourceId); + void closeResourceReviews(long resourceId); List selectPurgeableSnapshotsWithEvents(long resourceId); 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 5b77f98c423..58325dfd4bc 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,7 +34,7 @@ public class SchemaMigration { public final static int VERSION_UNKNOWN = -1; - public static final int LAST_VERSION = 257; + public static final int LAST_VERSION = 259; public static final int VERSION_2_13 = 241; 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 26a063c5a2e..59c4d9f02cd 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 @@ -175,6 +175,8 @@ INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('254'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('255'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('256'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('257'); +INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('258'); +INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('259'); 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-core/src/main/resources/org/sonar/core/persistence/schema-derby.ddl b/sonar-core/src/main/resources/org/sonar/core/persistence/schema-derby.ddl index 327f48e4e7c..2de07173e61 100644 --- a/sonar-core/src/main/resources/org/sonar/core/persistence/schema-derby.ddl +++ b/sonar-core/src/main/resources/org/sonar/core/persistence/schema-derby.ddl @@ -476,7 +476,7 @@ CREATE TABLE "ACTION_PLANS" ( "USER_ID" INTEGER, "NAME" VARCHAR(200), "DESCRIPTION" VARCHAR(1000), - "DEAD_LINE" TIMESTAMP, + "DEADLINE" TIMESTAMP, "USER_LOGIN" VARCHAR(40), "PROJECT_ID" INTEGER, "STATUS" VARCHAR(10), @@ -604,6 +604,8 @@ CREATE INDEX "INDEX_ACTIVE_RULE_NOTES_ON_ACTIVE_RULE_ID" ON "ACTIVE_RULE_NOTES" CREATE INDEX "INDEX_RULE_NOTES_ON_ACTIVE_RULE_ID" ON "RULE_NOTES" ("RULE_ID"); +CREATE INDEX "REVIEWS_RID" ON "REVIEWS" ("RESOURCE_ID"); + -- ---------------------------------------------- -- DDL Statements for keys diff --git a/sonar-core/src/main/resources/org/sonar/core/purge/PurgeMapper.xml b/sonar-core/src/main/resources/org/sonar/core/purge/PurgeMapper.xml index 815a1920462..e62a75ad90b 100644 --- a/sonar-core/src/main/resources/org/sonar/core/purge/PurgeMapper.xml +++ b/sonar-core/src/main/resources/org/sonar/core/purge/PurgeMapper.xml @@ -169,10 +169,22 @@ delete from reviews where resource_id=#{id} + + delete from review_comments rc where exists (select * from reviews r where rc.review_id=r.id and r.resource_id=#{id}) + + delete from events where resource_id=#{id} + + delete from action_plans where project_id=#{id} + + + + delete from action_plans_reviews apr where exists (select * from action_plans ap where ap.id=apr.action_plan_id and ap.project_id=#{id}) + + update snapshots set islast=${_false} where project_id=#{id} diff --git a/sonar-core/src/test/java/org/sonar/core/purge/PurgeDaoTest.java b/sonar-core/src/test/java/org/sonar/core/purge/PurgeDaoTest.java index 5d4e07a847a..df17a128b8f 100644 --- a/sonar-core/src/test/java/org/sonar/core/purge/PurgeDaoTest.java +++ b/sonar-core/src/test/java/org/sonar/core/purge/PurgeDaoTest.java @@ -174,7 +174,7 @@ public class PurgeDaoTest extends DaoTestCase { public void shouldDeleteProject() { setupData("shouldDeleteProject"); dao.deleteProject(1L); - assertEmptyTables("projects", "snapshots"); + assertEmptyTables("projects", "snapshots", "action_plans", "action_plans_reviews", "reviews", "review_comments"); } static final class SnapshotMatcher extends BaseMatcher { diff --git a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldDeleteProject.xml b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldDeleteProject.xml index 88e87f2583b..472874f6dee 100644 --- a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldDeleteProject.xml +++ b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldDeleteProject.xml @@ -16,6 +16,19 @@ build_date="2008-12-02 13:58:00.00" version="[null]" path="[null]"/> + + + + + + + + true, :limit => 10 t.column 'severity', :string, :null => true, :limit => 10 t.column 'rule_failure_permanent_id', :integer, :null => true - t.column 'project_id', :integer, :null => true + t.column 'project_id', :integer, :null => true t.column 'resource_id', :integer, :null => true t.column 'resource_line', :integer, :null => true end diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/258_add_index_on_review_resource_id.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/258_add_index_on_review_resource_id.rb new file mode 100644 index 00000000000..40810ba2a7f --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/258_add_index_on_review_resource_id.rb @@ -0,0 +1,34 @@ +# +# Sonar, entreprise quality control 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 2.14 +# +class AddIndexOnReviewResourceId < ActiveRecord::Migration + + def self.up + begin + add_index('reviews', 'resource_id', :name => 'reviews_rid') + rescue + # already exists + end + end + +end diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/259_rename_action_plans_columns.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/259_rename_action_plans_columns.rb new file mode 100644 index 00000000000..9ea0116032b --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/259_rename_action_plans_columns.rb @@ -0,0 +1,30 @@ +# +# Sonar, entreprise quality control 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 2.14 +# +class RenameActionPlansColumns < ActiveRecord::Migration + + def self.up + rename_column(:action_plans, :dead_line, :deadline) + end + +end -- 2.39.5