aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2015-04-20 15:38:08 +0200
committerJulien Lancelot <julien.lancelot@sonarsource.com>2015-04-21 17:34:06 +0200
commitc83af35f044f23b698ba23dca7097546b1eb2a13 (patch)
treefc4af6eef92dce6b945f746cae0333b2925d4515
parentacd4f5782083ad1efcc6ed8850c9d1fab9269291 (diff)
downloadsonarqube-c83af35f044f23b698ba23dca7097546b1eb2a13.tar.gz
sonarqube-c83af35f044f23b698ba23dca7097546b1eb2a13.zip
SONAR-6256 Add migration to feed dependencies.from_component_uuid and dependencies.to_component_uuid
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/db/migrations/MigrationSteps.java4
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/db/migrations/v52/FeedDependenciesComponentUuids.java64
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/FeedDependenciesComponentUuidsTest.java63
-rw-r--r--server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v52/FeedDependenciesComponentUuidsTest/migrate-result.xml7
-rw-r--r--server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v52/FeedDependenciesComponentUuidsTest/migrate.xml19
-rw-r--r--server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v52/FeedDependenciesComponentUuidsTest/not_migrate_already_migrated_data.xml19
-rw-r--r--server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v52/FeedDependenciesComponentUuidsTest/schema.sql38
-rw-r--r--server/sonar-web/src/main/webapp/WEB-INF/db/migrate/910_feed_dependencies_component_uuids.rb31
-rw-r--r--sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java2
-rw-r--r--sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql1
10 files changed, 246 insertions, 2 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/MigrationSteps.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/MigrationSteps.java
index 9b4de177310..127709ccafd 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/MigrationSteps.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/MigrationSteps.java
@@ -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
index 00000000000..fcb4ecb537d
--- /dev/null
+++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v52/FeedDependenciesComponentUuids.java
@@ -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
index 00000000000..ab46ea1551e
--- /dev/null
+++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/FeedDependenciesComponentUuidsTest.java
@@ -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
index 00000000000..fc8040f2c72
--- /dev/null
+++ b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v52/FeedDependenciesComponentUuidsTest/migrate-result.xml
@@ -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
index 00000000000..f8d460c2c15
--- /dev/null
+++ b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v52/FeedDependenciesComponentUuidsTest/migrate.xml
@@ -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
index 00000000000..65df42f527c
--- /dev/null
+++ b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v52/FeedDependenciesComponentUuidsTest/not_migrate_already_migrated_data.xml
@@ -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
index 00000000000..9dbb6c37af4
--- /dev/null
+++ b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v52/FeedDependenciesComponentUuidsTest/schema.sql
@@ -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
index 00000000000..742920ffe66
--- /dev/null
+++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/910_feed_dependencies_component_uuids.rb
@@ -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
diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java b/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java
index 59a46e128ea..87410d7a8cb 100644
--- a/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java
+++ b/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java
@@ -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
diff --git a/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql b/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql
index 17bda5bde4b..1f19a2ff695 100644
--- a/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql
+++ b/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql
@@ -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;