diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2015-04-20 12:42:47 +0200 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@sonarsource.com> | 2015-04-21 17:34:05 +0200 |
commit | acd4f5782083ad1efcc6ed8850c9d1fab9269291 (patch) | |
tree | 2b1b8e80eb5ced6fdcd1c2d731c464564b05884c /server | |
parent | cf172b28653ef2fb75a7b2c30acadac4dad6ee33 (diff) | |
download | sonarqube-acd4f5782083ad1efcc6ed8850c9d1fab9269291.tar.gz sonarqube-acd4f5782083ad1efcc6ed8850c9d1fab9269291.zip |
SONAR-6256 Add migration to add dependencies.from_component_uuid and dependencies.to_component_uuid
Diffstat (limited to 'server')
5 files changed, 164 insertions, 1 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 2944902fe34..9b4de177310 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 @@ -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 index 00000000000..276cc572ab9 --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v52/AddDependenciesComponentUuidColumns.java @@ -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 index 00000000000..99e041a75b1 --- /dev/null +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/AddDependenciesComponentUuidColumnsTest.java @@ -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 index 00000000000..c750b153af3 --- /dev/null +++ b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v52/AddDependenciesComponentUuidColumnsTest/schema.sql @@ -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 index 00000000000..3823386ce28 --- /dev/null +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/909_add_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 AddDependenciesComponentUuids < ActiveRecord::Migration + + def self.up + execute_java_migration('org.sonar.server.db.migrations.v52.AddDependenciesComponentUuidColumns') + end + +end |