]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-6256 Add migration to feed dependencies.from_component_uuid and dependencies...
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Mon, 20 Apr 2015 13:38:08 +0000 (15:38 +0200)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Tue, 21 Apr 2015 15:34:06 +0000 (17:34 +0200)
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/FeedDependenciesComponentUuids.java [new file with mode: 0644]
server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/FeedDependenciesComponentUuidsTest.java [new file with mode: 0644]
server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v52/FeedDependenciesComponentUuidsTest/migrate-result.xml [new file with mode: 0644]
server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v52/FeedDependenciesComponentUuidsTest/migrate.xml [new file with mode: 0644]
server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v52/FeedDependenciesComponentUuidsTest/not_migrate_already_migrated_data.xml [new file with mode: 0644]
server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v52/FeedDependenciesComponentUuidsTest/schema.sql [new file with mode: 0644]
server/sonar-web/src/main/webapp/WEB-INF/db/migrate/910_feed_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

index 9b4de177310c9ed544ee4e63782e9ce832308e13..127709ccafdd55a9ea49961561195e048c64873f 100644 (file)
@@ -65,6 +65,7 @@ import org.sonar.server.db.migrations.v51.RemovePermissionsOnModulesMigrationSte
 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.FeedDependenciesComponentUuids;
 import org.sonar.server.db.migrations.v52.FeedEventsComponentUuid;
 import org.sonar.server.db.migrations.v52.FeedProjectLinksComponentUuid;
 import org.sonar.server.db.migrations.v52.MoveProjectProfileAssociation;
@@ -137,6 +138,7 @@ public interface MigrationSteps {
     FeedProjectLinksComponentUuid.class,
     FeedEventsComponentUuid.class,
     MoveProjectProfileAssociation.class,
-    AddDependenciesComponentUuidColumns.class
+    AddDependenciesComponentUuidColumns.class,
+    FeedDependenciesComponentUuids.class
     );
 }
diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v52/FeedDependenciesComponentUuids.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v52/FeedDependenciesComponentUuids.java
new file mode 100644 (file)
index 0000000..fcb4ecb
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+ * 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.BaseDataChange;
+import org.sonar.server.db.migrations.MassUpdate;
+import org.sonar.server.db.migrations.Select;
+import org.sonar.server.db.migrations.SqlStatement;
+
+import java.sql.SQLException;
+
+/**
+ * Add the following columns to the dependencies table :
+ * - from_component_uuid
+ * - to_component_uuid
+ */
+public class FeedDependenciesComponentUuids extends BaseDataChange {
+
+
+  public FeedDependenciesComponentUuids(Database db) {
+    super(db);
+  }
+
+  @Override
+  public void execute(Context context) throws SQLException {
+    MassUpdate update = context.prepareMassUpdate().rowPluralName("dependencies");
+    update.select(
+      "SELECT from_component.uuid, to_component.uuid, dependency.id " +
+        "FROM dependencies dependency " +
+        "INNER JOIN projects from_component ON from_component.id=dependency.from_resource_id " +
+        "INNER JOIN projects to_component ON to_component.id=dependency.to_resource_id " +
+        "WHERE dependency.from_component_uuid IS NULL");
+    update.update("UPDATE dependencies SET from_component_uuid=?, to_component_uuid=? WHERE id=?");
+    update.execute(new MassUpdate.Handler() {
+      @Override
+      public boolean handle(Select.Row row, SqlStatement update) throws SQLException {
+        update.setString(1, row.getString(1));
+        update.setString(2, row.getString(2));
+        update.setLong(3, row.getLong(3));
+        return true;
+      }
+    });
+  }
+
+}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/FeedDependenciesComponentUuidsTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/FeedDependenciesComponentUuidsTest.java
new file mode 100644 (file)
index 0000000..ab46ea1
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * 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 org.sonar.server.db.migrations.MigrationStep;
+
+public class FeedDependenciesComponentUuidsTest {
+
+  @ClassRule
+  public static DbTester db = new DbTester().schema(FeedDependenciesComponentUuidsTest.class, "schema.sql");
+
+  MigrationStep migration;
+
+  @Before
+  public void setUp() throws Exception {
+    db.executeUpdateSql("truncate table dependencies");
+    db.executeUpdateSql("truncate table projects");
+
+    migration = new FeedDependenciesComponentUuids(db.database());
+  }
+
+  @Test
+  public void migrate_empty_db() throws Exception {
+    migration.execute();
+  }
+
+  @Test
+  public void migrate() throws Exception {
+    db.prepareDbUnit(this.getClass(), "migrate.xml");
+    migration.execute();
+    db.assertDbUnit(this.getClass(), "migrate-result.xml", "dependencies");
+  }
+
+  @Test
+  public void not_migrate_already_migrated_data() throws Exception {
+    db.prepareDbUnit(this.getClass(), "not_migrate_already_migrated_data.xml");
+    migration.execute();
+    db.assertDbUnit(this.getClass(), "not_migrate_already_migrated_data.xml", "dependencies");
+  }
+
+}
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v52/FeedDependenciesComponentUuidsTest/migrate-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v52/FeedDependenciesComponentUuidsTest/migrate-result.xml
new file mode 100644 (file)
index 0000000..fc8040f
--- /dev/null
@@ -0,0 +1,7 @@
+<dataset>
+
+  <dependencies id="1" from_resource_id="1" from_component_uuid="ABCD" from_snapshot_id="1" to_resource_id="2" to_component_uuid="EFGH" to_snapshot_id="2"
+                parent_dependency_id="[null]" project_snapshot_id="1"
+                dep_usage="USES" dep_weight="1" from_scope="PRJ" to_scope="PRJ"/>
+
+</dataset>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v52/FeedDependenciesComponentUuidsTest/migrate.xml b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v52/FeedDependenciesComponentUuidsTest/migrate.xml
new file mode 100644 (file)
index 0000000..f8d460c
--- /dev/null
@@ -0,0 +1,19 @@
+<dataset>
+
+  <projects id="1" root_id="[null]" scope="PRJ" qualifier="TRK" kee="org.struts:struts" name="Struts" deprecated_kee="org.struts:struts"
+            uuid="ABCD" project_uuid="ABCD" module_uuid="[null]" module_uuid_path=""
+            description="the description" long_name="Apache Struts"
+            enabled="[true]" language="[null]" copy_resource_id="[null]" person_id="[null]" path="[null]"
+            created_at="2008-12-02 13:58:00.00" authorization_updated_at="[null]"/>
+
+  <projects id="2" root_id="[null]" scope="PRJ" qualifier="TRK" kee="git" name="Git" deprecated_kee="git"
+            uuid="EFGH" project_uuid="EFGH" module_uuid="[null]" module_uuid_path=""
+            description="the description" long_name="Git"
+            enabled="[true]" language="[null]" copy_resource_id="[null]" person_id="[null]" path="[null]"
+            created_at="2009-12-02 13:58:00.00" authorization_updated_at="[null]"/>
+
+  <dependencies id="1" from_resource_id="1" from_component_uuid="[null]" from_snapshot_id="1" to_resource_id="2" to_component_uuid="[null]" to_snapshot_id="2"
+                parent_dependency_id="[null]" project_snapshot_id="1"
+                dep_usage="USES" dep_weight="1" from_scope="PRJ" to_scope="PRJ"/>
+
+</dataset>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v52/FeedDependenciesComponentUuidsTest/not_migrate_already_migrated_data.xml b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v52/FeedDependenciesComponentUuidsTest/not_migrate_already_migrated_data.xml
new file mode 100644 (file)
index 0000000..65df42f
--- /dev/null
@@ -0,0 +1,19 @@
+<dataset>
+
+  <projects id="1" root_id="[null]" scope="PRJ" qualifier="TRK" kee="org.struts:struts" name="Struts" deprecated_kee="org.struts:struts"
+            uuid="ABCD" project_uuid="ABCD" module_uuid="[null]" module_uuid_path=""
+            description="the description" long_name="Apache Struts"
+            enabled="[true]" language="[null]" copy_resource_id="[null]" person_id="[null]" path="[null]"
+            created_at="2008-12-02 13:58:00.00" authorization_updated_at="[null]"/>
+
+  <projects id="2" root_id="[null]" scope="PRJ" qualifier="TRK" kee="git" name="Git" deprecated_kee="git"
+            uuid="EFGH" project_uuid="EFGH" module_uuid="[null]" module_uuid_path=""
+            description="the description" long_name="Git"
+            enabled="[true]" language="[null]" copy_resource_id="[null]" person_id="[null]" path="[null]"
+            created_at="2009-12-02 13:58:00.00" authorization_updated_at="[null]"/>
+
+  <dependencies id="1" from_resource_id="1" from_component_uuid="ABCD" from_snapshot_id="1" to_resource_id="30" to_component_uuid="EFGH" to_snapshot_id="30"
+                parent_dependency_id="[null]" project_snapshot_id="1"
+                dep_usage="USES" dep_weight="1" from_scope="PRJ" to_scope="PRJ"/>
+
+</dataset>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v52/FeedDependenciesComponentUuidsTest/schema.sql b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v52/FeedDependenciesComponentUuidsTest/schema.sql
new file mode 100644 (file)
index 0000000..9dbb6c3
--- /dev/null
@@ -0,0 +1,38 @@
+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,
+  "PARENT_DEPENDENCY_ID" BIGINT,
+  "FROM_SCOPE" VARCHAR(3),
+  "TO_SCOPE" VARCHAR(3)
+);
+
+CREATE TABLE "PROJECTS" (
+  "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
+  "KEE" VARCHAR(400),
+  "ROOT_ID" INTEGER,
+  "UUID" VARCHAR(50),
+  "PROJECT_UUID" VARCHAR(50),
+  "MODULE_UUID" VARCHAR(50),
+  "MODULE_UUID_PATH" VARCHAR(4000),
+  "NAME" VARCHAR(256),
+  "DESCRIPTION" VARCHAR(2000),
+  "ENABLED" BOOLEAN NOT NULL DEFAULT TRUE,
+  "SCOPE" VARCHAR(3),
+  "QUALIFIER" VARCHAR(10),
+  "DEPRECATED_KEE" VARCHAR(400),
+  "PATH" VARCHAR(2000),
+  "LANGUAGE" VARCHAR(20),
+  "COPY_RESOURCE_ID" INTEGER,
+  "LONG_NAME" VARCHAR(256),
+  "PERSON_ID" INTEGER,
+  "CREATED_AT" TIMESTAMP,
+  "AUTHORIZATION_UPDATED_AT" BIGINT
+);
diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/910_feed_dependencies_component_uuids.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/910_feed_dependencies_component_uuids.rb
new file mode 100644 (file)
index 0000000..742920f
--- /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 FeedDependenciesComponentUuids < ActiveRecord::Migration
+
+  def self.up
+    execute_java_migration('org.sonar.server.db.migrations.v52.FeedDependenciesComponentUuids')
+  end
+
+end
index 59a46e128eac05c30f077e8f9a67576c0cbaaab8..87410d7a8cb7392f851f17df67ba86e64498d8f8 100644 (file)
@@ -33,7 +33,7 @@ import java.util.List;
  */
 public class DatabaseVersion implements BatchComponent, ServerComponent {
 
-  public static final int LAST_VERSION = 909;
+  public static final int LAST_VERSION = 910;
 
   /**
    * List of all the tables.n
index 17bda5bde4b36f3892f786527a64a70f10a34f07..1f19a2ff695a5b1d0ea80b3b7aa844a0d0a9b62b 100644 (file)
@@ -333,6 +333,7 @@ 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 SCHEMA_MIGRATIONS(VERSION) VALUES ('910');
 
 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;