]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-6256 Add migration to add dependencies.from_component_uuid and dependencies...
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Mon, 20 Apr 2015 10:42:47 +0000 (12:42 +0200)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Tue, 21 Apr 2015 15:34:05 +0000 (17:34 +0200)
12 files changed:
server/sonar-server/src/main/java/org/sonar/server/db/migrations/MigrationSteps.java
server/sonar-server/src/main/java/org/sonar/server/db/migrations/v52/AddDependenciesComponentUuidColumns.java [new file with mode: 0644]
server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/AddDependenciesComponentUuidColumnsTest.java [new file with mode: 0644]
server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v52/AddDependenciesComponentUuidColumnsTest/schema.sql [new file with mode: 0644]
server/sonar-web/src/main/webapp/WEB-INF/db/migrate/909_add_dependencies_component_uuids.rb [new file with mode: 0644]
sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.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/test/resources/org/sonar/core/purge/PurgeCommandsTest/shouldDeleteSnapshot-result.xml
sonar-core/src/test/resources/org/sonar/core/purge/PurgeCommandsTest/shouldDeleteSnapshot.xml
sonar-core/src/test/resources/org/sonar/core/purge/PurgeCommandsTest/shouldPurgeSnapshot-result.xml
sonar-core/src/test/resources/org/sonar/core/purge/PurgeCommandsTest/shouldPurgeSnapshot.xml

index 2944902fe348a2c2e67efe982f271e28edae2ce9..9b4de177310c9ed544ee4e63782e9ce832308e13 100644 (file)
@@ -64,6 +64,7 @@ import org.sonar.server.db.migrations.v51.FeedUsersLongDates;
 import org.sonar.server.db.migrations.v51.RemovePermissionsOnModulesMigrationStep;
 import org.sonar.server.db.migrations.v51.RenameComponentRelatedParamsInIssueFilters;
 import org.sonar.server.db.migrations.v51.UpdateProjectsModuleUuidPath;
+import org.sonar.server.db.migrations.v52.AddDependenciesComponentUuidColumns;
 import org.sonar.server.db.migrations.v52.FeedEventsComponentUuid;
 import org.sonar.server.db.migrations.v52.FeedProjectLinksComponentUuid;
 import org.sonar.server.db.migrations.v52.MoveProjectProfileAssociation;
@@ -135,6 +136,7 @@ public interface MigrationSteps {
     // 5.2
     FeedProjectLinksComponentUuid.class,
     FeedEventsComponentUuid.class,
-    MoveProjectProfileAssociation.class
+    MoveProjectProfileAssociation.class,
+    AddDependenciesComponentUuidColumns.class
     );
 }
diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v52/AddDependenciesComponentUuidColumns.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v52/AddDependenciesComponentUuidColumns.java
new file mode 100644 (file)
index 0000000..276cc57
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 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.
+ */
+
+package org.sonar.server.db.migrations.v52;
+
+import org.sonar.core.persistence.Database;
+import org.sonar.server.db.migrations.AddColumnsBuilder;
+import org.sonar.server.db.migrations.DdlChange;
+
+import java.sql.SQLException;
+
+/**
+ * Add the following columns to the dependencies table :
+ * - from_component_uuid
+ * - to_component_uuid
+ */
+public class AddDependenciesComponentUuidColumns extends DdlChange {
+
+  private final Database db;
+
+  public AddDependenciesComponentUuidColumns(Database db) {
+    super(db);
+    this.db = db;
+  }
+
+  @Override
+  public void execute(Context context) throws SQLException {
+    context.execute(generateSql());
+  }
+
+  private String generateSql() {
+    return new AddColumnsBuilder(db.getDialect(), "dependencies")
+      .addColumn(
+        new AddColumnsBuilder.ColumnDef()
+          .setName("from_component_uuid")
+          .setType(AddColumnsBuilder.ColumnDef.Type.STRING)
+          .setLimit(50)
+          .setNullable(true)
+      )
+      .addColumn(
+        new AddColumnsBuilder.ColumnDef()
+          .setName("to_component_uuid")
+          .setType(AddColumnsBuilder.ColumnDef.Type.STRING)
+          .setLimit(50)
+          .setNullable(true)
+      )
+      .build();
+  }
+
+}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/AddDependenciesComponentUuidColumnsTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/AddDependenciesComponentUuidColumnsTest.java
new file mode 100644 (file)
index 0000000..99e041a
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 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.
+ */
+
+package org.sonar.server.db.migrations.v52;
+
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.sonar.core.persistence.DbTester;
+
+import java.sql.Types;
+
+public class AddDependenciesComponentUuidColumnsTest {
+
+  @ClassRule
+  public static DbTester db = new DbTester().schema(AddDependenciesComponentUuidColumnsTest.class, "schema.sql");
+
+  AddDependenciesComponentUuidColumns migration;
+
+  @Before
+  public void setUp() throws Exception {
+    migration = new AddDependenciesComponentUuidColumns(db.database());
+  }
+
+  @Test
+  public void update_columns() throws Exception {
+    migration.execute();
+
+    db.assertColumnDefinition("dependencies", "from_component_uuid", Types.VARCHAR, 50);
+    db.assertColumnDefinition("dependencies", "to_component_uuid", Types.VARCHAR, 50);
+  }
+
+}
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v52/AddDependenciesComponentUuidColumnsTest/schema.sql b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v52/AddDependenciesComponentUuidColumnsTest/schema.sql
new file mode 100644 (file)
index 0000000..c750b15
--- /dev/null
@@ -0,0 +1,13 @@
+CREATE TABLE "DEPENDENCIES" (
+  "ID" BIGINT NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
+  "FROM_SNAPSHOT_ID" INTEGER,
+  "FROM_RESOURCE_ID" INTEGER,
+  "TO_SNAPSHOT_ID" INTEGER,
+  "TO_RESOURCE_ID" INTEGER,
+  "DEP_USAGE" VARCHAR(30),
+  "DEP_WEIGHT" INTEGER,
+  "PROJECT_SNAPSHOT_ID" INTEGER,
+  "PARENT_DEPENDENCY_ID" BIGINT,
+  "FROM_SCOPE" VARCHAR(3),
+  "TO_SCOPE" VARCHAR(3)
+);
diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/909_add_dependencies_component_uuids.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/909_add_dependencies_component_uuids.rb
new file mode 100644 (file)
index 0000000..3823386
--- /dev/null
@@ -0,0 +1,31 @@
+#
+# SonarQube, open source software quality management tool.
+# Copyright (C) 2008-2014 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.
+#
+
+#
+# SonarQube 5.2
+# SONAR-6256
+#
+class AddDependenciesComponentUuids < ActiveRecord::Migration
+
+  def self.up
+    execute_java_migration('org.sonar.server.db.migrations.v52.AddDependenciesComponentUuidColumns')
+  end
+
+end
index 78d238fd14ac47432fe1b98dc2344fca0eeccf41..59a46e128eac05c30f077e8f9a67576c0cbaaab8 100644 (file)
@@ -33,7 +33,7 @@ import java.util.List;
  */
 public class DatabaseVersion implements BatchComponent, ServerComponent {
 
-  public static final int LAST_VERSION = 908;
+  public static final int LAST_VERSION = 909;
 
   /**
    * List of all the tables.n
index 32fdb045630711c5405bb2727bd0d4d756e29c88..17bda5bde4b36f3892f786527a64a70f10a34f07 100644 (file)
@@ -332,6 +332,7 @@ INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('905');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('906');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('907');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('908');
+INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('909');
 
 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', '1418215735482', '1418215735482', null, null);
 ALTER TABLE USERS ALTER COLUMN ID RESTART WITH 2;
index 5ebe86e0e1b94031a043c0e34a7a3736c84afb59..78b7586205d5318cffd40c29936092ffec673e56 100644 (file)
@@ -7,8 +7,10 @@ CREATE TABLE "DEPENDENCIES" (
   "ID" BIGINT NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
   "FROM_SNAPSHOT_ID" INTEGER,
   "FROM_RESOURCE_ID" INTEGER,
+  "FROM_COMPONENT_UUID" VARCHAR(50),
   "TO_SNAPSHOT_ID" INTEGER,
   "TO_RESOURCE_ID" INTEGER,
+  "TO_COMPONENT_UUID" VARCHAR(50),
   "DEP_USAGE" VARCHAR(30),
   "DEP_WEIGHT" INTEGER,
   "PROJECT_SNAPSHOT_ID" INTEGER,
index e6e06a96fa99bf36a4de8236bcc3561282ca7297..9a0a675bc2429ba5195ea1e8f07cccce64b469e2 100644 (file)
@@ -22,7 +22,7 @@
                     person_id="[null]"
                     text_value="[null]" tendency="[null]" measure_date="[null]" project_id="[null]"
                     alert_status="[null]" description="[null]" measure_data="[null]"/>
-  <dependencies id="1" from_resource_id="1" from_snapshot_id="1" to_resource_id="30" to_snapshot_id="30"
+  <dependencies id="1" from_resource_id="1" from_component_uuid="A" from_snapshot_id="1" to_resource_id="30" to_component_uuid="CC" to_snapshot_id="30"
                 parent_dependency_id="[null]" project_snapshot_id="1"
                 dep_usage="USES" dep_weight="1" from_scope="PRJ" to_scope="LIB"/>
   <events id="1" name="Version 1.0" component_uuid="1" snapshot_id="1" category="VERSION" description="[null]"
index a4cabcfff0dade6daeee73f95ec437939b6c9a59..4c5a6d70b1ca4d06376978c6630102092a854d80 100644 (file)
@@ -21,7 +21,7 @@
                     person_id="[null]"
                     text_value="[null]" tendency="[null]" measure_date="[null]" project_id="[null]"
                     alert_status="[null]" description="[null]" measure_data="[null]"/>
-  <dependencies id="1" from_resource_id="1" from_snapshot_id="1" to_resource_id="30" to_snapshot_id="30"
+  <dependencies id="1" from_resource_id="1" from_component_uuid="A" from_snapshot_id="1" to_resource_id="30" to_component_uuid="CC" to_snapshot_id="30"
                 parent_dependency_id="[null]" project_snapshot_id="1"
                 dep_usage="USES" dep_weight="1" from_scope="PRJ" to_scope="LIB"/>
   <events id="1" name="Version 1.0" component_uuid="1" snapshot_id="1" category="VERSION" description="[null]"
                     person_id="[null]"
                     text_value="[null]" tendency="[null]" measure_date="[null]" project_id="[null]"
                     alert_status="[null]" description="[null]" measure_data="[null]"/>
-  <dependencies id="2" from_resource_id="10" from_snapshot_id="10" to_resource_id="5" to_snapshot_id="5"
+  <dependencies id="2" from_resource_id="10" from_component_uuid="AA" from_snapshot_id="10" to_resource_id="5" to_component_uuid="E" to_snapshot_id="5"
                 parent_dependency_id="[null]" project_snapshot_id="5"
                 dep_usage="USES" dep_weight="1" from_scope="PRJ" to_scope="LIB"/>
-  <dependencies id="3" from_resource_id="5" from_snapshot_id="5" to_resource_id="300" to_snapshot_id="300"
+  <dependencies id="3" from_resource_id="5" from_component_uuid="C" from_snapshot_id="5" to_resource_id="300" to_component_uuid="CCC" to_snapshot_id="300"
                 parent_dependency_id="[null]" project_snapshot_id="5"
                 dep_usage="USES" dep_weight="1" from_scope="PRJ" to_scope="LIB"/>
   <events id="2" name="Version 1.0" component_uuid="5" snapshot_id="5" category="VERSION" description="[null]"
index 8ca10cdab74dba5c805b15fa8d53411bf9a819c3..92b18f08cf74cf090bdbe8bd8cfce242c6545e9c 100644 (file)
@@ -33,11 +33,11 @@ Note that measures, events and reviews are not deleted.
                     text_value="[null]" tendency="[null]" measure_date="[null]" alert_status="[null]"
                     description="[null]" measure_data="[null]"/>
 
-  <!--<dependencies id="1" from_resource_id="1" from_snapshot_id="1" to_resource_id="2" to_snapshot_id="2"-->
+  <!--<dependencies id="1" from_resource_id="1" from_component_uuid="A" from_snapshot_id="1" to_resource_id="2" to_component_uuid="B" to_snapshot_id="2"-->
   <!--parent_dependency_id="[null]" project_snapshot_id="[null]"-->
   <!--dep_usage="USES" dep_weight="1" from_scope="PRJ" to_scope="LIB"/>-->
 
-  <!--<dependencies id="2" from_resource_id="3" from_snapshot_id="3" to_resource_id="1" to_snapshot_id="1"-->
+  <!--<dependencies id="2" from_resource_id="3" from_component_uuid="C" from_snapshot_id="3" to_resource_id="1" to_component_uuid="A" to_snapshot_id="1"-->
   <!--parent_dependency_id="[null]" project_snapshot_id="2"-->
   <!--dep_usage="USES" dep_weight="1" from_scope="LIB" to_scope="PRJ"/>-->
 
@@ -72,11 +72,11 @@ Note that measures, events and reviews are not deleted.
                     text_value="[null]" tendency="[null]" measure_date="[null]" alert_status="[null]"
                     description="[null]" measure_data="[null]"/>
 
-  <dependencies id="3" from_resource_id="33" from_snapshot_id="33" to_resource_id="44" to_snapshot_id="44"
+  <dependencies id="3" from_resource_id="33" from_component_uuid="CC" from_snapshot_id="33" to_resource_id="44" to_component_uuid="DD" to_snapshot_id="44"
                 parent_dependency_id="[null]" project_snapshot_id="[null]"
                 dep_usage="USES" dep_weight="1" from_scope="PRJ" to_scope="LIB"/>
 
-  <dependencies id="4" from_resource_id="55" from_snapshot_id="55" to_resource_id="66" to_snapshot_id="66"
+  <dependencies id="4" from_resource_id="55" from_component_uuid="EE" from_snapshot_id="55" to_resource_id="66" to_component_uuid="FF" to_snapshot_id="66"
                 parent_dependency_id="[null]" project_snapshot_id="2"
                 dep_usage="USES" dep_weight="1" from_scope="LIB" to_scope="PRJ"/>
 
index 00253585b495d7b40cced5145ee946bf17b1f643..7881def58d335406a5afdffd5043e219d85b11a1 100644 (file)
                     tendency="[null]" measure_date="[null]" alert_status="[null]" description="[null]"
                     measure_data="[null]"/>
 
-  <dependencies id="1" from_resource_id="1" from_snapshot_id="1" to_resource_id="2" to_snapshot_id="2"
+  <dependencies id="1" from_resource_id="1" from_component_uuid="A" from_snapshot_id="1" to_resource_id="2" to_component_uuid="B" to_snapshot_id="2"
                 parent_dependency_id="[null]" project_snapshot_id="[null]"
                 dep_usage="USES" dep_weight="1" from_scope="PRJ" to_scope="LIB"/>
 
-  <dependencies id="2" from_resource_id="3" from_snapshot_id="3" to_resource_id="1" to_snapshot_id="1"
+  <dependencies id="2" from_resource_id="3" from_component_uuid="C" from_snapshot_id="3" to_resource_id="1" to_component_uuid="A" to_snapshot_id="1"
                 parent_dependency_id="[null]" project_snapshot_id="2"
                 dep_usage="USES" dep_weight="1" from_scope="LIB" to_scope="PRJ"/>
 
                     text_value="[null]" tendency="[null]" measure_date="[null]" alert_status="[null]"
                     description="[null]" measure_data="[null]"/>
 
-  <dependencies id="3" from_resource_id="33" from_snapshot_id="33" to_resource_id="44" to_snapshot_id="44"
+  <dependencies id="3" from_resource_id="33" from_component_uuid="CC" from_snapshot_id="33" to_resource_id="44" to_component_uuid="DD" to_snapshot_id="44"
                 parent_dependency_id="[null]" project_snapshot_id="[null]"
                 dep_usage="USES" dep_weight="1" from_scope="PRJ" to_scope="LIB"/>
 
-  <dependencies id="4" from_resource_id="55" from_snapshot_id="55" to_resource_id="66" to_snapshot_id="66"
+  <dependencies id="4" from_resource_id="55" from_component_uuid="EE" from_snapshot_id="55" to_resource_id="66" to_component_uuid="FF" to_snapshot_id="66"
                 parent_dependency_id="[null]" project_snapshot_id="2"
                 dep_usage="USES" dep_weight="1" from_scope="LIB" to_scope="PRJ"/>