]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-10134 Remove unique index on QUALITY_GATES.NAME
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Mon, 4 Dec 2017 09:19:58 +0000 (10:19 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 14 Dec 2017 16:03:35 +0000 (17:03 +0100)
As quality gates are now associated to organization, it should be possible to use the same name in different organizations

server/sonar-db-core/src/main/resources/org/sonar/db/version/schema-h2.ddl
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v70/DbVersion70.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v70/DropUniqueIndexOnQualityGatesName.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v70/DbVersion70Test.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v70/DropUniqueIndexOnQualityGatesNameTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v70/DropUniqueIndexOnQualityGatesNameTest/quality_gates.sql [new file with mode: 0644]

index 1b1db706784d856e1146cb5f5bd917c76e1ee4cc..a70eeaa3e1e79419f61fd90accd6fc7ba527385f 100644 (file)
@@ -235,7 +235,6 @@ CREATE TABLE "QUALITY_GATES" (
   "CREATED_AT" TIMESTAMP,
   "UPDATED_AT" TIMESTAMP,
 );
-CREATE UNIQUE INDEX "UNIQ_QUALITY_GATES" ON "QUALITY_GATES" ("NAME");
 CREATE UNIQUE INDEX "UNIQ_QUALITY_GATES_UUID" ON "QUALITY_GATES" ("UUID");
 
 
index f11b627b5d4973d3f14cf20408e3a5cd286fa8ca..2b86136c4cf50f3c5ab3cd4e9f4f10e83223869b 100644 (file)
@@ -19,7 +19,6 @@
  */
 package org.sonar.server.platform.db.migration.version.v70;
 
-import java.util.UUID;
 import org.sonar.server.platform.db.migration.step.MigrationStepRegistry;
 import org.sonar.server.platform.db.migration.version.DbVersion;
 
@@ -43,6 +42,7 @@ public class DbVersion70 implements DbVersion {
       .add(1912, "Create QUALITY_GATES.UUID", AddUuidToQualityGates.class)
       .add(1913, "Populate QUALITY_GATES.UUID", PopulateUuidOnQualityGates.class)
       .add(1914, "Make QUALITY_GATES.UUID not nullable", MakeUuidNotNullableOnQualityGates.class)
+      .add(1915, "Drop unique index on QUALITY_GATES.NAME", DropUniqueIndexOnQualityGatesName.class)
     ;
   }
 }
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v70/DropUniqueIndexOnQualityGatesName.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v70/DropUniqueIndexOnQualityGatesName.java
new file mode 100644 (file)
index 0000000..b9b1134
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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.platform.db.migration.version.v70;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.DropIndexBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+public class DropUniqueIndexOnQualityGatesName extends DdlChange {
+
+  public DropUniqueIndexOnQualityGatesName(Database db) {
+    super(db);
+  }
+
+  @Override
+  public void execute(Context context) throws SQLException {
+    context.execute(new DropIndexBuilder(getDialect())
+      .setTable("quality_gates")
+      .setName("uniq_quality_gates")
+      .build());
+  }
+}
index 3ad5338b4e6774e584f676150fece0f41a10f475..ef2fe5a9b1b5ecbe2f27c974742f9bd56422fe16 100644 (file)
@@ -35,7 +35,7 @@ public class DbVersion70Test {
 
   @Test
   public void verify_migration_count() {
-    verifyMigrationCount(underTest, 15);
+    verifyMigrationCount(underTest, 16);
   }
 
 }
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v70/DropUniqueIndexOnQualityGatesNameTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v70/DropUniqueIndexOnQualityGatesNameTest.java
new file mode 100644 (file)
index 0000000..64ec99b
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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.platform.db.migration.version.v70;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.sonar.db.CoreDbTester;
+
+public class DropUniqueIndexOnQualityGatesNameTest {
+
+  @Rule
+  public final CoreDbTester dbTester = CoreDbTester.createForSchema(DropUniqueIndexOnQualityGatesNameTest.class, "quality_gates.sql");
+
+  @Rule
+  public ExpectedException expectedException = ExpectedException.none();
+
+  private DropUniqueIndexOnQualityGatesName underTest = new DropUniqueIndexOnQualityGatesName(dbTester.database());
+
+  @Test
+  public void unique_index_on_name_is_removed() throws SQLException {
+    underTest.execute();
+
+    dbTester.assertIndexDoesNotExist("quality_gates", "uniq_quality_gates");
+  }
+
+  @Test
+  public void migration_is_reentrant() throws SQLException {
+    underTest.execute();
+
+    underTest.execute();
+  }
+}
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v70/DropUniqueIndexOnQualityGatesNameTest/quality_gates.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v70/DropUniqueIndexOnQualityGatesNameTest/quality_gates.sql
new file mode 100644 (file)
index 0000000..a3af576
--- /dev/null
@@ -0,0 +1,10 @@
+CREATE TABLE "QUALITY_GATES" (
+  "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
+  "UUID" VARCHAR(40) NOT NULL,
+  "NAME" VARCHAR(100) NOT NULL,
+  "IS_BUILT_IN" BOOLEAN NOT NULL,
+  "CREATED_AT" TIMESTAMP,
+  "UPDATED_AT" TIMESTAMP,
+);
+CREATE UNIQUE INDEX "UNIQ_QUALITY_GATES" ON "QUALITY_GATES" ("NAME");
+CREATE UNIQUE INDEX "UNIQ_QUALITY_GATES_UUID" ON "QUALITY_GATES" ("UUID");
\ No newline at end of file