aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2015-04-21 17:30:16 +0200
committerJulien Lancelot <julien.lancelot@sonarsource.com>2015-04-21 17:34:06 +0200
commite58da285fd128f71ad8ac8c4a31890a25d64bc36 (patch)
treebdf75aad7cc9892804b1eadb6ffa8b9541a6344d /server
parentc83af35f044f23b698ba23dca7097546b1eb2a13 (diff)
downloadsonarqube-e58da285fd128f71ad8ac8c4a31890a25d64bc36.tar.gz
sonarqube-e58da285fd128f71ad8ac8c4a31890a25d64bc36.zip
SONAR-6256 Drop dependencies.from_resource_id and dependencies.to_resource_id
Diffstat (limited to 'server')
-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/AddDependenciesComponentUuidColumns.java6
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/db/migrations/v52/DropDependenciesComponentColumns.java55
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/DropDependenciesComponentColumnsTest.java52
-rw-r--r--server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/dependency_tree_controller.rb2
-rw-r--r--server/sonar-web/src/main/webapp/WEB-INF/app/models/dependency.rb4
-rw-r--r--server/sonar-web/src/main/webapp/WEB-INF/db/migrate/911_remove_dependencies_component_ids.rb31
7 files changed, 148 insertions, 6 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 127709ccafd..2da008de6de 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.DropDependenciesComponentColumns;
import org.sonar.server.db.migrations.v52.FeedDependenciesComponentUuids;
import org.sonar.server.db.migrations.v52.FeedEventsComponentUuid;
import org.sonar.server.db.migrations.v52.FeedProjectLinksComponentUuid;
@@ -139,6 +140,7 @@ public interface MigrationSteps {
FeedEventsComponentUuid.class,
MoveProjectProfileAssociation.class,
AddDependenciesComponentUuidColumns.class,
- FeedDependenciesComponentUuids.class
+ FeedDependenciesComponentUuids.class,
+ DropDependenciesComponentColumns.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
index 276cc572ab9..e4f6d31c061 100644
--- 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
@@ -26,6 +26,8 @@ import org.sonar.server.db.migrations.DdlChange;
import java.sql.SQLException;
+import static org.sonar.server.db.migrations.AddColumnsBuilder.ColumnDef.Type.STRING;
+
/**
* Add the following columns to the dependencies table :
* - from_component_uuid
@@ -50,14 +52,14 @@ public class AddDependenciesComponentUuidColumns extends DdlChange {
.addColumn(
new AddColumnsBuilder.ColumnDef()
.setName("from_component_uuid")
- .setType(AddColumnsBuilder.ColumnDef.Type.STRING)
+ .setType(STRING)
.setLimit(50)
.setNullable(true)
)
.addColumn(
new AddColumnsBuilder.ColumnDef()
.setName("to_component_uuid")
- .setType(AddColumnsBuilder.ColumnDef.Type.STRING)
+ .setType(STRING)
.setLimit(50)
.setNullable(true)
)
diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v52/DropDependenciesComponentColumns.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v52/DropDependenciesComponentColumns.java
new file mode 100644
index 00000000000..973d38aa53e
--- /dev/null
+++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v52/DropDependenciesComponentColumns.java
@@ -0,0 +1,55 @@
+/*
+ * 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 com.google.common.annotations.VisibleForTesting;
+import org.sonar.core.persistence.Database;
+import org.sonar.server.db.migrations.DdlChange;
+import org.sonar.server.db.migrations.DropColumnsBuilder;
+
+import java.sql.SQLException;
+
+/**
+ * Remove the following columns from the dependencies table :
+ * - from_resource_id
+ * - to_resource_id
+ */
+public class DropDependenciesComponentColumns extends DdlChange {
+
+ private final Database db;
+
+ public DropDependenciesComponentColumns(Database db) {
+ super(db);
+ this.db = db;
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(generateSql());
+ }
+
+ @VisibleForTesting
+ String generateSql() {
+ return new DropColumnsBuilder(db.getDialect(), "dependencies", "from_resource_id", "to_resource_id")
+ .build();
+ }
+
+}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/DropDependenciesComponentColumnsTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/DropDependenciesComponentColumnsTest.java
new file mode 100644
index 00000000000..3147195b99c
--- /dev/null
+++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/DropDependenciesComponentColumnsTest.java
@@ -0,0 +1,52 @@
+/*
+ * 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.Test;
+import org.sonar.core.persistence.Database;
+import org.sonar.core.persistence.dialect.PostgreSql;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class DropDependenciesComponentColumnsTest {
+
+ DropDependenciesComponentColumns migration;
+
+ Database database;
+
+ @Before
+ public void setUp() throws Exception {
+ database = mock(Database.class);
+ migration = new DropDependenciesComponentColumns(database);
+ }
+
+ @Test
+ public void generate_sql_on_postgresql() throws Exception {
+ when(database.getDialect()).thenReturn(new PostgreSql());
+ assertThat(migration.generateSql()).isEqualTo(
+ "ALTER TABLE dependencies DROP COLUMN from_resource_id, DROP COLUMN to_resource_id"
+ );
+ }
+
+}
diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/dependency_tree_controller.rb b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/dependency_tree_controller.rb
index 0d93e544c18..12222ce82fc 100644
--- a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/dependency_tree_controller.rb
+++ b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/dependency_tree_controller.rb
@@ -66,7 +66,7 @@ class Api::DependencyTreeController < Api::ApiController
dependencies.each do |dep|
hash={
:did => dep.id.to_s,
- :rid => dep.to_resource_id.to_s,
+ :rid => dep.to.id.to_s,
:w => dep.weight,
:u => dep.usage,
:s => dep.to_scope,
diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/models/dependency.rb b/server/sonar-web/src/main/webapp/WEB-INF/app/models/dependency.rb
index c6ff4617d0f..7505640f1ca 100644
--- a/server/sonar-web/src/main/webapp/WEB-INF/app/models/dependency.rb
+++ b/server/sonar-web/src/main/webapp/WEB-INF/app/models/dependency.rb
@@ -18,10 +18,10 @@
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
class Dependency < ActiveRecord::Base
- belongs_to :from, :class_name => 'Project', :foreign_key => 'from_resource_id'
+ belongs_to :from, :class_name => 'Project', :foreign_key => 'from_component_uuid', :primary_key => 'uuid'
belongs_to :from_snapshot, :class_name => 'Snapshot', :foreign_key => 'from_snapshot_id'
- belongs_to :to, :class_name => 'Project', :foreign_key => 'to_resource_id'
+ belongs_to :to, :class_name => 'Project', :foreign_key => 'to_component_uuid', :primary_key => 'uuid'
belongs_to :to_snapshot, :class_name => 'Snapshot', :foreign_key => 'to_snapshot_id'
belongs_to :project, :class_name => 'Project', :foreign_key => 'project_id'
diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/911_remove_dependencies_component_ids.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/911_remove_dependencies_component_ids.rb
new file mode 100644
index 00000000000..623c6e36709
--- /dev/null
+++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/911_remove_dependencies_component_ids.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 RemoveDependenciesComponentIds < ActiveRecord::Migration
+
+ def self.up
+ execute_java_migration('org.sonar.server.db.migrations.v52.DropDependenciesComponentColumns')
+ end
+
+end