From: Julien Lancelot Date: Mon, 20 Apr 2015 13:38:08 +0000 (+0200) Subject: SONAR-6256 Add migration to feed dependencies.from_component_uuid and dependencies... X-Git-Tag: 5.2-RC1~2164 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=c83af35f044f23b698ba23dca7097546b1eb2a13;p=sonarqube.git SONAR-6256 Add migration to feed dependencies.from_component_uuid and dependencies.to_component_uuid --- 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 @@ + + + + + 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 @@ + + + + + + + + + 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 @@ + + + + + + + + + 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;