]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-13221 change PK of ce_queue
authorPierre <pierre.guillot@sonarsource.com>
Wed, 15 Apr 2020 09:31:11 +0000 (11:31 +0200)
committersonartech <sonartech@sonarsource.com>
Mon, 25 May 2020 20:05:18 +0000 (20:05 +0000)
15 files changed:
server/sonar-db-dao/src/main/resources/org/sonar/db/ce/CeQueueMapper.xml
server/sonar-db-dao/src/schema/schema-sq.ddl
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/DbVersion83.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/cequeue/AddPrimaryKeyOnUuidColumnOfCeQueueTable.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/cequeue/DropIdColumnOfCeQueueTable.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/cequeue/DropPrimaryKeyOnIdColumnOfCeQueueTable.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/cequeue/DropUniqueIndexOnUuidColumnOfCeQueueTable.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/cequeue/AddPrimaryKeyOnUuidColumnOfCeQueueTableTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/cequeue/DropIdColumnOfCeQueueTableTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/cequeue/DropPrimaryKeyOnIdColumnOfCeQueueTableTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/cequeue/DropUniqueIndexOnUuidColumnOfCeQueueTableTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/cequeue/AddPrimaryKeyOnUuidColumnOfCeQueueTableTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/cequeue/DropIdColumnOfCeQueueTableTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/cequeue/DropPrimaryKeyOnIdColumnOfCeQueueTableTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/cequeue/DropUniqueIndexOnUuidColumnOfCeQueueTableTest/schema.sql [new file with mode: 0644]

index a55ec38c2f144e1ea3d057c7a0a4085599066b0c..fbf2d11dbee10b6819c591aab57ddd37a9f93ab5 100644 (file)
     cq.updated_at as updatedAt
   </sql>
 
-  <sql id="orderByDateAndId">
+  <sql id="orderByDateAndUuid">
     order by
       cq.created_at asc,
-      cq.id asc
+      cq.uuid asc
   </sql>
 
-  <sql id="orderByDescDateAndId">
+  <sql id="orderByDescDateAndUuid">
     order by
       cq.created_at desc,
-      cq.id desc
+      cq.uuid desc
   </sql>
 
   <select id="selectByUuid" parameterType="String" resultType="org.sonar.db.ce.CeQueueDto">
@@ -90,7 +90,7 @@
       ce_queue cq
     where
       cq.main_component_uuid=#{mainComponentUuid,jdbcType=VARCHAR}
-    <include refid="orderByDateAndId"/>
+    <include refid="orderByDateAndUuid"/>
   </select>
 
   <select id="selectAllInAscOrder" resultType="org.sonar.db.ce.CeQueueDto">
       <include refid="columns"/>
     from
       ce_queue cq
-    <include refid="orderByDateAndId"/>
+    <include refid="orderByDateAndUuid"/>
   </select>
 
   <select id="selectByQueryInDescOrder" resultType="org.sonar.db.ce.CeQueueDto">
     select
     <include refid="columns"/>
     <include refid="sqlSelectByQuery"/>
-    <include refid="orderByDescDateAndId"/>
+    <include refid="orderByDescDateAndUuid"/>
   </select>
 
   <select id="countByQuery" resultType="int">
 
   <sql id="columnsSelectEligibleForPeek">
     cq.uuid as "uuid",
-    cq.created_at as "created_at",
-    cq.id as "id"
+    cq.created_at as "created_at"
   </sql>
 
   <sql id="sqlSelectEligibleForPeek">
   <sql id="orderBySelectEligibleForPeek">
     order by
       created_at asc,
-      id asc
+      uuid asc
   </sql>
 
   <select id="selectPending" resultType="org.sonar.db.ce.CeQueueDto">
index 1ed5568680ba2f49e2dacf9fb6a4c3b338ab786e..d3fa90d0036e431521b2ed1b14af8c312d8c823c 100644 (file)
@@ -122,7 +122,6 @@ CREATE INDEX "CE_ACTIVITY_MAIN_ISLAST_KEY" ON "CE_ACTIVITY"("MAIN_IS_LAST_KEY");
 CREATE UNIQUE INDEX "CE_ACTIVITY_UUID" ON "CE_ACTIVITY"("UUID");
 
 CREATE TABLE "CE_QUEUE"(
-    "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
     "UUID" VARCHAR(40) NOT NULL,
     "TASK_TYPE" VARCHAR(15) NOT NULL,
     "MAIN_COMPONENT_UUID" VARCHAR(40),
@@ -135,10 +134,9 @@ CREATE TABLE "CE_QUEUE"(
     "CREATED_AT" BIGINT NOT NULL,
     "UPDATED_AT" BIGINT NOT NULL
 );
-ALTER TABLE "CE_QUEUE" ADD CONSTRAINT "PK_CE_QUEUE" PRIMARY KEY("ID");
+ALTER TABLE "CE_QUEUE" ADD CONSTRAINT "PK_CE_QUEUE" PRIMARY KEY("UUID");
 CREATE INDEX "CE_QUEUE_MAIN_COMPONENT" ON "CE_QUEUE"("MAIN_COMPONENT_UUID");
 CREATE INDEX "CE_QUEUE_COMPONENT" ON "CE_QUEUE"("COMPONENT_UUID");
-CREATE UNIQUE INDEX "CE_QUEUE_UUID" ON "CE_QUEUE"("UUID");
 
 CREATE TABLE "CE_SCANNER_CONTEXT"(
     "TASK_UUID" VARCHAR(40) NOT NULL,
index e5b9a03f46a519221cf7059566a706cbfff80bba..90659d93d7611dd6aeb2f82532474ac68914d5e1 100644 (file)
@@ -21,6 +21,10 @@ package org.sonar.server.platform.db.migration.version.v83;
 
 import org.sonar.server.platform.db.migration.step.MigrationStepRegistry;
 import org.sonar.server.platform.db.migration.version.DbVersion;
+import org.sonar.server.platform.db.migration.version.v83.cequeue.AddPrimaryKeyOnUuidColumnOfCeQueueTable;
+import org.sonar.server.platform.db.migration.version.v83.cequeue.DropIdColumnOfCeQueueTable;
+import org.sonar.server.platform.db.migration.version.v83.cequeue.DropPrimaryKeyOnIdColumnOfCeQueueTable;
+import org.sonar.server.platform.db.migration.version.v83.cequeue.DropUniqueIndexOnUuidColumnOfCeQueueTable;
 import org.sonar.server.platform.db.migration.version.v83.events.AddPrimaryKeyOnUuidColumnOfEventsTable;
 import org.sonar.server.platform.db.migration.version.v83.events.DropIdColumnOfEventsTable;
 import org.sonar.server.platform.db.migration.version.v83.events.DropPrimaryKeyOnIdColumnOfEventsTable;
@@ -77,6 +81,12 @@ public class DbVersion83 implements DbVersion {
       .add(3413, "Add primary key on 'UUID' column of 'SNAPSHOTS' table", AddPrimaryKeyOnUuidColumnOfSnapshotsTable.class)
       .add(3414, "Drop column 'ID' of 'SNAPSHOTS' table", DropIdColumnOfSnapshotsTable.class)
 
+      // Migration on ce_queue table
+      .add(3415, "Drop unique index on 'uuid' column of 'CE_QUEUE' table", DropUniqueIndexOnUuidColumnOfCeQueueTable.class)
+      .add(3416, "Drop primary key on 'ID' column of 'CE_QUEUE' table", DropPrimaryKeyOnIdColumnOfCeQueueTable.class)
+      .add(3417, "Add primary key on 'UUID' column of 'CE_QUEUE' table", AddPrimaryKeyOnUuidColumnOfCeQueueTable.class)
+      .add(3418, "Drop column 'ID' of 'CE_QUEUE' table", DropIdColumnOfCeQueueTable.class)
+
     ;
   }
 }
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/cequeue/AddPrimaryKeyOnUuidColumnOfCeQueueTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/cequeue/AddPrimaryKeyOnUuidColumnOfCeQueueTable.java
new file mode 100644 (file)
index 0000000..245c6b9
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.cequeue;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+import org.sonar.server.platform.db.migration.version.v83.util.AddPrimaryKeyBuilder;
+
+public class AddPrimaryKeyOnUuidColumnOfCeQueueTable extends DdlChange {
+
+  public AddPrimaryKeyOnUuidColumnOfCeQueueTable(Database db) {
+    super(db);
+  }
+
+  @Override
+  public void execute(Context context) throws SQLException {
+    context.execute(new AddPrimaryKeyBuilder("ce_queue", "uuid").build());
+  }
+
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/cequeue/DropIdColumnOfCeQueueTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/cequeue/DropIdColumnOfCeQueueTable.java
new file mode 100644 (file)
index 0000000..95dac82
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.cequeue;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.DropColumnsBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+public class DropIdColumnOfCeQueueTable extends DdlChange {
+
+  private Database db;
+
+  public DropIdColumnOfCeQueueTable(Database db) {
+    super(db);
+    this.db = db;
+  }
+
+  @Override
+  public void execute(Context context) throws SQLException {
+    context.execute(new DropColumnsBuilder(db.getDialect(), "ce_queue", "id").build());
+  }
+
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/cequeue/DropPrimaryKeyOnIdColumnOfCeQueueTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/cequeue/DropPrimaryKeyOnIdColumnOfCeQueueTable.java
new file mode 100644 (file)
index 0000000..4e2a02c
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.cequeue;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+import org.sonar.server.platform.db.migration.version.v83.util.DropPrimaryKeySqlGenerator;
+
+public class DropPrimaryKeyOnIdColumnOfCeQueueTable extends DdlChange {
+
+  private final DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator;
+
+  public DropPrimaryKeyOnIdColumnOfCeQueueTable(Database db, DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator) {
+    super(db);
+    this.dropPrimaryKeySqlGenerator = dropPrimaryKeySqlGenerator;
+  }
+
+  @Override
+  public void execute(Context context) throws SQLException {
+    context.execute(dropPrimaryKeySqlGenerator.generate("ce_queue", "ce_queue","id"));
+  }
+
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/cequeue/DropUniqueIndexOnUuidColumnOfCeQueueTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/cequeue/DropUniqueIndexOnUuidColumnOfCeQueueTable.java
new file mode 100644 (file)
index 0000000..d006e15
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.cequeue;
+
+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 DropUniqueIndexOnUuidColumnOfCeQueueTable extends DdlChange {
+
+  public DropUniqueIndexOnUuidColumnOfCeQueueTable(Database db) {
+    super(db);
+  }
+
+  @Override
+  public void execute(Context context) throws SQLException {
+    context.execute(new DropIndexBuilder(getDialect())
+      .setTable("ce_queue")
+      .setName("ce_queue_uuid")
+      .build());
+  }
+
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/cequeue/AddPrimaryKeyOnUuidColumnOfCeQueueTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/cequeue/AddPrimaryKeyOnUuidColumnOfCeQueueTableTest.java
new file mode 100644 (file)
index 0000000..f0833b7
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.cequeue;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.MigrationStep;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+public class AddPrimaryKeyOnUuidColumnOfCeQueueTableTest {
+
+  @Rule
+  public CoreDbTester db = CoreDbTester.createForSchema(AddPrimaryKeyOnUuidColumnOfCeQueueTableTest.class, "schema.sql");
+
+  private MigrationStep underTest = new AddPrimaryKeyOnUuidColumnOfCeQueueTable(db.database());
+
+  @Test
+  public void execute() throws SQLException {
+    underTest.execute();
+
+    db.assertPrimaryKey("ce_queue", "pk_ce_queue", "uuid");
+  }
+
+  @Test
+  public void migration_is_not_re_entrant() throws SQLException {
+    underTest.execute();
+
+    assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class);
+  }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/cequeue/DropIdColumnOfCeQueueTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/cequeue/DropIdColumnOfCeQueueTableTest.java
new file mode 100644 (file)
index 0000000..ca48e9b
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.cequeue;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.MigrationStep;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+public class DropIdColumnOfCeQueueTableTest {
+
+  @Rule
+  public CoreDbTester db = CoreDbTester.createForSchema(DropIdColumnOfCeQueueTableTest.class, "schema.sql");
+
+  private MigrationStep underTest = new DropIdColumnOfCeQueueTable(db.database());
+
+  @Test
+  public void execute() throws SQLException {
+    underTest.execute();
+
+    db.assertColumnDoesNotExist("ce_queue", "id");
+  }
+
+  @Test
+  public void migration_is_not_re_entrant() throws SQLException {
+    underTest.execute();
+
+    assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class);
+  }
+
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/cequeue/DropPrimaryKeyOnIdColumnOfCeQueueTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/cequeue/DropPrimaryKeyOnIdColumnOfCeQueueTableTest.java
new file mode 100644 (file)
index 0000000..d48c130
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.cequeue;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.MigrationStep;
+import org.sonar.server.platform.db.migration.version.v83.util.DropPrimaryKeySqlGenerator;
+import org.sonar.server.platform.db.migration.version.v83.util.GetConstraintHelper;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+public class DropPrimaryKeyOnIdColumnOfCeQueueTableTest {
+
+  private static final String TABLE_NAME = "ce_queue";
+  @Rule
+  public CoreDbTester db = CoreDbTester.createForSchema(DropPrimaryKeyOnIdColumnOfCeQueueTableTest.class, "schema.sql");
+
+  private DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new GetConstraintHelper(db.database()));
+
+  private MigrationStep underTest = new DropPrimaryKeyOnIdColumnOfCeQueueTable(db.database(), dropPrimaryKeySqlGenerator);
+
+  @Test
+  public void execute() throws SQLException {
+    underTest.execute();
+
+    db.assertNoPrimaryKey(TABLE_NAME);
+  }
+
+  @Test
+  public void migration_is_not_re_entrant() throws SQLException {
+    underTest.execute();
+
+    assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class);
+  }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/cequeue/DropUniqueIndexOnUuidColumnOfCeQueueTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/cequeue/DropUniqueIndexOnUuidColumnOfCeQueueTableTest.java
new file mode 100644 (file)
index 0000000..8c5aba9
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v83.cequeue;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.MigrationStep;
+
+public class DropUniqueIndexOnUuidColumnOfCeQueueTableTest {
+
+  @Rule
+  public CoreDbTester db = CoreDbTester.createForSchema(DropUniqueIndexOnUuidColumnOfCeQueueTableTest.class, "schema.sql");
+
+  private MigrationStep underTest = new DropUniqueIndexOnUuidColumnOfCeQueueTable(db.database());
+
+  @Test
+  public void execute_drop_index() throws SQLException {
+    db.assertUniqueIndex("ce_queue", "ce_queue_uuid", "uuid");
+
+    underTest.execute();
+
+    db.assertIndexDoesNotExist("ce_queue", "ce_queue_uuid");
+  }
+
+}
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/cequeue/AddPrimaryKeyOnUuidColumnOfCeQueueTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/cequeue/AddPrimaryKeyOnUuidColumnOfCeQueueTableTest/schema.sql
new file mode 100644 (file)
index 0000000..bf5f23f
--- /dev/null
@@ -0,0 +1,16 @@
+CREATE TABLE "CE_QUEUE"(
+    "ID" INTEGER NOT NULL,
+    "UUID" VARCHAR(40) NOT NULL,
+    "TASK_TYPE" VARCHAR(15) NOT NULL,
+    "MAIN_COMPONENT_UUID" VARCHAR(40),
+    "COMPONENT_UUID" VARCHAR(40),
+    "STATUS" VARCHAR(15),
+    "SUBMITTER_UUID" VARCHAR(255),
+    "STARTED_AT" BIGINT,
+    "WORKER_UUID" VARCHAR(40),
+    "EXECUTION_COUNT" INTEGER NOT NULL,
+    "CREATED_AT" BIGINT NOT NULL,
+    "UPDATED_AT" BIGINT NOT NULL
+);
+CREATE INDEX "CE_QUEUE_MAIN_COMPONENT" ON "CE_QUEUE"("MAIN_COMPONENT_UUID");
+CREATE INDEX "CE_QUEUE_COMPONENT" ON "CE_QUEUE"("COMPONENT_UUID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/cequeue/DropIdColumnOfCeQueueTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/cequeue/DropIdColumnOfCeQueueTableTest/schema.sql
new file mode 100644 (file)
index 0000000..48cfeb2
--- /dev/null
@@ -0,0 +1,17 @@
+CREATE TABLE "CE_QUEUE"(
+    "ID" INTEGER NOT NULL,
+    "UUID" VARCHAR(40) NOT NULL,
+    "TASK_TYPE" VARCHAR(15) NOT NULL,
+    "MAIN_COMPONENT_UUID" VARCHAR(40),
+    "COMPONENT_UUID" VARCHAR(40),
+    "STATUS" VARCHAR(15),
+    "SUBMITTER_UUID" VARCHAR(255),
+    "STARTED_AT" BIGINT,
+    "WORKER_UUID" VARCHAR(40),
+    "EXECUTION_COUNT" INTEGER NOT NULL,
+    "CREATED_AT" BIGINT NOT NULL,
+    "UPDATED_AT" BIGINT NOT NULL
+);
+ALTER TABLE "CE_QUEUE" ADD CONSTRAINT "PK_CE_QUEUE" PRIMARY KEY("UUID");
+CREATE INDEX "CE_QUEUE_MAIN_COMPONENT" ON "CE_QUEUE"("MAIN_COMPONENT_UUID");
+CREATE INDEX "CE_QUEUE_COMPONENT" ON "CE_QUEUE"("COMPONENT_UUID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/cequeue/DropPrimaryKeyOnIdColumnOfCeQueueTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/cequeue/DropPrimaryKeyOnIdColumnOfCeQueueTableTest/schema.sql
new file mode 100644 (file)
index 0000000..ca17310
--- /dev/null
@@ -0,0 +1,17 @@
+CREATE TABLE "CE_QUEUE"(
+    "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+    "UUID" VARCHAR(40) NOT NULL,
+    "TASK_TYPE" VARCHAR(15) NOT NULL,
+    "MAIN_COMPONENT_UUID" VARCHAR(40),
+    "COMPONENT_UUID" VARCHAR(40),
+    "STATUS" VARCHAR(15),
+    "SUBMITTER_UUID" VARCHAR(255),
+    "STARTED_AT" BIGINT,
+    "WORKER_UUID" VARCHAR(40),
+    "EXECUTION_COUNT" INTEGER NOT NULL,
+    "CREATED_AT" BIGINT NOT NULL,
+    "UPDATED_AT" BIGINT NOT NULL
+);
+ALTER TABLE "CE_QUEUE" ADD CONSTRAINT "PK_CE_QUEUE" PRIMARY KEY("ID");
+CREATE INDEX "CE_QUEUE_MAIN_COMPONENT" ON "CE_QUEUE"("MAIN_COMPONENT_UUID");
+CREATE INDEX "CE_QUEUE_COMPONENT" ON "CE_QUEUE"("COMPONENT_UUID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/cequeue/DropUniqueIndexOnUuidColumnOfCeQueueTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/cequeue/DropUniqueIndexOnUuidColumnOfCeQueueTableTest/schema.sql
new file mode 100644 (file)
index 0000000..8ab0a11
--- /dev/null
@@ -0,0 +1,18 @@
+CREATE TABLE "CE_QUEUE"(
+    "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+    "UUID" VARCHAR(40) NOT NULL,
+    "TASK_TYPE" VARCHAR(15) NOT NULL,
+    "MAIN_COMPONENT_UUID" VARCHAR(40),
+    "COMPONENT_UUID" VARCHAR(40),
+    "STATUS" VARCHAR(15),
+    "SUBMITTER_UUID" VARCHAR(255),
+    "STARTED_AT" BIGINT,
+    "WORKER_UUID" VARCHAR(40),
+    "EXECUTION_COUNT" INTEGER NOT NULL,
+    "CREATED_AT" BIGINT NOT NULL,
+    "UPDATED_AT" BIGINT NOT NULL
+);
+ALTER TABLE "CE_QUEUE" ADD CONSTRAINT "PK_CE_QUEUE" PRIMARY KEY("ID");
+CREATE INDEX "CE_QUEUE_MAIN_COMPONENT" ON "CE_QUEUE"("MAIN_COMPONENT_UUID");
+CREATE INDEX "CE_QUEUE_COMPONENT" ON "CE_QUEUE"("COMPONENT_UUID");
+CREATE UNIQUE INDEX "CE_QUEUE_UUID" ON "CE_QUEUE"("UUID");