]> source.dussan.org Git - sonarqube.git/commitdiff
Optimize database migrations
authorDuarte Meneses <duarte.meneses@sonarsource.com>
Thu, 11 Jun 2020 15:46:57 +0000 (10:46 -0500)
committersonartech <sonartech@sonarsource.com>
Tue, 23 Jun 2020 20:04:36 +0000 (20:04 +0000)
105 files changed:
server/sonar-db-dao/src/schema/schema-sq.ddl
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/sql/CreateIndexBuilder.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/sql/CreateTableAsBuilder.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/sql/RenameTableBuilder.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/DbVersion84.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/AddIndexOnIssueKeyOfIssueChangesTable.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/AddIndexOnKeeOfIssueChangesTable.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/AddUuidColumnToIssueChangesTable.java [deleted file]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/CopyIssueChangesTable.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/DropIdColumnOfIssueChangesTable.java [deleted file]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/DropIssueChangesTable.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/DropPrimaryKeyOnIdColumnOfIssueChangesTable.java [deleted file]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/MakeIssueChangesUuidColumnNotNullable.java [deleted file]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/PopulateIssueChangesUuid.java [deleted file]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/RenameIssueChangesCopyToIssueChanges.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/issues/AddPrimaryKeyOnKeeColumnOfIssuesTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/issues/DropIdColumnOfIssuesTable.java [deleted file]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/issues/DropPrimaryKeyOnIdColumnOfIssuesTable.java [deleted file]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/metrics/PopulateMetricsUuid.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/AddIndexOnProjectUuidOfLiveMeasuresTable.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/AddMetricUuidColumnToLiveMeasures.java [deleted file]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/AddPKeyOnUuidOfLiveMeasuresTable.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/CopyLiveMeasuresTable.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/DropIndexOnMetricIdOfLiveMeasuresTable.java [deleted file]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/DropLiveMeasuresTable.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/DropMetricIdColumnOfLiveMeasuresTable.java [deleted file]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/MakeLiveMeasuresMetricUuidNotNullable.java [deleted file]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/PopulateLiveMeasuresMetricUuid.java [deleted file]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/RenameLiveMeasuresCopyToLiveMeasures.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rules/PopulateRulesUuid.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/AddIndexToIssuesTable.java [deleted file]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/AddIndexesToIssuesTable.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/AddRuleUuidColumnToIssuesTable.java [deleted file]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/CopyIssuesTable.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/DropIndexOnRuleIdColumnOfIssuesTable.java [deleted file]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/DropIssuesTable.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/DropRuleIdColumnOfIssuesTable.java [deleted file]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/PopulateIssuesRuleUuidColumn.java [deleted file]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/RenameIssuesCopyToIssues.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/sql/CreateIndexBuilderTest.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/sql/CreateTableAsBuilderTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/AddIndexOnIssueKeyOfIssueChangesTableTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/AddIndexOnKeeOfIssueChangesTableTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/AddUuidColumnToIssueChangesTableTest.java [deleted file]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/CopyIssueChangesTableTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/DropIdColumnOfIssueChangesTableTest.java [deleted file]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/DropIssueChangesTableTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/DropPrimaryKeyOnIdColumnOfIssueChangesTableTest.java [deleted file]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/MakeIssueChangesUuidColumnNotNullableTest.java [deleted file]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/PopulateIssueChangesUuidTest.java [deleted file]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/RenameIssueChangesCopyToIssueChangesTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/issues/DropIdColumnOfIssuesTableTest.java [deleted file]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/issues/DropPrimaryKeyOnIdColumnOfIssuesTableTest.java [deleted file]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/metrics/PopulateMetricsUuidTest.java [deleted file]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/AddIndexOnProjectUuidOfLiveMeasuresTableTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/AddMetricUuidColumnToLiveMeasuresTest.java [deleted file]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/CopyLiveMeasuresTableTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/DropIndexOnMetricIdOfLiveMeasuresTableTest.java [deleted file]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/DropLiveMeasuresTableTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/DropMetricIdColumnOfLiveMeasuresTableTest.java [deleted file]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/MakeLiveMeasuresMetricUuidNotNullableTest.java [deleted file]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/PopulateLiveMeasuresMetricUuidTest.java [deleted file]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/RenameLiveMeasuresCopyToLiveMeasuresTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/rules/PopulateRulesUuidTest.java [deleted file]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/AddIndexToIssuesTableTest.java [deleted file]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/AddIndexesToIssuesTableTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/AddRuleUuidColumnToIssuesTableTest.java [deleted file]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/CopyIssuesTableTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/DropIndexOnRuleIdColumnOfIssuesTableTest.java [deleted file]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/DropIssuesTableTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/DropRuleIdColumnOfIssuesTableTest.java [deleted file]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/PopulateIssuesRuleUuidColumnTest.java [deleted file]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/RenameIssuesCopyToIssuesTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/issuechanges/AddIndexOnIssueKeyOfIssueChangesTableTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/issuechanges/AddIndexOnKeeOfIssueChangesTableTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/issuechanges/AddPrimaryKeyOnUuidColumnOfIssueChangesTableTest/schema.sql
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/issuechanges/AddUuidColumnToIssueChangesTableTest/schema.sql [deleted file]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/issuechanges/CopyIssueChangesTableTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/issuechanges/DropIdColumnOfIssueChangesTableTest/schema.sql [deleted file]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/issuechanges/DropIssueChangesTableTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/issuechanges/DropPrimaryKeyOnIdColumnOfIssueChangesTableTest/schema.sql [deleted file]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/issuechanges/MakeIssueChangesUuidColumnNotNullableTest/schema.sql [deleted file]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/issuechanges/PopulateIssueChangesUuidTest/schema.sql [deleted file]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/issuechanges/RenameIssueChangesCopyToIssueChangesTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/issues/DropIdColumnOfIssuesTableTest/schema.sql [deleted file]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/issues/DropPrimaryKeyOnIdColumnOfIssuesTableTest/schema.sql [deleted file]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/AddIndexOnMetricUuidOfLiveMeasuresTableTest/schema.sql
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/AddIndexOnProjectUuidOfLiveMeasuresTableTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/AddMetricUuidColumnToLiveMeasuresTest/schema.sql [deleted file]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/CopyLiveMeasuresTableTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/DropIndexOnMetricIdOfLiveMeasuresTableTest/schema.sql [deleted file]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/DropLiveMeasuresTableTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/DropMetricIdColumnOfLiveMeasuresTableTest/schema.sql [deleted file]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/MakeLiveMeasuresMetricUuidNotNullableTest/schema.sql [deleted file]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/PopulateLiveMeasuresMetricUuidTest/schema.sql [deleted file]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/RenameLiveMeasuresCopyToLiveMeasuresTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/rules/issues/AddIndexToIssuesTableTest/schema.sql [deleted file]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/rules/issues/AddIndexesToIssuesTableTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/rules/issues/AddRuleUuidColumnToIssuesTableTest/schema.sql [deleted file]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/rules/issues/CopyIssuesTableTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/rules/issues/DropIndexOnRuleIdColumnOfIssuesTableTest/schema.sql [deleted file]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/rules/issues/DropIssuesTableTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/rules/issues/DropRuleIdColumnOfIssuesTableTest/schema.sql [deleted file]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/rules/issues/PopulateIssuesRuleUuidColumnTest/schema.sql [deleted file]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/rules/issues/RenameIssuesCopyToIssuesTest/schema.sql [new file with mode: 0644]

index 106647743edcd88967a5249f88e43326ff9e7941..8367ba17026196c85c1c3567a5d965d659694c27 100644 (file)
@@ -361,15 +361,15 @@ CREATE TABLE "INTERNAL_PROPERTIES"(
 ALTER TABLE "INTERNAL_PROPERTIES" ADD CONSTRAINT "PK_INTERNAL_PROPERTIES" PRIMARY KEY("KEE");
 
 CREATE TABLE "ISSUE_CHANGES"(
+    "UUID" VARCHAR(40) NOT NULL,
     "KEE" VARCHAR(50),
     "ISSUE_KEY" VARCHAR(50) NOT NULL,
     "USER_LOGIN" VARCHAR(255),
     "CHANGE_TYPE" VARCHAR(20),
-    "CHANGE_DATA" CLOB(2147483647),
+    "CHANGE_DATA" CLOB,
     "CREATED_AT" BIGINT,
     "UPDATED_AT" BIGINT,
-    "ISSUE_CHANGE_CREATION_DATE" BIGINT,
-    "UUID" VARCHAR(40) NOT NULL
+    "ISSUE_CHANGE_CREATION_DATE" BIGINT
 );
 ALTER TABLE "ISSUE_CHANGES" ADD CONSTRAINT "PK_ISSUE_CHANGES" PRIMARY KEY("UUID");
 CREATE INDEX "ISSUE_CHANGES_ISSUE_KEY" ON "ISSUE_CHANGES"("ISSUE_KEY");
@@ -377,6 +377,7 @@ CREATE INDEX "ISSUE_CHANGES_KEE" ON "ISSUE_CHANGES"("KEE");
 
 CREATE TABLE "ISSUES"(
     "KEE" VARCHAR(50) NOT NULL,
+    "RULE_UUID" VARCHAR(40),
     "SEVERITY" VARCHAR(10),
     "MANUAL_SEVERITY" BOOLEAN NOT NULL,
     "MESSAGE" VARCHAR(4000),
@@ -401,8 +402,7 @@ CREATE TABLE "ISSUES"(
     "PROJECT_UUID" VARCHAR(50),
     "LOCATIONS" BLOB,
     "ISSUE_TYPE" TINYINT,
-    "FROM_HOTSPOT" BOOLEAN,
-    "RULE_UUID" VARCHAR(40)
+    "FROM_HOTSPOT" BOOLEAN
 );
 ALTER TABLE "ISSUES" ADD CONSTRAINT "PK_ISSUES" PRIMARY KEY("KEE");
 CREATE INDEX "ISSUES_ASSIGNEE" ON "ISSUES"("ASSIGNEE");
@@ -418,14 +418,14 @@ CREATE TABLE "LIVE_MEASURES"(
     "UUID" VARCHAR(40) NOT NULL,
     "PROJECT_UUID" VARCHAR(50) NOT NULL,
     "COMPONENT_UUID" VARCHAR(50) NOT NULL,
+    "METRIC_UUID" VARCHAR(40) NOT NULL,
     "VALUE" DOUBLE,
     "TEXT_VALUE" VARCHAR(4000),
     "VARIATION" DOUBLE,
     "MEASURE_DATA" BLOB,
     "UPDATE_MARKER" VARCHAR(40),
     "CREATED_AT" BIGINT NOT NULL,
-    "UPDATED_AT" BIGINT NOT NULL,
-    "METRIC_UUID" VARCHAR(40) NOT NULL
+    "UPDATED_AT" BIGINT NOT NULL
 );
 ALTER TABLE "LIVE_MEASURES" ADD CONSTRAINT "PK_LIVE_MEASURES" PRIMARY KEY("UUID");
 CREATE INDEX "LIVE_MEASURES_PROJECT" ON "LIVE_MEASURES"("PROJECT_UUID");
index 4a73626554c3e76c4830ee8a8ff05d764c47519b..0d6e710f61928f7057e57d1e80c333cc941be866 100644 (file)
@@ -21,7 +21,6 @@ package org.sonar.server.platform.db.migration.sql;
 
 import java.util.ArrayList;
 import java.util.List;
-import java.util.stream.Collectors;
 import org.sonar.server.platform.db.migration.def.ColumnDef;
 
 import static com.google.common.base.Preconditions.checkArgument;
@@ -32,7 +31,7 @@ import static org.sonar.server.platform.db.migration.def.Validations.validateTab
 
 public class CreateIndexBuilder {
 
-  private final List<ColumnDef> columns = new ArrayList<>();
+  private final List<String> columns = new ArrayList<>();
   private String tableName;
   private String indexName;
   private boolean unique = false;
@@ -65,10 +64,19 @@ public class CreateIndexBuilder {
   /**
    * Add a column to the scope of index. Order of calls to this
    * method is important and is kept as-is when creating the index.
-   * The attributes used from {@link ColumnDef} are the name, the type
-   * and the length (in case of VARCHAR). Other attributes are ignored.
+   * The attribute used from {@link ColumnDef} is the name.
+   * Other attributes are ignored.
    */
   public CreateIndexBuilder addColumn(ColumnDef column) {
+    columns.add(requireNonNull(column, "Column cannot be null").getName());
+    return this;
+  }
+
+  /**
+   * Add a column to the scope of index. Order of calls to this
+   * method is important and is kept as-is when creating the index.
+   */
+  public CreateIndexBuilder addColumn(String column) {
     columns.add(requireNonNull(column, "Column cannot be null"));
     return this;
   }
@@ -90,7 +98,7 @@ public class CreateIndexBuilder {
     sql.append(" ON ");
     sql.append(tableName);
     sql.append(" (");
-    sql.append(columns.stream().map(ColumnDef::getName).collect(Collectors.joining(", ")));
+    sql.append(String.join(", ", columns));
     sql.append(")");
     return sql.toString();
   }
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/sql/CreateTableAsBuilder.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/sql/CreateTableAsBuilder.java
new file mode 100644 (file)
index 0000000..2adc130
--- /dev/null
@@ -0,0 +1,118 @@
+/*
+ * 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.sql;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
+import javax.annotation.Nullable;
+import org.sonar.db.dialect.Dialect;
+import org.sonar.db.dialect.MsSql;
+import org.sonar.server.platform.db.migration.def.ColumnDef;
+
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkState;
+import static java.util.Objects.requireNonNull;
+import static org.sonar.server.platform.db.migration.def.Validations.validateTableName;
+
+/**
+ * Creates a new table based on an existing table.
+ * With Oracle, H2 and PSQL it uses the 'CREATE TABLE [...] AS' statement. This is not supported in SQL Server, so we use 'SELECT [...] INTO [new_table] FROM [old_table]'.
+ * Note that indexes are not kept. Constraints are also not kept except for 'NOT NULL' in some dbs and under certain conditions. Some dbs also allow to specify 'NOT NULL'
+ * constraint or even data type when specifying the new table.
+ * For simplicity, we explicitly add NOT NULL constrains with separate statements for all DBs, since it's a fast operation.
+ */
+public class CreateTableAsBuilder {
+  private final Dialect dialect;
+  private final String tableName;
+  private final String fromTableName;
+  private List<Column> columns = new ArrayList<>();
+
+  public CreateTableAsBuilder(Dialect dialect, String tableName, String fromTableName) {
+    this.dialect = requireNonNull(dialect, "dialect can't be null");
+    this.tableName = validateTableName(tableName);
+    this.fromTableName = validateTableName(fromTableName);
+    checkArgument(!tableName.equals(fromTableName), "Table names must be different");
+  }
+
+  public CreateTableAsBuilder addColumn(ColumnDef column) {
+    columns.add(new Column(column, null));
+    return this;
+  }
+
+  public CreateTableAsBuilder addColumnWithCast(ColumnDef column, String castFrom) {
+    columns.add(new Column(column, castFrom));
+    return this;
+  }
+
+  public List<String> build() {
+    checkState(!columns.isEmpty(), "Columns need to be specified");
+
+    List<String> sql = new ArrayList<>();
+
+    String select = columns.stream().map(this::toSelect).collect(Collectors.joining(", "));
+
+    if (dialect.getId().equals(MsSql.ID)) {
+      sql.add("SELECT " + select + " INTO " + tableName + " FROM " + fromTableName);
+    } else {
+      StringBuilder sb = new StringBuilder("CREATE TABLE " + tableName + " (");
+      appendColumnNames(sb);
+      sb.append(") AS (SELECT ").append(select).append(" FROM ").append(fromTableName).append(")");
+      sql.add(sb.toString());
+    }
+
+    List<Column> notNullColumns = columns.stream().filter(c -> !c.definition().isNullable()).collect(Collectors.toList());
+    for (Column c : notNullColumns) {
+      sql.addAll(new AlterColumnsBuilder(dialect, tableName).updateColumn(c.definition()).build());
+    }
+
+    return sql;
+  }
+
+  private String toSelect(Column column) {
+    if (column.castFrom() == null) {
+      return column.definition().getName();
+    }
+    // Example: CAST (metric_id AS VARCHAR(40)) AS metric_uuid
+    return "CAST (" + column.castFrom() + " AS " + column.definition().generateSqlType(dialect) + ") AS " + column.definition().getName();
+  }
+
+  private void appendColumnNames(StringBuilder res) {
+    res.append(columns.stream().map(c -> c.definition().getName()).collect(Collectors.joining(", ")));
+  }
+
+  private static class Column {
+    private ColumnDef columnDef;
+    private String castFrom;
+
+    public Column(ColumnDef columnDef, @Nullable String castFrom) {
+      this.columnDef = columnDef;
+      this.castFrom = castFrom;
+    }
+
+    private ColumnDef definition() {
+      return columnDef;
+    }
+
+    private String castFrom() {
+      return castFrom;
+    }
+  }
+}
index a6e2453e4513b6bfe9cb892df761e4407f9b7629..c0c73e1a68ee735437cbfabc736bb51930a8b1c7 100644 (file)
@@ -81,8 +81,7 @@ public class RenameTableBuilder {
       case Oracle.ID:
         String renameSqlCommand = "RENAME " + name + " TO " + newName;
         return autoGeneratedId ? asList(
-          "DROP TRIGGER " + name + "_idt",
-            renameSqlCommand,
+          "DROP TRIGGER " + name + "_idt", renameSqlCommand,
           "RENAME " + name + "_seq TO " + newName + "_seq",
             CreateTableBuilder.createOracleTriggerForTable(newName))
           : singletonList(renameSqlCommand);
index 811bb596e040944e1ee3fdba308a4e241323da6e..af5f746ee8e9d285b0b2a7bd6ab2c0bf4673a20e 100644 (file)
@@ -96,15 +96,13 @@ import org.sonar.server.platform.db.migration.version.v84.groups.qprofileeditgro
 import org.sonar.server.platform.db.migration.version.v84.groups.qprofileeditgroups.DropIndexOnGroupIdOfQProfileEditGroupsTable;
 import org.sonar.server.platform.db.migration.version.v84.groups.qprofileeditgroups.MakeQProfileEditGroupsGroupUuidNotNullable;
 import org.sonar.server.platform.db.migration.version.v84.groups.qprofileeditgroups.PopulateQProfileEditGroupsGroupUuid;
+import org.sonar.server.platform.db.migration.version.v84.issuechanges.AddIndexOnIssueKeyOfIssueChangesTable;
+import org.sonar.server.platform.db.migration.version.v84.issuechanges.AddIndexOnKeeOfIssueChangesTable;
 import org.sonar.server.platform.db.migration.version.v84.issuechanges.AddPrimaryKeyOnUuidColumnOfIssueChangesTable;
-import org.sonar.server.platform.db.migration.version.v84.issuechanges.AddUuidColumnToIssueChangesTable;
-import org.sonar.server.platform.db.migration.version.v84.issuechanges.DropIdColumnOfIssueChangesTable;
-import org.sonar.server.platform.db.migration.version.v84.issuechanges.DropPrimaryKeyOnIdColumnOfIssueChangesTable;
-import org.sonar.server.platform.db.migration.version.v84.issuechanges.MakeIssueChangesUuidColumnNotNullable;
-import org.sonar.server.platform.db.migration.version.v84.issuechanges.PopulateIssueChangesUuid;
+import org.sonar.server.platform.db.migration.version.v84.issuechanges.CopyIssueChangesTable;
+import org.sonar.server.platform.db.migration.version.v84.issuechanges.DropIssueChangesTable;
+import org.sonar.server.platform.db.migration.version.v84.issuechanges.RenameIssueChangesCopyToIssueChanges;
 import org.sonar.server.platform.db.migration.version.v84.issues.AddPrimaryKeyOnKeeColumnOfIssuesTable;
-import org.sonar.server.platform.db.migration.version.v84.issues.DropIdColumnOfIssuesTable;
-import org.sonar.server.platform.db.migration.version.v84.issues.DropPrimaryKeyOnIdColumnOfIssuesTable;
 import org.sonar.server.platform.db.migration.version.v84.manualmeasures.AddPrimaryKeyOnUuidColumnOfManualMeasuresTable;
 import org.sonar.server.platform.db.migration.version.v84.manualmeasures.AddUuidColumnToManualMeasures;
 import org.sonar.server.platform.db.migration.version.v84.manualmeasures.DropIdColumnOfManualMeasuresTable;
@@ -118,11 +116,11 @@ import org.sonar.server.platform.db.migration.version.v84.metrics.DropPrimaryKey
 import org.sonar.server.platform.db.migration.version.v84.metrics.MakeMetricsUuidColumnNotNullable;
 import org.sonar.server.platform.db.migration.version.v84.metrics.PopulateMetricsUuid;
 import org.sonar.server.platform.db.migration.version.v84.metrics.livemeasures.AddIndexOnMetricUuidOfLiveMeasuresTable;
-import org.sonar.server.platform.db.migration.version.v84.metrics.livemeasures.AddMetricUuidColumnToLiveMeasures;
-import org.sonar.server.platform.db.migration.version.v84.metrics.livemeasures.DropIndexOnMetricIdOfLiveMeasuresTable;
-import org.sonar.server.platform.db.migration.version.v84.metrics.livemeasures.DropMetricIdColumnOfLiveMeasuresTable;
-import org.sonar.server.platform.db.migration.version.v84.metrics.livemeasures.MakeLiveMeasuresMetricUuidNotNullable;
-import org.sonar.server.platform.db.migration.version.v84.metrics.livemeasures.PopulateLiveMeasuresMetricUuid;
+import org.sonar.server.platform.db.migration.version.v84.metrics.livemeasures.AddIndexOnProjectUuidOfLiveMeasuresTable;
+import org.sonar.server.platform.db.migration.version.v84.metrics.livemeasures.AddPKeyOnUuidOfLiveMeasuresTable;
+import org.sonar.server.platform.db.migration.version.v84.metrics.livemeasures.CopyLiveMeasuresTable;
+import org.sonar.server.platform.db.migration.version.v84.metrics.livemeasures.DropLiveMeasuresTable;
+import org.sonar.server.platform.db.migration.version.v84.metrics.livemeasures.RenameLiveMeasuresCopyToLiveMeasures;
 import org.sonar.server.platform.db.migration.version.v84.metrics.manualmeasures.AddMetricUuidColumnToManualMeasures;
 import org.sonar.server.platform.db.migration.version.v84.metrics.manualmeasures.DropMetricIdColumnOfManualMeasuresTable;
 import org.sonar.server.platform.db.migration.version.v84.metrics.manualmeasures.MakeManualMeasuresMetricUuidNotNullable;
@@ -237,11 +235,10 @@ import org.sonar.server.platform.db.migration.version.v84.rules.deprecatedruleke
 import org.sonar.server.platform.db.migration.version.v84.rules.deprecatedrulekeys.DropRuleIdColumnOfDeprecatedRuleKeysTable;
 import org.sonar.server.platform.db.migration.version.v84.rules.deprecatedrulekeys.MakeDeprecatedRuleKeysRuleUuidColumnNotNullable;
 import org.sonar.server.platform.db.migration.version.v84.rules.deprecatedrulekeys.PopulateDeprecatedRuleKeysRuleUuidColumn;
-import org.sonar.server.platform.db.migration.version.v84.rules.issues.AddIndexToIssuesTable;
-import org.sonar.server.platform.db.migration.version.v84.rules.issues.AddRuleUuidColumnToIssuesTable;
-import org.sonar.server.platform.db.migration.version.v84.rules.issues.DropIndexOnRuleIdColumnOfIssuesTable;
-import org.sonar.server.platform.db.migration.version.v84.rules.issues.DropRuleIdColumnOfIssuesTable;
-import org.sonar.server.platform.db.migration.version.v84.rules.issues.PopulateIssuesRuleUuidColumn;
+import org.sonar.server.platform.db.migration.version.v84.rules.issues.AddIndexesToIssuesTable;
+import org.sonar.server.platform.db.migration.version.v84.rules.issues.CopyIssuesTable;
+import org.sonar.server.platform.db.migration.version.v84.rules.issues.DropIssuesTable;
+import org.sonar.server.platform.db.migration.version.v84.rules.issues.RenameIssuesCopyToIssues;
 import org.sonar.server.platform.db.migration.version.v84.rules.rulesmetadata.AddPrimaryKeyOnUuidAndOrganizationUuidColumnOfRulesMetadataTable;
 import org.sonar.server.platform.db.migration.version.v84.rules.rulesmetadata.AddRuleUuidColumnToRulesMetadataTable;
 import org.sonar.server.platform.db.migration.version.v84.rules.rulesmetadata.DropPrimaryKeyOnIdColumnOfRulesMetadataTable;
@@ -351,197 +348,193 @@ public class DbVersion84 implements DbVersion {
       .add(3407, "Add primary key on 'UUID' column of 'NOTIFICATIONS' table", AddPrimaryKeyOnUuidColumnOfNotificationTable.class)
       .add(3408, "Drop column 'ID' of 'NOTIFICATIONS' table", DropIdColumnOfNotificationTable.class)
 
-      // Migration on ISSUES table
-      .add(3409, "Drop primary key on 'ID' column of 'ISSUES' table", DropPrimaryKeyOnIdColumnOfIssuesTable.class)
-      .add(3410, "Add primary key on 'KEE' column of 'ISSUES' table", AddPrimaryKeyOnKeeColumnOfIssuesTable.class)
-      .add(3411, "Drop column 'ID' of 'ISSUES' table", DropIdColumnOfIssuesTable.class)
-
       // Migration on SNAPSHOTS table
-      .add(3412, "Drop primary key on 'ID' column of 'SNAPSHOTS' table", DropPrimaryKeyOnIdColumnOfSnapshotsTable.class)
-      .add(3413, "Add primary key on 'UUID' column of 'SNAPSHOTS' table", AddPrimaryKeyOnUuidColumnOfSnapshotsTable.class)
-      .add(3414, "Drop column 'ID' of 'SNAPSHOTS' table", DropIdColumnOfSnapshotsTable.class)
+      .add(3409, "Drop primary key on 'ID' column of 'SNAPSHOTS' table", DropPrimaryKeyOnIdColumnOfSnapshotsTable.class)
+      .add(3410, "Add primary key on 'UUID' column of 'SNAPSHOTS' table", AddPrimaryKeyOnUuidColumnOfSnapshotsTable.class)
+      .add(3411, "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)
+      .add(3412, "Drop unique index on 'uuid' column of 'CE_QUEUE' table", DropUniqueIndexOnUuidColumnOfCeQueueTable.class)
+      .add(3413, "Drop primary key on 'ID' column of 'CE_QUEUE' table", DropPrimaryKeyOnIdColumnOfCeQueueTable.class)
+      .add(3414, "Add primary key on 'UUID' column of 'CE_QUEUE' table", AddPrimaryKeyOnUuidColumnOfCeQueueTable.class)
+      .add(3415, "Drop column 'ID' of 'CE_QUEUE' table", DropIdColumnOfCeQueueTable.class)
 
       // Migration on CE_ACTIVITY table
-      .add(3419, "Drop primary key on 'ID' column of 'CE_ACTIVITY' table", DropPrimaryKeyOnIdColumnOfCeActivityTable.class)
-      .add(3420, "Add primary key on 'UUID' column of 'CE_ACTIVITY' table", AddPrimaryKeyOnUuidColumnOfCeActivityTable.class)
-      .add(3421, "Drop column 'ID' of 'CE_ACTIVITY' table", DropIdColumnOfCeActivityTable.class)
+      .add(3416, "Drop primary key on 'ID' column of 'CE_ACTIVITY' table", DropPrimaryKeyOnIdColumnOfCeActivityTable.class)
+      .add(3417, "Add primary key on 'UUID' column of 'CE_ACTIVITY' table", AddPrimaryKeyOnUuidColumnOfCeActivityTable.class)
+      .add(3418, "Drop column 'ID' of 'CE_ACTIVITY' table", DropIdColumnOfCeActivityTable.class)
 
       // Migration of DUPLICATIONS_INDEX table
-      .add(3422, "Add 'uuid' columns for DUPLICATIONS_INDEX", AddUuidToDuplicationsIndexTable.class)
-      .add(3423, "Populate 'uuid' columns for DUPLICATIONS_INDEX", PopulateDuplicationsIndexUuid.class)
-      .add(3424, "Make 'uuid' column not nullable for DUPLICATIONS_INDEX", MakeDuplicationsIndexUuidColumnNotNullable.class)
-      .add(3425, "Drop primary key on 'ID' column of 'DUPLICATIONS_INDEX' table", DropPrimaryKeyOnIdColumnOfDuplicationsIndexTable.class)
-      .add(3426, "Add primary key on 'UUID' column of 'DUPLICATIONS_INDEX' table", AddPrimaryKeyOnUuidColumnOfDuplicationsIndexTable.class)
-      .add(3427, "Drop column 'ID' of 'DUPLICATIONS_INDEX' table", DropIdColumnOfDuplicationsIndexTable.class)
+      .add(3419, "Add 'uuid' columns for DUPLICATIONS_INDEX", AddUuidToDuplicationsIndexTable.class)
+      .add(3420, "Populate 'uuid' columns for DUPLICATIONS_INDEX", PopulateDuplicationsIndexUuid.class)
+      .add(3421, "Make 'uuid' column not nullable for DUPLICATIONS_INDEX", MakeDuplicationsIndexUuidColumnNotNullable.class)
+      .add(3422, "Drop primary key on 'ID' column of 'DUPLICATIONS_INDEX' table", DropPrimaryKeyOnIdColumnOfDuplicationsIndexTable.class)
+      .add(3423, "Add primary key on 'UUID' column of 'DUPLICATIONS_INDEX' table", AddPrimaryKeyOnUuidColumnOfDuplicationsIndexTable.class)
+      .add(3424, "Drop column 'ID' of 'DUPLICATIONS_INDEX' table", DropIdColumnOfDuplicationsIndexTable.class)
 
       // Migration of ACTIVE_RULE_PARAMS table
-      .add(3428, "Add 'uuid' column for 'ACTIVE_RULE_PARAMS' table", AddUuidColumnToActiveRuleParametersTable.class)
-      .add(3429, "Populate 'uuid' column for 'ACTIVE_RULE_PARAMS' table", PopulateActiveRuleParametersUuid.class)
-      .add(3430, "Make 'uuid' column not nullable for 'ACTIVE_RULE_PARAMS' table", MakeActiveRuleParametersUuidColumnNotNullable.class)
-      .add(3431, "Drop primary key on 'ID' column of 'ACTIVE_RULE_PARAMS' table", DropPrimaryKeyOnIdColumnOfActiveRuleParametersTable.class)
-      .add(3432, "Add primary key on 'UUID' column of 'ACTIVE_RULE_PARAMS' table", AddPrimaryKeyOnUuidColumnOfActiveRuleParametersTable.class)
-      .add(3433, "Drop column 'ID' of 'ACTIVE_RULE_PARAMS' table", DropIdColumnOfActiveRuleParametersTable.class)
+      .add(3425, "Add 'uuid' column for 'ACTIVE_RULE_PARAMS' table", AddUuidColumnToActiveRuleParametersTable.class)
+      .add(3426, "Populate 'uuid' column for 'ACTIVE_RULE_PARAMS' table", PopulateActiveRuleParametersUuid.class)
+      .add(3427, "Make 'uuid' column not nullable for 'ACTIVE_RULE_PARAMS' table", MakeActiveRuleParametersUuidColumnNotNullable.class)
+      .add(3428, "Drop primary key on 'ID' column of 'ACTIVE_RULE_PARAMS' table", DropPrimaryKeyOnIdColumnOfActiveRuleParametersTable.class)
+      .add(3429, "Add primary key on 'UUID' column of 'ACTIVE_RULE_PARAMS' table", AddPrimaryKeyOnUuidColumnOfActiveRuleParametersTable.class)
+      .add(3430, "Drop column 'ID' of 'ACTIVE_RULE_PARAMS' table", DropIdColumnOfActiveRuleParametersTable.class)
 
       // Migration on PROJECT_MEASURES table
-      .add(3434, "Add 'uuid' columns for 'PROJECT_MEASURES'", AddUuidColumnToProjectMeasures.class)
-      .add(3435, "Add tech index on 'group_uuid' column of 'PROJECT_MEASURES' table", AddTechIndexOnUuidOfProjectMeasuresTable.class)
-      .add(3436, "Populate 'uuid' column for 'PROJECT_MEASURES'", PopulateProjectMeasureUuid.class)
-      .add(3437, "Drop tech index on 'group_id' column of 'PROJECT_MEASURES' table", DropTechIndexOnUuidOfProjectMeasuresTable.class)
-      .add(3438, "Make 'uuid' column not nullable for 'PROJECT_MEASURES'", MakeProjectMeasuresUuidColumnNotNullable.class)
-      .add(3439, "Drop primary key on 'ID' column of 'PROJECT_MEASURES' table", DropPrimaryKeyOnIdColumnOfProjectMeasuresTable.class)
-      .add(3440, "Add primary key on 'UUID' column of 'PROJECT_MEASURES' table", AddPrimaryKeyOnUuidColumnOfProjectMeasuresTable.class)
-      .add(3441, "Drop column 'ID' of 'PROJECT_MEASURES' table", DropIdColumnOfProjectMeasuresTable.class)
+      .add(3431, "Add 'uuid' columns for 'PROJECT_MEASURES'", AddUuidColumnToProjectMeasures.class)
+      .add(3432, "Add tech index on 'group_uuid' column of 'PROJECT_MEASURES' table", AddTechIndexOnUuidOfProjectMeasuresTable.class)
+      .add(3433, "Populate 'uuid' column for 'PROJECT_MEASURES'", PopulateProjectMeasureUuid.class)
+      .add(3434, "Drop tech index on 'group_id' column of 'PROJECT_MEASURES' table", DropTechIndexOnUuidOfProjectMeasuresTable.class)
+      .add(3435, "Make 'uuid' column not nullable for 'PROJECT_MEASURES'", MakeProjectMeasuresUuidColumnNotNullable.class)
+      .add(3436, "Drop primary key on 'ID' column of 'PROJECT_MEASURES' table", DropPrimaryKeyOnIdColumnOfProjectMeasuresTable.class)
+      .add(3437, "Add primary key on 'UUID' column of 'PROJECT_MEASURES' table", AddPrimaryKeyOnUuidColumnOfProjectMeasuresTable.class)
+      .add(3438, "Drop column 'ID' of 'PROJECT_MEASURES' table", DropIdColumnOfProjectMeasuresTable.class)
 
       // Migration of USER_TOKENS table
-      .add(3442, "Add 'UUID' column on 'USER_TOKENS' table", AddUuidColumnToUserTokens.class)
-      .add(3443, "Populate 'uuid' for 'USER_TOKENS'", PopulateUserTokensUuid.class)
-      .add(3444, "Make 'uuid' column not nullable for user_tokens", MakeUserTokensUuidNotNullable.class)
-      .add(3445, "Drop primary key on 'ID' column of 'USER_TOKENS' table", DropPrimaryKeyOnIdColumnOfUserTokensTable.class)
-      .add(3446, "Add primary key on 'UUID' column of 'USER_TOKENS' table", AddPrimaryKeyOnUuidColumnOfUserTokensTable.class)
-      .add(3447, "Drop column 'ID' of 'USER_TOKENS' table", DropIdColumnOfUserTokensTable.class)
+      .add(3439, "Add 'UUID' column on 'USER_TOKENS' table", AddUuidColumnToUserTokens.class)
+      .add(3440, "Populate 'uuid' for 'USER_TOKENS'", PopulateUserTokensUuid.class)
+      .add(3441, "Make 'uuid' column not nullable for user_tokens", MakeUserTokensUuidNotNullable.class)
+      .add(3442, "Drop primary key on 'ID' column of 'USER_TOKENS' table", DropPrimaryKeyOnIdColumnOfUserTokensTable.class)
+      .add(3443, "Add primary key on 'UUID' column of 'USER_TOKENS' table", AddPrimaryKeyOnUuidColumnOfUserTokensTable.class)
+      .add(3444, "Drop column 'ID' of 'USER_TOKENS' table", DropIdColumnOfUserTokensTable.class)
 
       // Migration on PROJECT_QPROFILES table
-      .add(3448, "Add 'uuid' column for 'PROJECT_QPROFILES'", AddUuidColumnToProjectQProfilesTable.class)
-      .add(3449, "Populate 'uuid' column for 'PROJECT_QPROFILES'", PopulateProjectQProfilesUuid.class)
-      .add(3450, "Make 'uuid' column not nullable for 'PROJECT_QPROFILES'", MakeProjectQProfilesUuidColumnNotNullable.class)
-      .add(3451, "Drop primary key on 'ID' column of 'PROJECT_QPROFILES' table", DropPrimaryKeyOnIdColumnOfProjectQProfilesTable.class)
-      .add(3452, "Add primary key on 'UUID' column of 'PROJECT_QPROFILES' table", AddPrimaryKeyOnUuidColumnOfProjectQProfilesTable.class)
-      .add(3453, "Drop column 'ID' of 'PROJECT_QPROFILES' table", DropIdColumnOfProjectQProfilesTable.class)
+      .add(3445, "Add 'uuid' column for 'PROJECT_QPROFILES'", AddUuidColumnToProjectQProfilesTable.class)
+      .add(3446, "Populate 'uuid' column for 'PROJECT_QPROFILES'", PopulateProjectQProfilesUuid.class)
+      .add(3447, "Make 'uuid' column not nullable for 'PROJECT_QPROFILES'", MakeProjectQProfilesUuidColumnNotNullable.class)
+      .add(3448, "Drop primary key on 'ID' column of 'PROJECT_QPROFILES' table", DropPrimaryKeyOnIdColumnOfProjectQProfilesTable.class)
+      .add(3449, "Add primary key on 'UUID' column of 'PROJECT_QPROFILES' table", AddPrimaryKeyOnUuidColumnOfProjectQProfilesTable.class)
+      .add(3450, "Drop column 'ID' of 'PROJECT_QPROFILES' table", DropIdColumnOfProjectQProfilesTable.class)
 
       // Migration of MANUAL_MEASURES table
-      .add(3454, "Add 'uuid' column for 'MANUAL_MEASURES'", AddUuidColumnToManualMeasures.class)
-      .add(3455, "Populate 'uuid' column for 'MANUAL_MEASURES'", PopulateManualMeasureUuid.class)
-      .add(3456, "Make 'uuid' column not nullable for 'MANUAL_MEASURES'", MakeManualMeasuresUuidColumnNotNullable.class)
-      .add(3457, "Drop primary key on 'ID' column of 'MANUAL_MEASURES' table", DropPrimaryKeyOnIdColumnOfManualMeasuresTable.class)
-      .add(3458, "Add primary key on 'UUID' column of 'MANUAL_MEASURES' table", AddPrimaryKeyOnUuidColumnOfManualMeasuresTable.class)
-      .add(3459, "Drop column 'ID' of 'MANUAL_MEASURES' table", DropIdColumnOfManualMeasuresTable.class)
+      .add(3451, "Add 'uuid' column for 'MANUAL_MEASURES'", AddUuidColumnToManualMeasures.class)
+      .add(3452, "Populate 'uuid' column for 'MANUAL_MEASURES'", PopulateManualMeasureUuid.class)
+      .add(3453, "Make 'uuid' column not nullable for 'MANUAL_MEASURES'", MakeManualMeasuresUuidColumnNotNullable.class)
+      .add(3454, "Drop primary key on 'ID' column of 'MANUAL_MEASURES' table", DropPrimaryKeyOnIdColumnOfManualMeasuresTable.class)
+      .add(3455, "Add primary key on 'UUID' column of 'MANUAL_MEASURES' table", AddPrimaryKeyOnUuidColumnOfManualMeasuresTable.class)
+      .add(3456, "Drop column 'ID' of 'MANUAL_MEASURES' table", DropIdColumnOfManualMeasuresTable.class)
 
       // Migration of GROUP_ROLES table
-      .add(3460, "Add 'UUID' column on 'GROUP_ROLES' table", AddUuidColumnToGroupRolesTable.class)
-      .add(3461, "Populate 'uuid' for 'GROUP_ROLES'", PopulateGroupRolesUuid.class)
-      .add(3462, "Make 'uuid' column not nullable for 'GROUP_ROLES'", MakeGroupRolesUuidColumnNotNullable.class)
-      .add(3463, "Drop primary key on 'ID' column of 'GROUP_ROLES' table", DropPrimaryKeyOnIdColumnOfGroupRolesTable.class)
-      .add(3464, "Add primary key on 'UUID' column of 'GROUP_ROLES' table", AddPrimaryKeyOnUuidColumnOfGroupRolesTable.class)
-      .add(3465, "Drop column 'ID' of 'GROUP_ROLES' table", DropIdColumnOfGroupRolesTable.class)
+      .add(3457, "Add 'UUID' column on 'GROUP_ROLES' table", AddUuidColumnToGroupRolesTable.class)
+      .add(3458, "Populate 'uuid' for 'GROUP_ROLES'", PopulateGroupRolesUuid.class)
+      .add(3459, "Make 'uuid' column not nullable for 'GROUP_ROLES'", MakeGroupRolesUuidColumnNotNullable.class)
+      .add(3460, "Drop primary key on 'ID' column of 'GROUP_ROLES' table", DropPrimaryKeyOnIdColumnOfGroupRolesTable.class)
+      .add(3461, "Add primary key on 'UUID' column of 'GROUP_ROLES' table", AddPrimaryKeyOnUuidColumnOfGroupRolesTable.class)
+      .add(3462, "Drop column 'ID' of 'GROUP_ROLES' table", DropIdColumnOfGroupRolesTable.class)
 
       // Migration of USER_ROLES table
-      .add(3466, "Add 'UUID' column on 'USER_ROLES' table", AddUuidColumnToUserRolesTable.class)
-      .add(3467, "Populate 'uuid' for 'USER_ROLES'", PopulateUserRolesUuid.class)
-      .add(3468, "Make 'uuid' column not nullable for 'USER_ROLES'", MakeUserRolesUuidColumnNotNullable.class)
-      .add(3469, "Drop primary key on 'ID' column of 'USER_ROLES' table", DropPrimaryKeyOnIdColumnOfUserRolesTable.class)
-      .add(3470, "Add primary key on 'UUID' column of 'USER_ROLES' table", AddPrimaryKeyOnUuidColumnOfUserRolesTable.class)
-      .add(3471, "Drop column 'ID' of 'USER_ROLES' table", DropIdColumnOfUserRolesTable.class)
+      .add(3463, "Add 'UUID' column on 'USER_ROLES' table", AddUuidColumnToUserRolesTable.class)
+      .add(3464, "Populate 'uuid' for 'USER_ROLES'", PopulateUserRolesUuid.class)
+      .add(3465, "Make 'uuid' column not nullable for 'USER_ROLES'", MakeUserRolesUuidColumnNotNullable.class)
+      .add(3466, "Drop primary key on 'ID' column of 'USER_ROLES' table", DropPrimaryKeyOnIdColumnOfUserRolesTable.class)
+      .add(3468, "Add primary key on 'UUID' column of 'USER_ROLES' table", AddPrimaryKeyOnUuidColumnOfUserRolesTable.class)
+      .add(3469, "Drop column 'ID' of 'USER_ROLES' table", DropIdColumnOfUserRolesTable.class)
 
       // Migration of FILE_SOURCES table
-      .add(3472, "Add 'UUID' column on 'FILE_SOURCES' table", AddUuidColumnToFileSourcesTable.class)
-      .add(3473, "Populate 'uuid' for 'FILE_SOURCES'", PopulateFileSourcesUuid.class)
-      .add(3474, "Make 'uuid' column not nullable for 'FILE_SOURCES'", MakeFileSourcesUuidColumnNotNullable.class)
-      .add(3475, "Drop primary key on 'ID' column of 'FILE_SOURCES' table", DropPrimaryKeyOnIdColumnOfFileSourcesTable.class)
-      .add(3476, "Add primary key on 'UUID' column of 'FILE_SOURCES' table", AddPrimaryKeyOnUuidColumnOfFileSourcesTable.class)
-      .add(3477, "Drop column 'ID' of 'FILE_SOURCES' table", DropIdColumnOfFileSourcesTable.class)
+      .add(3470, "Add 'UUID' column on 'FILE_SOURCES' table", AddUuidColumnToFileSourcesTable.class)
+      .add(3471, "Populate 'uuid' for 'FILE_SOURCES'", PopulateFileSourcesUuid.class)
+      .add(3472, "Make 'uuid' column not nullable for 'FILE_SOURCES'", MakeFileSourcesUuidColumnNotNullable.class)
+      .add(3473, "Drop primary key on 'ID' column of 'FILE_SOURCES' table", DropPrimaryKeyOnIdColumnOfFileSourcesTable.class)
+      .add(3474, "Add primary key on 'UUID' column of 'FILE_SOURCES' table", AddPrimaryKeyOnUuidColumnOfFileSourcesTable.class)
+      .add(3475, "Drop column 'ID' of 'FILE_SOURCES' table", DropIdColumnOfFileSourcesTable.class)
 
       // Migration of ISSUE_CHANGES table
-      .add(3478, "Add 'UUID' column on 'ISSUE_CHANGES' table", AddUuidColumnToIssueChangesTable.class)
-      .add(3479, "Populate 'uuid' for 'ISSUE_CHANGES'", PopulateIssueChangesUuid.class)
-      .add(3480, "Make 'uuid' column not nullable for 'ISSUE_CHANGES'", MakeIssueChangesUuidColumnNotNullable.class)
-      .add(3481, "Drop primary key on 'ID' column of 'ISSUE_CHANGES' table", DropPrimaryKeyOnIdColumnOfIssueChangesTable.class)
-      .add(3482, "Add primary key on 'UUID' column of 'ISSUE_CHANGES' table", AddPrimaryKeyOnUuidColumnOfIssueChangesTable.class)
-      .add(3483, "Drop column 'ID' of 'ISSUE_CHANGES' table", DropIdColumnOfIssueChangesTable.class)
+      .add(3476, "Copy 'ISSUE_CHANGES' table to 'ISSUE_CHANGES_COPY'", CopyIssueChangesTable.class)
+      .add(3477, "Drop 'ISSUE_CHANGES' table", DropIssueChangesTable.class)
+      .add(3478, "Rename table 'ISSUE_CHANGES_COPY' to 'ISSUE_CHANGES'", RenameIssueChangesCopyToIssueChanges.class)
+      .add(3479, "Add index on 'ISSUE_KEY' of 'ISSUE_CHANGES' table", AddIndexOnIssueKeyOfIssueChangesTable.class)
+      .add(3480, "Add index on 'KEE' of 'ISSUE_CHANGES' table", AddIndexOnKeeOfIssueChangesTable.class)
+      .add(3481, "Add primary key on 'UUID' column of 'ISSUE_CHANGES' table", AddPrimaryKeyOnUuidColumnOfIssueChangesTable.class)
 
       // Migration of QUALITY_GATE_CONDITIONS table
-      .add(3484, "Add 'UUID' column on 'QUALITY_GATE_CONDITIONS' table", AddUuidColumnToQualityGateConditionsTable.class)
-      .add(3485, "Populate 'uuid' for 'QUALITY_GATE_CONDITIONS'", PopulateQualityGateConditionsUuid.class)
-      .add(3486, "Make 'uuid' column not nullable for 'QUALITY_GATE_CONDITIONS'", MakeQualityGateConditionsUuidColumnNotNullable.class)
-      .add(3487, "Drop primary key on 'ID' column of 'QUALITY_GATE_CONDITIONS' table", DropPrimaryKeyOnIdColumnOfQualityGateConditionsTable.class)
-      .add(3488, "Add primary key on 'UUID' column of 'QUALITY_GATE_CONDITIONS' table", AddPrimaryKeyOnUuidColumnOfQualityGateConditionsTable.class)
-      .add(3489, "Drop column 'ID' of 'QUALITY_GATE_CONDITIONS' table", DropIdColumnOfQualityGateConditionsTable.class)
+      .add(3483, "Add 'UUID' column on 'QUALITY_GATE_CONDITIONS' table", AddUuidColumnToQualityGateConditionsTable.class)
+      .add(3484, "Populate 'uuid' for 'QUALITY_GATE_CONDITIONS'", PopulateQualityGateConditionsUuid.class)
+      .add(3485, "Make 'uuid' column not nullable for 'QUALITY_GATE_CONDITIONS'", MakeQualityGateConditionsUuidColumnNotNullable.class)
+      .add(3486, "Drop primary key on 'ID' column of 'QUALITY_GATE_CONDITIONS' table", DropPrimaryKeyOnIdColumnOfQualityGateConditionsTable.class)
+      .add(3487, "Add primary key on 'UUID' column of 'QUALITY_GATE_CONDITIONS' table", AddPrimaryKeyOnUuidColumnOfQualityGateConditionsTable.class)
+      .add(3488, "Drop column 'ID' of 'QUALITY_GATE_CONDITIONS' table", DropIdColumnOfQualityGateConditionsTable.class)
 
       // Migration of PERM_TEMPLATES_GROUPS table
-      .add(3490, "Add 'UUID' column on 'PERM_TEMPLATES_GROUPS' table", AddUuidColumnToPermTemplatesGroupsTable.class)
-      .add(3491, "Populate 'uuid' for 'PERM_TEMPLATES_GROUPS'", PopulatePermTemplatesGroupsUuid.class)
-      .add(3492, "Make 'uuid' column not nullable for 'PERM_TEMPLATES_GROUPS'", MakePermTemplatesGroupsUuidColumnNotNullable.class)
-      .add(3493, "Drop primary key on 'ID' column of 'PERM_TEMPLATES_GROUPS' table", DropPrimaryKeyOnIdColumnOfPermTemplatesGroupsTable.class)
-      .add(3494, "Add primary key on 'UUID' column of 'PERM_TEMPLATES_GROUPS' table", AddPrimaryKeyOnUuidColumnOfPermTemplatesGroupsTable.class)
-      .add(3495, "Drop column 'ID' of 'PERM_TEMPLATES_GROUPS' table", DropIdColumnOfPermTemplatesGroupsTable.class)
+      .add(3489, "Add 'UUID' column on 'PERM_TEMPLATES_GROUPS' table", AddUuidColumnToPermTemplatesGroupsTable.class)
+      .add(3490, "Populate 'uuid' for 'PERM_TEMPLATES_GROUPS'", PopulatePermTemplatesGroupsUuid.class)
+      .add(3491, "Make 'uuid' column not nullable for 'PERM_TEMPLATES_GROUPS'", MakePermTemplatesGroupsUuidColumnNotNullable.class)
+      .add(3492, "Drop primary key on 'ID' column of 'PERM_TEMPLATES_GROUPS' table", DropPrimaryKeyOnIdColumnOfPermTemplatesGroupsTable.class)
+      .add(3493, "Add primary key on 'UUID' column of 'PERM_TEMPLATES_GROUPS' table", AddPrimaryKeyOnUuidColumnOfPermTemplatesGroupsTable.class)
+      .add(3494, "Drop column 'ID' of 'PERM_TEMPLATES_GROUPS' table", DropIdColumnOfPermTemplatesGroupsTable.class)
 
       // Migration of PERM_TPL_CHARACTERISTICS table
-      .add(3496, "Add 'UUID' column on 'PERM_TPL_CHARACTERISTICS' table", AddUuidColumnToPermTplCharacteristicsTable.class)
-      .add(3497, "Populate 'uuid' for 'PERM_TPL_CHARACTERISTICS'", PopulatePermTplCharacteristicsUuid.class)
-      .add(3498, "Make 'uuid' column not nullable for 'PERM_TPL_CHARACTERISTICS'", MakePermTplCharacteristicsUuidColumnNotNullable.class)
-      .add(3499, "Drop primary key on 'ID' column of 'PERM_TPL_CHARACTERISTICS' table", DropPrimaryKeyOnIdColumnOfPermTplCharacteristicsTable.class)
-      .add(3500, "Add primary key on 'UUID' column of 'PERM_TPL_CHARACTERISTICS' table", AddPrimaryKeyOnUuidColumnOfPermTplCharacteristicsTable.class)
-      .add(3501, "Drop column 'ID' of 'PERM_TPL_CHARACTERISTICS' table", DropIdColumnOfPermTplCharacteristicsTable.class)
+      .add(3495, "Add 'UUID' column on 'PERM_TPL_CHARACTERISTICS' table", AddUuidColumnToPermTplCharacteristicsTable.class)
+      .add(3496, "Populate 'uuid' for 'PERM_TPL_CHARACTERISTICS'", PopulatePermTplCharacteristicsUuid.class)
+      .add(3497, "Make 'uuid' column not nullable for 'PERM_TPL_CHARACTERISTICS'", MakePermTplCharacteristicsUuidColumnNotNullable.class)
+      .add(3498, "Drop primary key on 'ID' column of 'PERM_TPL_CHARACTERISTICS' table", DropPrimaryKeyOnIdColumnOfPermTplCharacteristicsTable.class)
+      .add(3499, "Add primary key on 'UUID' column of 'PERM_TPL_CHARACTERISTICS' table", AddPrimaryKeyOnUuidColumnOfPermTplCharacteristicsTable.class)
+      .add(3500, "Drop column 'ID' of 'PERM_TPL_CHARACTERISTICS' table", DropIdColumnOfPermTplCharacteristicsTable.class)
 
       // Migration of PERM_TEMPLATES_USERS table
-      .add(3502, "Add 'UUID' column on 'PERM_TEMPLATES_USERS' table", AddUuidColumnToPermTemplatesUsersTable.class)
-      .add(3503, "Populate 'uuid' for 'PERM_TEMPLATES_USERS'", PopulatePermTemplatesUsersUuid.class)
-      .add(3504, "Make 'uuid' column not nullable for 'PERM_TEMPLATES_USERS'", MakePermTemplatesUsersUuidColumnNotNullable.class)
-      .add(3505, "Drop primary key on 'ID' column of 'PERM_TEMPLATES_USERS' table", DropPrimaryKeyOnIdColumnOfPermTemplatesUsersTable.class)
-      .add(3506, "Add primary key on 'UUID' column of 'PERM_TEMPLATES_USERS' table", AddPrimaryKeyOnUuidColumnOfPermTemplatesUsersTable.class)
-      .add(3507, "Drop column 'ID' of 'PERM_TEMPLATES_USERS' table", DropIdColumnOfPermTemplatesUsersTable.class)
+      .add(3501, "Add 'UUID' column on 'PERM_TEMPLATES_USERS' table", AddUuidColumnToPermTemplatesUsersTable.class)
+      .add(3502, "Populate 'uuid' for 'PERM_TEMPLATES_USERS'", PopulatePermTemplatesUsersUuid.class)
+      .add(3503, "Make 'uuid' column not nullable for 'PERM_TEMPLATES_USERS'", MakePermTemplatesUsersUuidColumnNotNullable.class)
+      .add(3504, "Drop primary key on 'ID' column of 'PERM_TEMPLATES_USERS' table", DropPrimaryKeyOnIdColumnOfPermTemplatesUsersTable.class)
+      .add(3505, "Add primary key on 'UUID' column of 'PERM_TEMPLATES_USERS' table", AddPrimaryKeyOnUuidColumnOfPermTemplatesUsersTable.class)
+      .add(3506, "Drop column 'ID' of 'PERM_TEMPLATES_USERS' table", DropIdColumnOfPermTemplatesUsersTable.class)
 
       // Migration of ACTIVE_RULES table
-      .add(3508, "Add 'UUID' column on 'ACTIVE_RULES' table", AddUuidColumnToActiveRulesTable.class)
-      .add(3509, "Populate 'uuid' for 'ACTIVE_RULES'", PopulateActiveRulesUuid.class)
-      .add(3510, "Make 'uuid' column not nullable for 'ACTIVE_RULES'", MakeActiveRulesUuidColumnNotNullable.class)
+      .add(3507, "Add 'UUID' column on 'ACTIVE_RULES' table", AddUuidColumnToActiveRulesTable.class)
+      .add(3508, "Populate 'uuid' for 'ACTIVE_RULES'", PopulateActiveRulesUuid.class)
+      .add(3509, "Make 'uuid' column not nullable for 'ACTIVE_RULES'", MakeActiveRulesUuidColumnNotNullable.class)
 
       // Migration of FK in ACTIVE_RULE_PARAMETERS to ACTIVE_RULES
-      .add(3511, "Add 'active_rule_uuid' column on 'ACTIVE_RULE_PARAMETERS' table", AddActiveRuleUuidColumnToActiveRuleParameters.class)
-      .add(3512, "Populate 'active_rule_uuid' for 'ACTIVE_RULE_PARAMETERS'", PopulateActiveRuleParametersActiveRuleUuid.class)
-      .add(3513, "Make 'active_rule_uuid' column not nullable for 'ACTIVE_RULE_PARAMETERS'", MakeActiveRuleParametersActiveRuleUuidNotNullable.class)
-      .add(3514, "Drop index on 'active_rule_id' column of 'ACTIVE_RULE_PARAMETERS' table", DropIndexOnActiveRuleIdOfActiveRuleParametersTable.class)
-      .add(3515, "Add index on 'active_rule_uuid' column of 'ACTIVE_RULE_PARAMETERS' table", AddIndexOnActiveRuleUuidOfActiveRuleParametersTable.class)
+      .add(3510, "Add 'active_rule_uuid' column on 'ACTIVE_RULE_PARAMETERS' table", AddActiveRuleUuidColumnToActiveRuleParameters.class)
+      .add(3511, "Populate 'active_rule_uuid' for 'ACTIVE_RULE_PARAMETERS'", PopulateActiveRuleParametersActiveRuleUuid.class)
+      .add(3512, "Make 'active_rule_uuid' column not nullable for 'ACTIVE_RULE_PARAMETERS'", MakeActiveRuleParametersActiveRuleUuidNotNullable.class)
+      .add(3513, "Drop index on 'active_rule_id' column of 'ACTIVE_RULE_PARAMETERS' table", DropIndexOnActiveRuleIdOfActiveRuleParametersTable.class)
+      .add(3514, "Add index on 'active_rule_uuid' column of 'ACTIVE_RULE_PARAMETERS' table", AddIndexOnActiveRuleUuidOfActiveRuleParametersTable.class)
 
       // Finish migration of ACTIVE_RULES
-      .add(3516, "Drop primary key on 'ID' column of 'ACTIVE_RULES' table", DropPrimaryKeyOnIdColumnOfActiveRulesTable.class)
-      .add(3517, "Add primary key on 'UUID' column of 'ACTIVE_RULES' table", AddPrimaryKeyOnUuidColumnOfActiveRulesTable.class)
-      .add(3518, "Drop column 'ID' of 'ACTIVE_RULES' table", DropIdColumnOfActiveRulesTable.class)
-      .add(3519, "Drop column 'active_rule_id' of 'ACTIVE_RULE_PARAMETERS' table", DropActiveRuleIdColumnOfActiveRuleParametersTable.class)
+      .add(3515, "Drop primary key on 'ID' column of 'ACTIVE_RULES' table", DropPrimaryKeyOnIdColumnOfActiveRulesTable.class)
+      .add(3516, "Add primary key on 'UUID' column of 'ACTIVE_RULES' table", AddPrimaryKeyOnUuidColumnOfActiveRulesTable.class)
+      .add(3517, "Drop column 'ID' of 'ACTIVE_RULES' table", DropIdColumnOfActiveRulesTable.class)
+      .add(3518, "Drop column 'active_rule_id' of 'ACTIVE_RULE_PARAMETERS' table", DropActiveRuleIdColumnOfActiveRuleParametersTable.class)
 
       // Migration on RULES_PARAMETERS table - populate uuid column
-      .add(3520, "Add 'uuid' column for 'RULES_PARAMETERS'", AddUuidColumnToRulesParameters.class)
-      .add(3521, "Populate 'uuid' column for 'RULES_PARAMETERS'", PopulateRulesParametersUuid.class)
-      .add(3522, "Make 'uuid' column not nullable for 'RULES_PARAMETERS'", MakeRulesParametersUuidColumnNotNullable.class)
+      .add(3519, "Add 'uuid' column for 'RULES_PARAMETERS'", AddUuidColumnToRulesParameters.class)
+      .add(3520, "Populate 'uuid' column for 'RULES_PARAMETERS'", PopulateRulesParametersUuid.class)
+      .add(3521, "Make 'uuid' column not nullable for 'RULES_PARAMETERS'", MakeRulesParametersUuidColumnNotNullable.class)
 
       // Migration of ACTIVE_RULE_PARAMS FK to RULES_PARAMETERS, switch from ruleParamId to ruleParamUuid
-      .add(3523, "Add 'rules_parameter_uuid' column for 'ACTIVE_RULE_PARAMS' table", AddRulesParameterUuidColumnToActiveRuleParameters.class)
-      .add(3524, "Populate 'rules_parameter_uuid' column for 'ACTIVE_RULE_PARAMS' table", PopulateActiveRuleParametersRulesParameterUuid.class)
-      .add(3525, "Make 'rules_parameter_uuid' column not nullable for 'ACTIVE_RULE_PARAMS' table", MakeActiveRuleParametersRulesParameterUuidColumnNotNullable.class)
-      .add(3526, "Drop column 'rules_parameter_id' of 'ACTIVE_RULE_PARAMS' table", DropRulesParameterIdColumnOfActiveRuleParametersTable.class)
+      .add(3522, "Add 'rules_parameter_uuid' column for 'ACTIVE_RULE_PARAMS' table", AddRulesParameterUuidColumnToActiveRuleParameters.class)
+      .add(3523, "Populate 'rules_parameter_uuid' column for 'ACTIVE_RULE_PARAMS' table", PopulateActiveRuleParametersRulesParameterUuid.class)
+      .add(3524, "Make 'rules_parameter_uuid' column not nullable for 'ACTIVE_RULE_PARAMS' table", MakeActiveRuleParametersRulesParameterUuidColumnNotNullable.class)
+      .add(3525, "Drop column 'rules_parameter_id' of 'ACTIVE_RULE_PARAMS' table", DropRulesParameterIdColumnOfActiveRuleParametersTable.class)
 
       // Migration on RULES_PARAMETERS table change PK
-      .add(3527, "Drop primary key on 'ID' column of 'RULES_PARAMETERS' table", DropPrimaryKeyOnIdColumnOfRulesParametersTable.class)
-      .add(3528, "Add primary key on 'UUID' column of 'RULES_PARAMETERS' table", AddPrimaryKeyOnUuidColumnOfRulesParametersTable.class)
-      .add(3529, "Drop column 'ID' of 'RULES_PARAMETERS' table", DropIdColumnOfRulesParametersTable.class)
+      .add(3526, "Drop primary key on 'ID' column of 'RULES_PARAMETERS' table", DropPrimaryKeyOnIdColumnOfRulesParametersTable.class)
+      .add(3527, "Add primary key on 'UUID' column of 'RULES_PARAMETERS' table", AddPrimaryKeyOnUuidColumnOfRulesParametersTable.class)
+      .add(3528, "Drop column 'ID' of 'RULES_PARAMETERS' table", DropIdColumnOfRulesParametersTable.class)
 
       // Migration of METRICS table
-      .add(3530, "Add 'UUID' column on 'METRICS' table", AddUuidColumnToMetricsTable.class)
-      .add(3531, "Populate 'uuid' for 'METRICS'", PopulateMetricsUuid.class)
-      .add(3532, "Make 'uuid' column not nullable for 'METRICS'", MakeMetricsUuidColumnNotNullable.class)
+      .add(3529, "Add 'UUID' column on 'METRICS' table", AddUuidColumnToMetricsTable.class)
+      .add(3530, "Populate 'uuid' for 'METRICS'", PopulateMetricsUuid.class)
+      .add(3531, "Make 'uuid' column not nullable for 'METRICS'", MakeMetricsUuidColumnNotNullable.class)
 
       // Migration of FK in PROJECT_MEASURES to METRICS
-      .add(3533, "Add 'metric_uuid' column on 'PROJECT_MEASURES' table", AddMetricUuidColumnToProjectMeasures.class)
-      .add(3534, "Populate 'metric_uuid' for 'PROJECT_MEASURES'", PopulateProjectMeasuresMetricUuid.class)
-      .add(3535, "Make 'metric_uuid' column not nullable for 'PROJECT_MEASURES'", MakeProjectMeasuresMetricUuidNotNullable.class)
-      .add(3536, "Drop index on 'metric_id' and 'analysis_uuid' columns of 'PROJECT_MEASURES' table", DropIndexOnMetricIdOfProjectMeasuresTable.class)
-      .add(3537, "Add index on 'metric_uuid' and 'analysis_uuid' columns of 'PROJECT_MEASURES' table", AddIndexOnMetricUuidOfProjectMeasuresTable.class)
+      .add(3532, "Add 'metric_uuid' column on 'PROJECT_MEASURES' table", AddMetricUuidColumnToProjectMeasures.class)
+      .add(3533, "Populate 'metric_uuid' for 'PROJECT_MEASURES'", PopulateProjectMeasuresMetricUuid.class)
+      .add(3534, "Make 'metric_uuid' column not nullable for 'PROJECT_MEASURES'", MakeProjectMeasuresMetricUuidNotNullable.class)
+      .add(3535, "Drop index on 'metric_id' and 'analysis_uuid' columns of 'PROJECT_MEASURES' table", DropIndexOnMetricIdOfProjectMeasuresTable.class)
+      .add(3536, "Add index on 'metric_uuid' and 'analysis_uuid' columns of 'PROJECT_MEASURES' table", AddIndexOnMetricUuidOfProjectMeasuresTable.class)
 
       // Migration of FK in QUALITY_GATE_CONDITIONS to METRICS
-      .add(3538, "Add 'metric_uuid' column on 'QUALITY_GATE_CONDITIONS' table", AddMetricUuidColumnToQualityGateConditions.class)
-      .add(3539, "Populate 'metric_uuid' for 'QUALITY_GATE_CONDITIONS'", PopulateQualityGateConditionsMetricUuid.class)
-      .add(3540, "Make 'metric_uuid' column not nullable for 'QUALITY_GATE_CONDITIONS'", MakeQualityGateConditionsMetricUuidNotNullable.class)
+      .add(3537, "Add 'metric_uuid' column on 'QUALITY_GATE_CONDITIONS' table", AddMetricUuidColumnToQualityGateConditions.class)
+      .add(3538, "Populate 'metric_uuid' for 'QUALITY_GATE_CONDITIONS'", PopulateQualityGateConditionsMetricUuid.class)
+      .add(3539, "Make 'metric_uuid' column not nullable for 'QUALITY_GATE_CONDITIONS'", MakeQualityGateConditionsMetricUuidNotNullable.class)
 
       // Migration of FK in LIVE_MEASURES to METRICS
-      .add(3541, "Add 'metric_uuid' column on 'LIVE_MEASURES' table", AddMetricUuidColumnToLiveMeasures.class)
-      .add(3542, "Populate 'metric_uuid' for 'LIVE_MEASURES'", PopulateLiveMeasuresMetricUuid.class)
-      .add(3543, "Make 'metric_uuid' column not nullable for 'LIVE_MEASURES'", MakeLiveMeasuresMetricUuidNotNullable.class)
-      .add(3544, "Drop index on 'metric_id' column of 'LIVE_MEASURES' table", DropIndexOnMetricIdOfLiveMeasuresTable.class)
+      .add(3540, "Copy 'LIVE_MEASURES' table to 'LIVE_MEASURES_COPY'", CopyLiveMeasuresTable.class)
+      .add(3541, "Drop 'LIVE_MEASURES' table", DropLiveMeasuresTable.class)
+      .add(3542, "Rename table 'LIVE_MEASURES_COPY' to 'LIVE_MEASURES'", RenameLiveMeasuresCopyToLiveMeasures.class)
+      .add(3543, "Add primary key on 'uuid' column of 'LIVE_MEASURES' table", AddPKeyOnUuidOfLiveMeasuresTable.class)
+      .add(3544, "Add index on 'project_uuid' column of 'LIVE_MEASURES' table", AddIndexOnProjectUuidOfLiveMeasuresTable.class)
       .add(3545, "Add index on 'metric_uuid' column of 'LIVE_MEASURES' table", AddIndexOnMetricUuidOfLiveMeasuresTable.class)
 
       // Migration of FK in MANUAL_MEASURES to METRICS
@@ -554,7 +547,6 @@ public class DbVersion84 implements DbVersion {
       .add(3550, "Add primary key on 'UUID' column of 'METRICS' table", AddPrimaryKeyOnUuidColumnOfMetricsTable.class)
       .add(3551, "Drop column 'METRIC_ID' of 'PROJECT_MEASURES' table", DropMetricIdColumnOfProjectMeasuresTable.class)
       .add(3552, "Drop column 'METRIC_ID' of 'QUALITY_GATE_CONDITIONS' table", DropMetricIdColumnOfQualityGateConditionsTable.class)
-      .add(3553, "Drop column 'METRIC_ID' of 'LIVE_MEASURES' table", DropMetricIdColumnOfLiveMeasuresTable.class)
       .add(3554, "Drop column 'METRIC_ID' of 'MANUAL_MEASURES' table", DropMetricIdColumnOfManualMeasuresTable.class)
       .add(3555, "Drop column 'ID' of 'METRICS' table", DropIdColumnOfMetricsTable.class)
 
@@ -770,11 +762,12 @@ public class DbVersion84 implements DbVersion {
       .add(3702, "Add index to 'DEPRECATED_RULE_KEYS' table", AddIndexToDeprecatedRuleKeysTable.class)
       .add(3703, "Drop column 'RULE_ID' of 'DEPRECATED_RULE_KEYS' table", DropRuleIdColumnOfDeprecatedRuleKeysTable.class)
       // Migration of ISSUE FK to RULES, switch from rule_id to rule_uuid
-      .add(3704, "Add 'RULE_UUID' column for 'ISSUES' table", AddRuleUuidColumnToIssuesTable.class)
-      .add(3705, "Add index to 'ISSUES' table", AddIndexToIssuesTable.class)
-      .add(3706, "Populate 'RULE_UUID' column for 'ISSUES' table", PopulateIssuesRuleUuidColumn.class)
-      .add(3707, "Drop index on 'RULE_ID' of 'ISSUES' table", DropIndexOnRuleIdColumnOfIssuesTable.class)
-      .add(3708, "Drop column 'RULE_ID' of 'ISSUES' table", DropRuleIdColumnOfIssuesTable.class)
+      .add(3704, "Copy 'ISSUES' table to 'ISSUES_COPY", CopyIssuesTable.class)
+      .add(3705, "Drop 'ISSUES' table", DropIssuesTable.class)
+      .add(3706, "Rename 'ISSUES_COPY' table to 'ISSUES'", RenameIssuesCopyToIssues.class)
+      .add(3707, "Add indexes to 'ISSUES' table", AddIndexesToIssuesTable.class)
+      .add(3708, "Add primary key on 'KEE' column of 'ISSUES' table", AddPrimaryKeyOnKeeColumnOfIssuesTable.class)
+
       // continue with RULES table cleanup
       .add(3709, "Drop primary key on 'ID' column of 'RULES' table", DropPrimaryKeyOnIdColumnOfRulesTable.class)
       .add(3710, "Add primary key on 'UUID' column of 'RULES' table", AddPrimaryKeyOnUuidColumnOfRulesTable.class)
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/AddIndexOnIssueKeyOfIssueChangesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/AddIndexOnIssueKeyOfIssueChangesTable.java
new file mode 100644 (file)
index 0000000..9e39b93
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * 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.v84.issuechanges;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.db.DatabaseUtils;
+import org.sonar.server.platform.db.migration.sql.CreateIndexBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
+
+public class AddIndexOnIssueKeyOfIssueChangesTable extends DdlChange {
+  private static final String TABLE_NAME = "issue_changes";
+  private static final String INDEX_NAME = "issue_changes_issue_key";
+
+  public AddIndexOnIssueKeyOfIssueChangesTable(Database db) {
+    super(db);
+  }
+
+  @Override
+  public void execute(Context context) throws SQLException {
+    if (!indexExists()) {
+      context.execute(new CreateIndexBuilder()
+        .setUnique(false)
+        .setTable(TABLE_NAME)
+        .setName(INDEX_NAME)
+        .addColumn(newVarcharColumnDefBuilder()
+          .setColumnName("issue_key")
+          .setIsNullable(true)
+          .setLimit(50)
+          .build())
+        .build());
+    }
+  }
+
+  private boolean indexExists() throws SQLException {
+    try (Connection connection = getDatabase().getDataSource().getConnection()) {
+      return DatabaseUtils.indexExists(TABLE_NAME, INDEX_NAME, connection);
+    }
+  }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/AddIndexOnKeeOfIssueChangesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/AddIndexOnKeeOfIssueChangesTable.java
new file mode 100644 (file)
index 0000000..56cb501
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * 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.v84.issuechanges;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.db.DatabaseUtils;
+import org.sonar.server.platform.db.migration.sql.CreateIndexBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
+
+public class AddIndexOnKeeOfIssueChangesTable extends DdlChange {
+  private static final String TABLE_NAME = "issue_changes";
+  private static final String INDEX_NAME = "issue_changes_kee";
+
+  public AddIndexOnKeeOfIssueChangesTable(Database db) {
+    super(db);
+  }
+
+  @Override
+  public void execute(Context context) throws SQLException {
+    if (!indexExists()) {
+      context.execute(new CreateIndexBuilder()
+        .setUnique(false)
+        .setTable(TABLE_NAME)
+        .setName(INDEX_NAME)
+        .addColumn(newVarcharColumnDefBuilder()
+          .setColumnName("kee")
+          .setIsNullable(true)
+          .setLimit(50)
+          .build())
+        .build());
+    }
+  }
+
+  private boolean indexExists() throws SQLException {
+    try (Connection connection = getDatabase().getDataSource().getConnection()) {
+      return DatabaseUtils.indexExists(TABLE_NAME, INDEX_NAME, connection);
+    }
+  }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/AddUuidColumnToIssueChangesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/AddUuidColumnToIssueChangesTable.java
deleted file mode 100644 (file)
index 5e230a5..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * 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.v84.issuechanges;
-
-import org.sonar.db.Database;
-import org.sonar.server.platform.db.migration.version.v84.common.AddUuidColumnToTable;
-
-public class AddUuidColumnToIssueChangesTable extends AddUuidColumnToTable {
-  private static final String TABLE = "issue_changes";
-
-  public AddUuidColumnToIssueChangesTable(Database db) {
-    super(db, TABLE);
-  }
-}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/CopyIssueChangesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/CopyIssueChangesTable.java
new file mode 100644 (file)
index 0000000..344f984
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ * 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.v84.issuechanges;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.CreateTableAsBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.sonar.server.platform.db.migration.def.BigIntegerColumnDef.newBigIntegerColumnDefBuilder;
+import static org.sonar.server.platform.db.migration.def.ClobColumnDef.newClobColumnDefBuilder;
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
+
+public class CopyIssueChangesTable extends DdlChange {
+  public CopyIssueChangesTable(Database db) {
+    super(db);
+  }
+
+  @Override public void execute(Context context) throws SQLException {
+    CreateTableAsBuilder builder = new CreateTableAsBuilder(getDialect(), "issue_changes_copy", "issue_changes")
+      // this will cause the following changes:
+      // * Add UUID with values in ID casted to varchar
+      .addColumnWithCast(newVarcharColumnDefBuilder().setColumnName("uuid").setLimit(40).setIsNullable(false).build(), "id")
+      .addColumn(newVarcharColumnDefBuilder().setColumnName("kee").setLimit(50).build())
+      .addColumn(newVarcharColumnDefBuilder().setColumnName("issue_key").setLimit(50).setIsNullable(false).build())
+      .addColumn(newVarcharColumnDefBuilder().setColumnName("user_login").setLimit(255).build())
+      .addColumn(newVarcharColumnDefBuilder().setColumnName("change_type").setLimit(20).build())
+      .addColumn(newClobColumnDefBuilder().setColumnName("change_data").build())
+      .addColumn(newBigIntegerColumnDefBuilder().setColumnName("created_at").build())
+      .addColumn(newBigIntegerColumnDefBuilder().setColumnName("updated_at").build())
+      .addColumn(newBigIntegerColumnDefBuilder().setColumnName("issue_change_creation_date").build());
+    context.execute(builder.build());
+       /*
+        "UUID VARCHAR(40) NOT NULL",
+        "KEE VARCHAR(50)",
+        "ISSUE_KEY VARCHAR(50) NOT NULL",
+        "USER_LOGIN VARCHAR(255)",
+        "CHANGE_TYPE VARCHAR(20)",
+        "CHANGE_DATA CLOB(2147483647)",
+        "CREATED_AT BIGINT",
+        "UPDATED_AT BIGINT",
+        "ISSUE_CHANGE_CREATION_DATE BIGINT"
+        */
+  }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/DropIdColumnOfIssueChangesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/DropIdColumnOfIssueChangesTable.java
deleted file mode 100644 (file)
index 3855775..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * 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.v84.issuechanges;
-
-import org.sonar.db.Database;
-import org.sonar.server.platform.db.migration.version.v84.common.DropIdColumn;
-
-public class DropIdColumnOfIssueChangesTable extends DropIdColumn {
-  private static final String TABLE = "issue_changes";
-
-  public DropIdColumnOfIssueChangesTable(Database db) {
-    super(db, TABLE);
-  }
-}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/DropIssueChangesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/DropIssueChangesTable.java
new file mode 100644 (file)
index 0000000..7584e1f
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * 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.v84.issuechanges;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.DropTableBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+public class DropIssueChangesTable extends DdlChange {
+  public DropIssueChangesTable(Database db) {
+    super(db);
+  }
+
+  @Override public void execute(Context context) throws SQLException {
+    context.execute(new DropTableBuilder(getDialect(), "issue_changes").build());
+  }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/DropPrimaryKeyOnIdColumnOfIssueChangesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/DropPrimaryKeyOnIdColumnOfIssueChangesTable.java
deleted file mode 100644 (file)
index 99e8371..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * 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.v84.issuechanges;
-
-import org.sonar.db.Database;
-import org.sonar.server.platform.db.migration.version.v84.common.DropPrimaryKeyOnIdColumn;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
-
-public class DropPrimaryKeyOnIdColumnOfIssueChangesTable extends DropPrimaryKeyOnIdColumn {
-  private static final String TABLE_NAME = "issue_changes";
-
-  public DropPrimaryKeyOnIdColumnOfIssueChangesTable(Database db, DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator) {
-    super(db, dropPrimaryKeySqlGenerator, TABLE_NAME);
-  }
-}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/MakeIssueChangesUuidColumnNotNullable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/MakeIssueChangesUuidColumnNotNullable.java
deleted file mode 100644 (file)
index 3482137..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * 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.v84.issuechanges;
-
-import org.sonar.db.Database;
-import org.sonar.server.platform.db.migration.version.v84.common.MakeUuidColumnNotNullable;
-
-public class MakeIssueChangesUuidColumnNotNullable extends MakeUuidColumnNotNullable {
-  private static final String TABLE = "issue_changes";
-
-  public MakeIssueChangesUuidColumnNotNullable(Database db) {
-    super(db, TABLE);
-  }
-}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/PopulateIssueChangesUuid.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/PopulateIssueChangesUuid.java
deleted file mode 100644 (file)
index d965a14..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * 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.v84.issuechanges;
-
-import java.sql.SQLException;
-import org.sonar.core.util.UuidFactory;
-import org.sonar.db.Database;
-import org.sonar.server.platform.db.migration.step.DataChange;
-import org.sonar.server.platform.db.migration.step.MassUpdate;
-
-public class PopulateIssueChangesUuid extends DataChange {
-
-  private final UuidFactory uuidFactory;
-
-  public PopulateIssueChangesUuid(Database db, UuidFactory uuidFactory) {
-    super(db);
-    this.uuidFactory = uuidFactory;
-  }
-
-  @Override
-  protected void execute(Context context) throws SQLException {
-    MassUpdate massUpdate = context.prepareMassUpdate();
-
-    massUpdate.select("select id from issue_changes where uuid is null");
-    massUpdate.update("update issue_changes set uuid = ? where id = ?");
-
-    massUpdate.execute((row, update) -> {
-      update.setString(1, uuidFactory.create());
-      update.setLong(2, row.getLong(1));
-      return true;
-    });
-  }
-}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/RenameIssueChangesCopyToIssueChanges.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/RenameIssueChangesCopyToIssueChanges.java
new file mode 100644 (file)
index 0000000..5f9d698
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * 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.v84.issuechanges;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.RenameTableBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+public class RenameIssueChangesCopyToIssueChanges extends DdlChange {
+  public RenameIssueChangesCopyToIssueChanges(Database db) {
+    super(db);
+  }
+
+  @Override public void execute(Context context) throws SQLException {
+    context.execute(new RenameTableBuilder(getDialect())
+      .setName("issue_changes_copy")
+      .setNewName("issue_changes")
+      .setAutoGeneratedId(false)
+      .build());
+  }
+}
index 71d552a0b21279c25d4bfcee25a7a1c28e1ccc98..9210d878ee283d22545d7b8f9f5708faf82068b6 100644 (file)
@@ -25,6 +25,7 @@ import org.sonar.server.platform.db.migration.step.DdlChange;
 import org.sonar.server.platform.db.migration.version.v84.util.AddPrimaryKeyBuilder;
 
 public class AddPrimaryKeyOnKeeColumnOfIssuesTable extends DdlChange {
+  private static final String TABLE_NAME = "issues";
 
   public AddPrimaryKeyOnKeeColumnOfIssuesTable(Database db) {
     super(db);
@@ -32,7 +33,7 @@ public class AddPrimaryKeyOnKeeColumnOfIssuesTable extends DdlChange {
 
   @Override
   public void execute(Context context) throws SQLException {
-    context.execute(new AddPrimaryKeyBuilder("issues", "kee").build());
+    context.execute(new AddPrimaryKeyBuilder(TABLE_NAME, "kee").build());
   }
 
 }
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/issues/DropIdColumnOfIssuesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/issues/DropIdColumnOfIssuesTable.java
deleted file mode 100644 (file)
index 22726ff..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * 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.v84.issues;
-
-import org.sonar.db.Database;
-import org.sonar.server.platform.db.migration.version.v84.common.DropIdColumn;
-
-public class DropIdColumnOfIssuesTable extends DropIdColumn {
-  private static final String TABLE = "issues";
-
-  public DropIdColumnOfIssuesTable(Database db) {
-    super(db, TABLE);
-  }
-}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/issues/DropPrimaryKeyOnIdColumnOfIssuesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/issues/DropPrimaryKeyOnIdColumnOfIssuesTable.java
deleted file mode 100644 (file)
index 59427ac..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * 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.v84.issues;
-
-import org.sonar.db.Database;
-import org.sonar.server.platform.db.migration.version.v84.common.DropPrimaryKeyOnIdColumn;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
-
-public class DropPrimaryKeyOnIdColumnOfIssuesTable extends DropPrimaryKeyOnIdColumn {
-  private static final String TABLE_NAME = "issues";
-
-  public DropPrimaryKeyOnIdColumnOfIssuesTable(Database db, DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator) {
-    super(db, dropPrimaryKeySqlGenerator, TABLE_NAME);
-  }
-}
index 55579431c54b3365e58b6c48d37518b530088c11..132769bba16618a0779a53a6e0dcbc1e9bafe398 100644 (file)
 package org.sonar.server.platform.db.migration.version.v84.metrics;
 
 import java.sql.SQLException;
-import org.sonar.core.util.UuidFactory;
 import org.sonar.db.Database;
 import org.sonar.server.platform.db.migration.step.DataChange;
 import org.sonar.server.platform.db.migration.step.MassUpdate;
 
 public class PopulateMetricsUuid extends DataChange {
-
-  private final UuidFactory uuidFactory;
-
-  public PopulateMetricsUuid(Database db, UuidFactory uuidFactory) {
+  public PopulateMetricsUuid(Database db) {
     super(db);
-    this.uuidFactory = uuidFactory;
   }
 
   @Override
@@ -42,8 +37,9 @@ public class PopulateMetricsUuid extends DataChange {
     massUpdate.update("update metrics set uuid = ? where id = ?");
 
     massUpdate.execute((row, update) -> {
-      update.setString(1, uuidFactory.create());
-      update.setLong(2, row.getLong(1));
+      long id = row.getLong(1);
+      update.setString(1, Long.toString(id));
+      update.setLong(2, id);
       return true;
     });
   }
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/AddIndexOnProjectUuidOfLiveMeasuresTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/AddIndexOnProjectUuidOfLiveMeasuresTable.java
new file mode 100644 (file)
index 0000000..0a25794
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ * 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.v84.metrics.livemeasures;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.db.DatabaseUtils;
+import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
+import org.sonar.server.platform.db.migration.sql.CreateIndexBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
+
+public class AddIndexOnProjectUuidOfLiveMeasuresTable extends DdlChange {
+  private static final String TABLE_NAME = "live_measures";
+  private static final String INDEX_NAME = "live_measures_project";
+
+  public AddIndexOnProjectUuidOfLiveMeasuresTable(Database db) {
+    super(db);
+  }
+
+  @Override
+  public void execute(Context context) throws SQLException {
+    if (!indexExists()) {
+      context.execute(new CreateIndexBuilder()
+        .setUnique(false)
+        .setTable(TABLE_NAME)
+        .setName(INDEX_NAME)
+        .addColumn(newVarcharColumnDefBuilder()
+          .setColumnName("project_uuid")
+          .setIsNullable(false)
+          .setLimit(VarcharColumnDef.UUID_SIZE)
+          .build())
+        .build());
+    }
+  }
+
+  private boolean indexExists() throws SQLException {
+    try (Connection connection = getDatabase().getDataSource().getConnection()) {
+      return DatabaseUtils.indexExists(TABLE_NAME, INDEX_NAME, connection);
+    }
+  }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/AddMetricUuidColumnToLiveMeasures.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/AddMetricUuidColumnToLiveMeasures.java
deleted file mode 100644 (file)
index bd0a548..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * 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.v84.metrics.livemeasures;
-
-import java.sql.SQLException;
-import org.sonar.db.Database;
-import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
-import org.sonar.server.platform.db.migration.sql.AddColumnsBuilder;
-import org.sonar.server.platform.db.migration.step.DdlChange;
-
-import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
-
-public class AddMetricUuidColumnToLiveMeasures extends DdlChange {
-  private static final String TABLE = "live_measures";
-
-  private static final VarcharColumnDef uuidColumnDefinition = newVarcharColumnDefBuilder()
-    .setColumnName("metric_uuid")
-    .setIsNullable(true)
-    .setDefaultValue(null)
-    .setLimit(VarcharColumnDef.UUID_SIZE)
-    .build();
-
-  public AddMetricUuidColumnToLiveMeasures(Database db) {
-    super(db);
-  }
-
-  @Override
-  public void execute(Context context) throws SQLException {
-    context.execute(new AddColumnsBuilder(getDialect(), TABLE)
-      .addColumn(uuidColumnDefinition)
-      .build());
-  }
-}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/AddPKeyOnUuidOfLiveMeasuresTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/AddPKeyOnUuidOfLiveMeasuresTable.java
new file mode 100644 (file)
index 0000000..b1fefef
--- /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.v84.metrics.livemeasures;
+
+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.v84.util.AddPrimaryKeyBuilder;
+
+public class AddPKeyOnUuidOfLiveMeasuresTable extends DdlChange {
+  private static final String TABLE_NAME = "live_measures";
+
+  public AddPKeyOnUuidOfLiveMeasuresTable(Database db) {
+    super(db);
+  }
+
+  @Override
+  public void execute(Context context) throws SQLException {
+    context.execute(new AddPrimaryKeyBuilder(TABLE_NAME, "uuid").build());
+  }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/CopyLiveMeasuresTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/CopyLiveMeasuresTable.java
new file mode 100644 (file)
index 0000000..380469e
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ * 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.v84.metrics.livemeasures;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
+import org.sonar.server.platform.db.migration.sql.CreateTableAsBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.sonar.server.platform.db.migration.def.BigIntegerColumnDef.newBigIntegerColumnDefBuilder;
+import static org.sonar.server.platform.db.migration.def.BlobColumnDef.newBlobColumnDefBuilder;
+import static org.sonar.server.platform.db.migration.def.DecimalColumnDef.newDecimalColumnDefBuilder;
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
+
+public class CopyLiveMeasuresTable extends DdlChange {
+  public CopyLiveMeasuresTable(Database db) {
+    super(db);
+  }
+
+  @Override public void execute(Context context) throws SQLException {
+    CreateTableAsBuilder builder = new CreateTableAsBuilder(getDialect(), "live_measures_copy", "live_measures")
+      // this will cause the following changes:
+      // * Add METRIC_UUID with values in METRIC_ID casted to varchar
+      .addColumn(newVarcharColumnDefBuilder().setColumnName("uuid").setLimit(VarcharColumnDef.UUID_SIZE).setIsNullable(false).build())
+      .addColumn(newVarcharColumnDefBuilder().setColumnName("project_uuid").setLimit(50).setIsNullable(false).build())
+      .addColumn(newVarcharColumnDefBuilder().setColumnName("component_uuid").setLimit(50).setIsNullable(false).build())
+      .addColumnWithCast(newVarcharColumnDefBuilder().setColumnName("metric_uuid").setLimit(40).setIsNullable(false).build(), "metric_id")
+      .addColumn(newDecimalColumnDefBuilder().setColumnName("value").build())
+      .addColumn(newVarcharColumnDefBuilder().setColumnName("text_value").setLimit(4000).build())
+      .addColumn(newDecimalColumnDefBuilder().setColumnName("variation").build())
+      .addColumn(newBlobColumnDefBuilder().setColumnName("measure_data").build())
+      .addColumn(newVarcharColumnDefBuilder().setColumnName("update_marker").setLimit(VarcharColumnDef.UUID_SIZE).build())
+      .addColumn(newBigIntegerColumnDefBuilder().setColumnName("created_at").setIsNullable(false).build())
+      .addColumn(newBigIntegerColumnDefBuilder().setColumnName("updated_at").setIsNullable(false).build());
+    context.execute(builder.build());
+
+    /*
+     *         "UUID VARCHAR(40) NOT NULL",
+     *         "PROJECT_UUID VARCHAR(50) NOT NULL",
+     *         "COMPONENT_UUID VARCHAR(50) NOT NULL",
+     *         "METRIC_UUID VARCHAR(40) NOT NULL",
+     *         "VALUE DOUBLE",
+     *         "TEXT_VALUE VARCHAR(4000)",
+     *         "VARIATION DOUBLE",
+     *         "MEASURE_DATA BLOB",
+     *         "UPDATE_MARKER VARCHAR(40)",
+     *         "CREATED_AT BIGINT NOT NULL",
+     *         "UPDATED_AT BIGINT NOT NULL"
+     */
+  }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/DropIndexOnMetricIdOfLiveMeasuresTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/DropIndexOnMetricIdOfLiveMeasuresTable.java
deleted file mode 100644 (file)
index 08b63ea..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * 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.v84.metrics.livemeasures;
-
-import java.sql.Connection;
-import java.sql.SQLException;
-import org.sonar.db.Database;
-import org.sonar.db.DatabaseUtils;
-import org.sonar.server.platform.db.migration.sql.DropIndexBuilder;
-import org.sonar.server.platform.db.migration.step.DdlChange;
-
-public class DropIndexOnMetricIdOfLiveMeasuresTable extends DdlChange {
-  private static final String TABLE_NAME = "live_measures";
-  private static final String INDEX_NAME = "live_measures_component";
-
-  public DropIndexOnMetricIdOfLiveMeasuresTable(Database db) {
-    super(db);
-  }
-
-  @Override
-  public void execute(Context context) throws SQLException {
-    if (indexExists()) {
-      context.execute(new DropIndexBuilder(getDialect())
-        .setTable(TABLE_NAME)
-        .setName(INDEX_NAME)
-        .build());
-    }
-  }
-
-  private boolean indexExists() throws SQLException {
-    try (Connection connection = getDatabase().getDataSource().getConnection()) {
-      return DatabaseUtils.indexExists(TABLE_NAME, INDEX_NAME, connection);
-    }
-  }
-}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/DropLiveMeasuresTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/DropLiveMeasuresTable.java
new file mode 100644 (file)
index 0000000..db77363
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * 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.v84.metrics.livemeasures;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.DropTableBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+public class DropLiveMeasuresTable extends DdlChange {
+  public DropLiveMeasuresTable(Database db) {
+    super(db);
+  }
+
+  @Override public void execute(Context context) throws SQLException {
+    context.execute(new DropTableBuilder(getDialect(), "live_measures").build());
+  }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/DropMetricIdColumnOfLiveMeasuresTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/DropMetricIdColumnOfLiveMeasuresTable.java
deleted file mode 100644 (file)
index 708532d..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * 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.v84.metrics.livemeasures;
-
-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 DropMetricIdColumnOfLiveMeasuresTable extends DdlChange {
-  public DropMetricIdColumnOfLiveMeasuresTable(Database db) {
-    super(db);
-  }
-
-  @Override
-  public void execute(Context context) throws SQLException {
-    context.execute(new DropColumnsBuilder(getDialect(), "live_measures", "metric_id").build());
-  }
-}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/MakeLiveMeasuresMetricUuidNotNullable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/MakeLiveMeasuresMetricUuidNotNullable.java
deleted file mode 100644 (file)
index 11b72b2..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * 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.v84.metrics.livemeasures;
-
-import java.sql.SQLException;
-import org.sonar.db.Database;
-import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
-import org.sonar.server.platform.db.migration.sql.AlterColumnsBuilder;
-import org.sonar.server.platform.db.migration.step.DdlChange;
-
-import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
-
-public class MakeLiveMeasuresMetricUuidNotNullable extends DdlChange {
-  private static final String TABLE = "live_measures";
-
-  private static final VarcharColumnDef uuidColumnDefinition = newVarcharColumnDefBuilder()
-    .setColumnName("metric_uuid")
-    .setIsNullable(false)
-    .setDefaultValue(null)
-    .setLimit(VarcharColumnDef.UUID_SIZE)
-    .build();
-
-  public MakeLiveMeasuresMetricUuidNotNullable(Database db) {
-    super(db);
-  }
-
-  @Override
-  public void execute(Context context) throws SQLException {
-    context.execute(new AlterColumnsBuilder(getDialect(), TABLE)
-      .updateColumn(uuidColumnDefinition)
-      .build());
-  }
-}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/PopulateLiveMeasuresMetricUuid.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/PopulateLiveMeasuresMetricUuid.java
deleted file mode 100644 (file)
index 7170806..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * 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.v84.metrics.livemeasures;
-
-import java.sql.SQLException;
-import org.sonar.db.Database;
-import org.sonar.server.platform.db.migration.step.DataChange;
-import org.sonar.server.platform.db.migration.step.MassUpdate;
-
-public class PopulateLiveMeasuresMetricUuid extends DataChange {
-
-  public PopulateLiveMeasuresMetricUuid(Database db) {
-    super(db);
-  }
-
-  @Override
-  protected void execute(Context context) throws SQLException {
-    MassUpdate  massUpdate = context.prepareMassUpdate();
-
-    massUpdate.select("select lm.uuid, m.uuid " +
-      "from live_measures lm " +
-      "join metrics m on lm.metric_id = m.id");
-
-    massUpdate.update("update live_measures set metric_uuid = ? where uuid = ?");
-
-    massUpdate.execute((row, update) -> {
-      update.setString(1, row.getString(2));
-      update.setString(2, row.getString(1));
-      return true;
-    });
-
-    massUpdate = context.prepareMassUpdate();
-
-    massUpdate.select("select uuid from live_measures where metric_uuid is null");
-    massUpdate.update("delete from live_measures where uuid = ?");
-
-    massUpdate.execute((row, update) -> {
-      update.setString(1, row.getString(1));
-      return true;
-    });
-  }
-}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/RenameLiveMeasuresCopyToLiveMeasures.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/RenameLiveMeasuresCopyToLiveMeasures.java
new file mode 100644 (file)
index 0000000..4758826
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * 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.v84.metrics.livemeasures;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.RenameTableBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+public class RenameLiveMeasuresCopyToLiveMeasures extends DdlChange {
+  public RenameLiveMeasuresCopyToLiveMeasures(Database db) {
+    super(db);
+  }
+
+  @Override public void execute(Context context) throws SQLException {
+    context.execute(new RenameTableBuilder(getDialect())
+      .setName("live_measures_copy")
+      .setNewName("live_measures")
+      .setAutoGeneratedId(false)
+      .build());
+  }
+}
index b21c99813f290923ff809def811b6e62931f2710..d889e1c7cfc0ec59115d5d166ed18a0e99859d0b 100644 (file)
 package org.sonar.server.platform.db.migration.version.v84.rules;
 
 import java.sql.SQLException;
-import org.sonar.core.util.UuidFactory;
 import org.sonar.db.Database;
 import org.sonar.server.platform.db.migration.step.DataChange;
 import org.sonar.server.platform.db.migration.step.MassUpdate;
 
 public class PopulateRulesUuid extends DataChange {
-
-  private final UuidFactory uuidFactory;
-
-  public PopulateRulesUuid(Database db, UuidFactory uuidFactory) {
+  public PopulateRulesUuid(Database db) {
     super(db);
-    this.uuidFactory = uuidFactory;
   }
 
   @Override
@@ -42,8 +37,9 @@ public class PopulateRulesUuid extends DataChange {
     massUpdate.update("update rules set uuid = ? where id = ?");
 
     massUpdate.execute((row, update) -> {
-      update.setString(1, uuidFactory.create());
-      update.setLong(2, row.getLong(1));
+      long id = row.getLong(1);
+      update.setString(1, Long.toString(id));
+      update.setLong(2, id);
       return true;
     });
   }
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/AddIndexToIssuesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/AddIndexToIssuesTable.java
deleted file mode 100644 (file)
index 91d8ba9..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * 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.v84.rules.issues;
-
-import java.sql.Connection;
-import java.sql.SQLException;
-import org.sonar.db.Database;
-import org.sonar.db.DatabaseUtils;
-import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
-import org.sonar.server.platform.db.migration.sql.CreateIndexBuilder;
-import org.sonar.server.platform.db.migration.step.DdlChange;
-
-import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
-
-public class AddIndexToIssuesTable extends DdlChange {
-  private static final String TABLE = "issues";
-  private static final String INDEX_NAME = "issues_rule_uuid";
-
-  private static final VarcharColumnDef uuidColumnDefinition = newVarcharColumnDefBuilder()
-    .setColumnName("rule_uuid")
-    .setIsNullable(true)
-    .setLimit(VarcharColumnDef.UUID_SIZE)
-    .build();
-
-  public AddIndexToIssuesTable(Database db) {
-    super(db);
-  }
-
-  @Override
-  public void execute(Context context) throws SQLException {
-    if (!indexExists()) {
-      context.execute(new CreateIndexBuilder()
-        .setTable(TABLE)
-        .setName(INDEX_NAME)
-        .addColumn(uuidColumnDefinition)
-        .build());
-    }
-  }
-
-  private boolean indexExists() throws SQLException {
-    try (Connection connection = getDatabase().getDataSource().getConnection()) {
-      return DatabaseUtils.indexExists(TABLE, INDEX_NAME, connection);
-    }
-  }
-}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/AddIndexesToIssuesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/AddIndexesToIssuesTable.java
new file mode 100644 (file)
index 0000000..f0f8aa5
--- /dev/null
@@ -0,0 +1,105 @@
+/*
+ * 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.v84.rules.issues;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.db.DatabaseUtils;
+import org.sonar.server.platform.db.migration.sql.CreateIndexBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+public class AddIndexesToIssuesTable extends DdlChange {
+  private static final String TABLE = "issues";
+
+  public AddIndexesToIssuesTable(Database db) {
+    super(db);
+  }
+
+  @Override
+  public void execute(Context context) throws SQLException {
+    if (!indexExists("issues_assignee")) {
+      context.execute(new CreateIndexBuilder()
+        .setTable(TABLE)
+        .setName("issues_assignee")
+        .addColumn("assignee")
+        .build());
+    }
+    if (!indexExists("issues_component_uuid")) {
+
+      context.execute(new CreateIndexBuilder()
+        .setTable(TABLE)
+        .setName("issues_component_uuid")
+        .addColumn("component_uuid")
+        .build());
+    }
+    if (!indexExists("issues_creation_date")) {
+
+      context.execute(new CreateIndexBuilder()
+        .setTable(TABLE)
+        .setName("issues_creation_date")
+        .addColumn("issue_creation_date")
+        .build());
+    }
+    if (!indexExists("issues_kee")) {
+
+      context.execute(new CreateIndexBuilder()
+        .setTable(TABLE)
+        .setName("issues_kee")
+        .setUnique(true)
+        .addColumn("kee")
+        .build());
+    }
+    if (!indexExists("issues_project_uuid")) {
+      context.execute(new CreateIndexBuilder()
+        .setTable(TABLE)
+        .setName("issues_project_uuid")
+        .addColumn("project_uuid")
+        .build());
+    }
+    if (!indexExists("issues_resolution")) {
+      context.execute(new CreateIndexBuilder()
+        .setTable(TABLE)
+        .setName("issues_resolution")
+        .addColumn("resolution")
+        .build());
+    }
+    if (!indexExists("issues_updated_at")) {
+      context.execute(new CreateIndexBuilder()
+        .setTable(TABLE)
+        .setName("issues_updated_at")
+        .addColumn("updated_at")
+        .build());
+    }
+    if (!indexExists("issues_rule_uuid")) {
+      context.execute(new CreateIndexBuilder()
+        .setTable(TABLE)
+        .setName("issues_rule_uuid")
+        .addColumn("rule_uuid")
+        .build());
+    }
+  }
+
+  private boolean indexExists(String name) throws SQLException {
+    try (Connection connection = getDatabase().getDataSource().getConnection()) {
+      return DatabaseUtils.indexExists(TABLE, name, connection);
+    }
+  }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/AddRuleUuidColumnToIssuesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/AddRuleUuidColumnToIssuesTable.java
deleted file mode 100644 (file)
index 037cf2f..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * 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.v84.rules.issues;
-
-import java.sql.SQLException;
-import org.sonar.db.Database;
-import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
-import org.sonar.server.platform.db.migration.sql.AddColumnsBuilder;
-import org.sonar.server.platform.db.migration.step.DdlChange;
-
-import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
-
-public class AddRuleUuidColumnToIssuesTable extends DdlChange {
-  private static final String TABLE = "issues";
-
-  private static final VarcharColumnDef uuidColumnDefinition = newVarcharColumnDefBuilder()
-    .setColumnName("rule_uuid")
-    .setIsNullable(true)
-    .setLimit(VarcharColumnDef.UUID_SIZE)
-    .build();
-
-  public AddRuleUuidColumnToIssuesTable(Database db) {
-    super(db);
-  }
-
-  @Override
-  public void execute(Context context) throws SQLException {
-    context.execute(new AddColumnsBuilder(getDialect(), TABLE)
-      .addColumn(uuidColumnDefinition)
-      .build());
-  }
-}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/CopyIssuesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/CopyIssuesTable.java
new file mode 100644 (file)
index 0000000..324839b
--- /dev/null
@@ -0,0 +1,104 @@
+/*
+ * 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.v84.rules.issues;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.CreateTableAsBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.sonar.server.platform.db.migration.def.BigIntegerColumnDef.newBigIntegerColumnDefBuilder;
+import static org.sonar.server.platform.db.migration.def.BlobColumnDef.newBlobColumnDefBuilder;
+import static org.sonar.server.platform.db.migration.def.BooleanColumnDef.newBooleanColumnDefBuilder;
+import static org.sonar.server.platform.db.migration.def.DecimalColumnDef.newDecimalColumnDefBuilder;
+import static org.sonar.server.platform.db.migration.def.IntegerColumnDef.newIntegerColumnDefBuilder;
+import static org.sonar.server.platform.db.migration.def.TinyIntColumnDef.newTinyIntColumnDefBuilder;
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
+
+public class CopyIssuesTable extends DdlChange {
+  public CopyIssuesTable(Database db) {
+    super(db);
+  }
+
+  @Override public void execute(Context context) throws SQLException {
+    CreateTableAsBuilder builder = new CreateTableAsBuilder(getDialect(), "issues_copy", "issues")
+      // this will cause the following changes:
+      // * Drop ID and RULE_ID
+      // * Add RULE_UUID with values in RULE_ID casted to varchar
+      .addColumn(newVarcharColumnDefBuilder().setColumnName("kee").setLimit(50).setIsNullable(false).build())
+      .addColumnWithCast(newVarcharColumnDefBuilder().setColumnName("rule_uuid").setLimit(40).build(), "rule_id")
+      .addColumn(newVarcharColumnDefBuilder().setColumnName("severity").setLimit(10).build())
+      .addColumn(newBooleanColumnDefBuilder().setColumnName("manual_severity").setIsNullable(false).build())
+      .addColumn(newVarcharColumnDefBuilder().setColumnName("message").setLimit(4000).build())
+      .addColumn(newIntegerColumnDefBuilder().setColumnName("line").build())
+      .addColumn(newDecimalColumnDefBuilder().setColumnName("gap").build())
+      .addColumn(newVarcharColumnDefBuilder().setColumnName("status").setLimit(20).build())
+      .addColumn(newVarcharColumnDefBuilder().setColumnName("resolution").setLimit(20).build())
+      .addColumn(newVarcharColumnDefBuilder().setColumnName("checksum").setLimit(1000).build())
+      .addColumn(newVarcharColumnDefBuilder().setColumnName("reporter").setLimit(255).build())
+      .addColumn(newVarcharColumnDefBuilder().setColumnName("assignee").setLimit(255).build())
+      .addColumn(newVarcharColumnDefBuilder().setColumnName("author_login").setLimit(255).build())
+      .addColumn(newVarcharColumnDefBuilder().setColumnName("action_plan_key").setLimit(50).build())
+      .addColumn(newVarcharColumnDefBuilder().setColumnName("issue_attributes").setLimit(4000).build())
+      .addColumn(newIntegerColumnDefBuilder().setColumnName("effort").build())
+      .addColumn(newBigIntegerColumnDefBuilder().setColumnName("created_at").build())
+      .addColumn(newBigIntegerColumnDefBuilder().setColumnName("updated_at").build())
+      .addColumn(newBigIntegerColumnDefBuilder().setColumnName("issue_creation_date").build())
+      .addColumn(newBigIntegerColumnDefBuilder().setColumnName("issue_update_date").build())
+      .addColumn(newBigIntegerColumnDefBuilder().setColumnName("issue_close_date").build())
+      .addColumn(newVarcharColumnDefBuilder().setColumnName("tags").setLimit(4000).build())
+      .addColumn(newVarcharColumnDefBuilder().setColumnName("component_uuid").setLimit(50).build())
+      .addColumn(newVarcharColumnDefBuilder().setColumnName("project_uuid").setLimit(50).build())
+      .addColumn(newBlobColumnDefBuilder().setColumnName("locations").build())
+      .addColumn(newTinyIntColumnDefBuilder().setColumnName("issue_type").build())
+      .addColumn(newBooleanColumnDefBuilder().setColumnName("from_hotspot").build());
+
+    context.execute(builder.build());
+        /*
+         "KEE VARCHAR(50) NOT NULL",
+         "RULE_UUID VARCHAR(40)",
+         "SEVERITY VARCHAR(10)",
+         "MANUAL_SEVERITY BOOLEAN NOT NULL",
+         "MESSAGE VARCHAR(4000)",
+         "LINE INTEGER",
+         "GAP DOUBLE",
+         "STATUS VARCHAR(20)",
+         "RESOLUTION VARCHAR(20)",
+         "CHECKSUM VARCHAR(1000)",
+         "REPORTER VARCHAR(255)",
+         "ASSIGNEE VARCHAR(255)",
+         "AUTHOR_LOGIN VARCHAR(255)",
+         "ACTION_PLAN_KEY VARCHAR(50)",
+         "ISSUE_ATTRIBUTES VARCHAR(4000)",
+         "EFFORT INTEGER",
+         "CREATED_AT BIGINT",
+         "UPDATED_AT BIGINT",
+         "ISSUE_CREATION_DATE BIGINT",
+         "ISSUE_UPDATE_DATE BIGINT",
+         "ISSUE_CLOSE_DATE BIGINT",
+         "TAGS VARCHAR(4000)",
+         "COMPONENT_UUID VARCHAR(50)",
+         "PROJECT_UUID VARCHAR(50)",
+         "LOCATIONS BLOB",
+         "ISSUE_TYPE TINYINT",
+         "FROM_HOTSPOT BOOLEAN"
+         */
+  }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/DropIndexOnRuleIdColumnOfIssuesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/DropIndexOnRuleIdColumnOfIssuesTable.java
deleted file mode 100644 (file)
index 623e33c..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * 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.v84.rules.issues;
-
-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 DropIndexOnRuleIdColumnOfIssuesTable extends DdlChange {
-
-  public DropIndexOnRuleIdColumnOfIssuesTable(Database db) {
-    super(db);
-  }
-
-  @Override
-  public void execute(Context context) throws SQLException {
-    context.execute(new DropIndexBuilder(getDialect())
-      .setTable("issues")
-      .setName("issues_rule_id")
-      .build());
-  }
-
-}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/DropIssuesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/DropIssuesTable.java
new file mode 100644 (file)
index 0000000..a1d440b
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * 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.v84.rules.issues;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.DropTableBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+public class DropIssuesTable extends DdlChange {
+  public DropIssuesTable(Database db) {
+    super(db);
+  }
+
+  @Override public void execute(Context context) throws SQLException {
+    context.execute(new DropTableBuilder(getDialect(), "issues").build());
+  }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/DropRuleIdColumnOfIssuesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/DropRuleIdColumnOfIssuesTable.java
deleted file mode 100644 (file)
index 18a1e15..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * 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.v84.rules.issues;
-
-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 DropRuleIdColumnOfIssuesTable extends DdlChange {
-
-  public DropRuleIdColumnOfIssuesTable(Database db) {
-    super(db);
-  }
-
-  @Override
-  public void execute(Context context) throws SQLException {
-    context.execute(new DropColumnsBuilder(getDialect(), "issues", "rule_id").build());
-  }
-}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/PopulateIssuesRuleUuidColumn.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/PopulateIssuesRuleUuidColumn.java
deleted file mode 100644 (file)
index fe8ba94..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * 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.v84.rules.issues;
-
-import java.sql.SQLException;
-import org.sonar.db.Database;
-import org.sonar.server.platform.db.migration.step.DataChange;
-import org.sonar.server.platform.db.migration.step.MassUpdate;
-
-public class PopulateIssuesRuleUuidColumn extends DataChange {
-
-  public PopulateIssuesRuleUuidColumn(Database db) {
-    super(db);
-  }
-
-  @Override
-  protected void execute(Context context) throws SQLException {
-    MassUpdate massUpdate = context.prepareMassUpdate();
-
-    massUpdate.select("select iss.kee, ru.uuid " +
-      "from issues iss " +
-      "join rules ru on iss.rule_id = ru.id " +
-      "where iss.rule_uuid is null");
-    massUpdate.update("update issues set rule_uuid = ? where kee = ?");
-
-    massUpdate.execute((row, update) -> {
-      update.setString(1, row.getString(2));
-      update.setString(2, row.getString(1));
-      return true;
-    });
-  }
-}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/RenameIssuesCopyToIssues.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/RenameIssuesCopyToIssues.java
new file mode 100644 (file)
index 0000000..a9147d4
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * 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.v84.rules.issues;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.RenameTableBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+public class RenameIssuesCopyToIssues extends DdlChange {
+  public RenameIssuesCopyToIssues(Database db) {
+    super(db);
+  }
+
+  @Override public void execute(Context context) throws SQLException {
+    context.execute(new RenameTableBuilder(getDialect())
+      .setName("issues_copy")
+      .setNewName("issues")
+      .setAutoGeneratedId(false)
+      .build());
+  }
+}
index d0f6704fc8808a9d9d22f16887f16327848bb5a2..9371374dd670ca30f6ab95d24abab1ffd5f3f8f1 100644 (file)
@@ -134,7 +134,7 @@ public class CreateIndexBuilderTest {
     new CreateIndexBuilder()
       .setTable("issues")
       .setName("issues_key")
-      .addColumn(null)
+      .addColumn((String) null)
       .build();
   }
 
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/sql/CreateTableAsBuilderTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/sql/CreateTableAsBuilderTest.java
new file mode 100644 (file)
index 0000000..8ed75c4
--- /dev/null
@@ -0,0 +1,89 @@
+/*
+ * 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.sql;
+
+import java.util.List;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.sonar.db.dialect.Dialect;
+import org.sonar.db.dialect.H2;
+import org.sonar.db.dialect.MsSql;
+import org.sonar.db.dialect.Oracle;
+import org.sonar.db.dialect.PostgreSql;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
+
+public class CreateTableAsBuilderTest {
+  @Rule
+  public ExpectedException expectedException = ExpectedException.none();
+
+  @Test
+  public void create_table() {
+    String createTableAs = "CREATE TABLE issues_copy (rule_uuid) AS (SELECT rule_uuid FROM issues)";
+    String selectInto = "SELECT rule_uuid INTO issues_copy FROM issues";
+
+    verifySql(new H2(), createTableAs, "ALTER TABLE issues_copy ALTER COLUMN rule_uuid VARCHAR (40) NOT NULL");
+    verifySql(new MsSql(), selectInto, "ALTER TABLE issues_copy ALTER COLUMN rule_uuid NVARCHAR (40) NOT NULL");
+    verifySql(new Oracle(), createTableAs, "ALTER TABLE issues_copy MODIFY (rule_uuid VARCHAR2 (40 CHAR) NOT NULL)");
+    verifySql(new PostgreSql(), createTableAs, "ALTER TABLE issues_copy ALTER COLUMN rule_uuid TYPE VARCHAR (40), ALTER COLUMN rule_uuid SET NOT NULL");
+  }
+
+  @Test
+  public void create_table_with_cast() {
+    verifySqlWithCast(new H2(), "CREATE TABLE issues_copy (rule_uuid) AS (SELECT CAST (rule_id AS VARCHAR (40)) AS rule_uuid FROM issues)",
+      "ALTER TABLE issues_copy ALTER COLUMN rule_uuid VARCHAR (40) NOT NULL");
+    verifySqlWithCast(new MsSql(), "SELECT CAST (rule_id AS NVARCHAR (40)) AS rule_uuid INTO issues_copy FROM issues",
+      "ALTER TABLE issues_copy ALTER COLUMN rule_uuid NVARCHAR (40) NOT NULL");
+    verifySqlWithCast(new Oracle(), "CREATE TABLE issues_copy (rule_uuid) AS (SELECT CAST (rule_id AS VARCHAR2 (40 CHAR)) AS rule_uuid FROM issues)",
+      "ALTER TABLE issues_copy MODIFY (rule_uuid VARCHAR2 (40 CHAR) NOT NULL)");
+    verifySqlWithCast(new PostgreSql(), "CREATE TABLE issues_copy (rule_uuid) AS (SELECT CAST (rule_id AS VARCHAR (40)) AS rule_uuid FROM issues)",
+      "ALTER TABLE issues_copy ALTER COLUMN rule_uuid TYPE VARCHAR (40), ALTER COLUMN rule_uuid SET NOT NULL");
+  }
+
+
+  @Test
+  public void fail_if_columns_not_set() {
+    expectedException.expect(IllegalStateException.class);
+    new CreateTableAsBuilder(new H2(), "issues_copy", "issues")
+      .build();
+  }
+
+  @Test
+  public void fail_if_table_not_set() {
+    expectedException.expect(NullPointerException.class);
+    new CreateTableAsBuilder(new H2(), null, "issues");
+  }
+
+  private static void verifySqlWithCast(Dialect dialect, String... expectedSql) {
+    List<String> actual = new CreateTableAsBuilder(dialect, "issues_copy", "issues")
+      .addColumnWithCast(newVarcharColumnDefBuilder().setColumnName("rule_uuid").setIsNullable(false).setLimit(40).build(), "rule_id")
+      .build();
+    assertThat(actual).containsExactly(expectedSql);
+  }
+
+  private static void verifySql(Dialect dialect, String... expectedSql) {
+    List<String> actual = new CreateTableAsBuilder(dialect, "issues_copy", "issues")
+      .addColumn(newVarcharColumnDefBuilder().setColumnName("rule_uuid").setIsNullable(false).setLimit(40).build())
+      .build();
+    assertThat(actual).containsExactly(expectedSql);
+  }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/AddIndexOnIssueKeyOfIssueChangesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/AddIndexOnIssueKeyOfIssueChangesTableTest.java
new file mode 100644 (file)
index 0000000..307dd0c
--- /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.v84.issuechanges;
+
+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 AddIndexOnIssueKeyOfIssueChangesTableTest {
+  @Rule
+  public CoreDbTester db = CoreDbTester.createForSchema(AddIndexOnIssueKeyOfIssueChangesTableTest.class, "schema.sql");
+
+  private MigrationStep underTest = new AddIndexOnIssueKeyOfIssueChangesTable(db.database());
+
+  @Test
+  public void execute() throws SQLException {
+    underTest.execute();
+
+    db.assertIndex("issue_changes", "issue_changes_issue_key", "issue_key");
+  }
+
+  @Test
+  public void migration_is_re_entrant() throws SQLException {
+    underTest.execute();
+
+    // re-entrant
+    underTest.execute();
+
+    db.assertIndex("issue_changes", "issue_changes_issue_key", "issue_key");
+  }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/AddIndexOnKeeOfIssueChangesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/AddIndexOnKeeOfIssueChangesTableTest.java
new file mode 100644 (file)
index 0000000..0d7aea5
--- /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.v84.issuechanges;
+
+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 AddIndexOnKeeOfIssueChangesTableTest {
+  @Rule
+  public CoreDbTester db = CoreDbTester.createForSchema(AddIndexOnKeeOfIssueChangesTableTest.class, "schema.sql");
+
+  private MigrationStep underTest = new AddIndexOnKeeOfIssueChangesTable(db.database());
+
+  @Test
+  public void execute() throws SQLException {
+    underTest.execute();
+
+    db.assertIndex("issue_changes", "issue_changes_kee", "kee");
+  }
+
+  @Test
+  public void migration_is_re_entrant() throws SQLException {
+    underTest.execute();
+
+    // re-entrant
+    underTest.execute();
+
+    db.assertIndex("issue_changes", "issue_changes_kee", "kee");
+  }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/AddUuidColumnToIssueChangesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/AddUuidColumnToIssueChangesTableTest.java
deleted file mode 100644 (file)
index 3111075..0000000
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * 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.v84.issuechanges;
-
-import java.sql.SQLException;
-import java.sql.Types;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.sonar.core.util.UuidFactoryFast;
-import org.sonar.db.CoreDbTester;
-import org.sonar.server.platform.db.migration.step.DdlChange;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class AddUuidColumnToIssueChangesTableTest {
-
-  @Rule
-  public CoreDbTester db = CoreDbTester.createForSchema(AddUuidColumnToIssueChangesTableTest.class, "schema.sql");
-
-  private DdlChange underTest = new AddUuidColumnToIssueChangesTable(db.database());
-
-  private UuidFactoryFast uuidFactory = UuidFactoryFast.getInstance();
-
-  @Before
-  public void setup() {
-    insertIssueChange(1L);
-    insertIssueChange(2L);
-    insertIssueChange(3L);
-  }
-
-  @Test
-  public void add_uuid_column() throws SQLException {
-    underTest.execute();
-
-    db.assertColumnDefinition("issue_changes", "uuid", Types.VARCHAR, 40, true);
-
-    assertThat(db.countRowsOfTable("issue_changes"))
-      .isEqualTo(3);
-  }
-
-  private void insertIssueChange(Long id) {
-    db.executeInsert("issue_changes",
-      "id", id,
-      "issue_key", uuidFactory.create());
-  }
-
-}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/CopyIssueChangesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/CopyIssueChangesTableTest.java
new file mode 100644 (file)
index 0000000..a196035
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * 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.v84.issuechanges;
+
+import java.sql.JDBCType;
+import java.sql.SQLException;
+import java.sql.Types;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.MigrationStep;
+
+public class CopyIssueChangesTableTest {
+  @Rule
+  public CoreDbTester db = CoreDbTester.createForSchema(CopyIssueChangesTableTest.class, "schema.sql");
+
+  private MigrationStep underTest = new CopyIssueChangesTable(db.database());
+
+  @Test
+  public void execute() throws SQLException {
+    db.assertTableExists("issue_changes");
+    db.assertTableDoesNotExist("issue_changes_copy");
+
+    underTest.execute();
+    db.assertTableExists("issue_changes");
+    db.assertTableExists("issue_changes_copy");
+    db.assertColumnDefinition("issue_changes_copy", "uuid", Types.VARCHAR, 40, false);
+    db.assertColumnDefinition("issue_changes_copy", "issue_key", Types.VARCHAR, 50, false);
+    db.assertColumnDefinition("issue_changes_copy", "updated_at", Types.BIGINT, null, true);
+  }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/DropIdColumnOfIssueChangesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/DropIdColumnOfIssueChangesTableTest.java
deleted file mode 100644 (file)
index 87f32b9..0000000
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * 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.v84.issuechanges;
-
-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.DdlChange;
-
-import static org.assertj.core.api.Assertions.assertThatThrownBy;
-
-public class DropIdColumnOfIssueChangesTableTest {
-
-  @Rule
-  public CoreDbTester db = CoreDbTester.createForSchema(DropIdColumnOfIssueChangesTableTest.class, "schema.sql");
-
-  private DdlChange underTest = new DropIdColumnOfIssueChangesTable(db.database());
-
-  @Test
-  public void execute() throws SQLException {
-    underTest.execute();
-
-    db.assertColumnDoesNotExist("issue_changes", "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/v84/issuechanges/DropIssueChangesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/DropIssueChangesTableTest.java
new file mode 100644 (file)
index 0000000..4a6189d
--- /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.v84.issuechanges;
+
+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 DropIssueChangesTableTest {
+  @Rule
+  public CoreDbTester db = CoreDbTester.createForSchema(DropIssueChangesTableTest.class, "schema.sql");
+
+  private MigrationStep underTest = new DropIssueChangesTable(db.database());
+
+  @Test
+  public void execute() throws SQLException {
+    db.assertTableExists("issue_changes");
+    underTest.execute();
+    db.assertTableDoesNotExist("issue_changes");
+  }
+
+  @Test
+  public void migration_is_re_entrant() throws SQLException {
+    db.assertTableExists("issue_changes");
+
+    underTest.execute();
+
+    // re-entrant
+    underTest.execute();
+    db.assertTableDoesNotExist("issue_changes");
+  }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/DropPrimaryKeyOnIdColumnOfIssueChangesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/DropPrimaryKeyOnIdColumnOfIssueChangesTableTest.java
deleted file mode 100644 (file)
index f72a917..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * 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.v84.issuechanges;
-
-import java.sql.SQLException;
-import org.junit.Rule;
-import org.junit.Test;
-import org.sonar.db.CoreDbTester;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
-import org.sonar.server.platform.db.migration.version.v84.util.SqlHelper;
-
-import static org.assertj.core.api.Assertions.assertThatThrownBy;
-
-public class DropPrimaryKeyOnIdColumnOfIssueChangesTableTest {
-
-  private static final String TABLE_NAME = "issue_changes";
-  @Rule
-  public CoreDbTester db = CoreDbTester.createForSchema(DropPrimaryKeyOnIdColumnOfIssueChangesTableTest.class, "schema.sql");
-
-  private DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new SqlHelper(db.database()));
-
-  private DropPrimaryKeyOnIdColumnOfIssueChangesTable underTest = new DropPrimaryKeyOnIdColumnOfIssueChangesTable(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/v84/issuechanges/MakeIssueChangesUuidColumnNotNullableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/MakeIssueChangesUuidColumnNotNullableTest.java
deleted file mode 100644 (file)
index 1400287..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * 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.v84.issuechanges;
-
-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 java.sql.Types.VARCHAR;
-
-public class MakeIssueChangesUuidColumnNotNullableTest {
-  @Rule
-  public CoreDbTester db = CoreDbTester.createForSchema(MakeIssueChangesUuidColumnNotNullableTest.class, "schema.sql");
-
-  private MigrationStep underTest = new MakeIssueChangesUuidColumnNotNullable(db.database());
-
-  @Test
-  public void uuid_column_is_not_nullable() throws SQLException {
-    underTest.execute();
-
-    db.assertColumnDefinition("issue_changes", "uuid", VARCHAR, null, false);
-  }
-}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/PopulateIssueChangesUuidTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/PopulateIssueChangesUuidTest.java
deleted file mode 100644 (file)
index f1bc280..0000000
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * 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.v84.issuechanges;
-
-import java.sql.SQLException;
-import java.util.Objects;
-import java.util.stream.Collectors;
-import org.junit.Rule;
-import org.junit.Test;
-import org.sonar.core.util.UuidFactory;
-import org.sonar.core.util.UuidFactoryFast;
-import org.sonar.db.CoreDbTester;
-import org.sonar.server.platform.db.migration.step.DataChange;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class PopulateIssueChangesUuidTest {
-
-  @Rule
-  public CoreDbTester db = CoreDbTester.createForSchema(PopulateIssueChangesUuidTest.class, "schema.sql");
-
-  private UuidFactory uuidFactory = UuidFactoryFast.getInstance();
-  private DataChange underTest = new PopulateIssueChangesUuid(db.database(), uuidFactory);
-
-  @Test
-  public void populate_uuids() throws SQLException {
-    insertIssueChange(1L);
-    insertIssueChange(2L);
-    insertIssueChange(3L);
-
-    underTest.execute();
-
-    verifyUuidsAreNotNull();
-  }
-
-  @Test
-  public void migration_is_reentrant() throws SQLException {
-    insertIssueChange(1L);
-    insertIssueChange(2L);
-    insertIssueChange(3L);
-
-    underTest.execute();
-    // re-entrant
-    underTest.execute();
-
-    verifyUuidsAreNotNull();
-  }
-
-  private void verifyUuidsAreNotNull() {
-    assertThat(db.select("select uuid from issue_changes")
-      .stream()
-      .map(row -> row.get("UUID"))
-      .filter(Objects::isNull)
-      .collect(Collectors.toList())).isEmpty();
-  }
-
-  private void insertIssueChange(Long id) {
-    db.executeInsert("issue_changes",
-      "id", id,
-      "uuid", uuidFactory.create(),
-      "issue_key", uuidFactory.create());
-  }
-}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/RenameIssueChangesCopyToIssueChangesTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/RenameIssueChangesCopyToIssueChangesTest.java
new file mode 100644 (file)
index 0000000..f383c46
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * 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.v84.issuechanges;
+
+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 RenameIssueChangesCopyToIssueChangesTest {
+  @Rule
+  public CoreDbTester db = CoreDbTester.createForSchema(RenameIssueChangesCopyToIssueChangesTest.class, "schema.sql");
+
+  private MigrationStep underTest = new RenameIssueChangesCopyToIssueChanges(db.database());
+
+  @Test
+  public void execute() throws SQLException {
+    db.assertTableExists("issue_changes_copy");
+    db.assertTableDoesNotExist("issue_changes");
+
+    underTest.execute();
+    db.assertTableExists("issue_changes");
+  }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/issues/DropIdColumnOfIssuesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/issues/DropIdColumnOfIssuesTableTest.java
deleted file mode 100644 (file)
index 2bc4ddb..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * 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.v84.issues;
-
-import java.sql.SQLException;
-import org.junit.Rule;
-import org.junit.Test;
-import org.sonar.db.CoreDbTester;
-
-import static org.assertj.core.api.Assertions.assertThatThrownBy;
-
-public class DropIdColumnOfIssuesTableTest {
-
-  @Rule
-  public CoreDbTester db = CoreDbTester.createForSchema(DropIdColumnOfIssuesTableTest.class, "schema.sql");
-
-  private DropIdColumnOfIssuesTable underTest = new DropIdColumnOfIssuesTable(db.database());
-
-  @Test
-  public void execute() throws SQLException {
-    underTest.execute();
-
-    db.assertColumnDoesNotExist("issues", "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/v84/issues/DropPrimaryKeyOnIdColumnOfIssuesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/issues/DropPrimaryKeyOnIdColumnOfIssuesTableTest.java
deleted file mode 100644 (file)
index 19d47da..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * 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.v84.issues;
-
-import java.sql.SQLException;
-import org.junit.Rule;
-import org.junit.Test;
-import org.sonar.db.CoreDbTester;
-import org.sonar.server.platform.db.migration.version.v84.util.DropPrimaryKeySqlGenerator;
-import org.sonar.server.platform.db.migration.version.v84.util.SqlHelper;
-
-import static org.assertj.core.api.Assertions.assertThatThrownBy;
-
-public class DropPrimaryKeyOnIdColumnOfIssuesTableTest {
-
-  private static final String TABLE_NAME = "issues";
-  @Rule
-  public CoreDbTester db = CoreDbTester.createForSchema(DropPrimaryKeyOnIdColumnOfIssuesTableTest.class, "schema.sql");
-
-  private DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new SqlHelper(db.database()));
-
-  private DropPrimaryKeyOnIdColumnOfIssuesTable underTest = new DropPrimaryKeyOnIdColumnOfIssuesTable(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/v84/metrics/PopulateMetricsUuidTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/metrics/PopulateMetricsUuidTest.java
deleted file mode 100644 (file)
index 49d5567..0000000
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * 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.v84.metrics;
-
-import java.sql.SQLException;
-import java.util.Objects;
-import java.util.stream.Collectors;
-import org.junit.Rule;
-import org.junit.Test;
-import org.sonar.core.util.UuidFactory;
-import org.sonar.core.util.UuidFactoryFast;
-import org.sonar.db.CoreDbTester;
-import org.sonar.server.platform.db.migration.step.DataChange;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class PopulateMetricsUuidTest {
-
-  @Rule
-  public CoreDbTester db = CoreDbTester.createForSchema(PopulateMetricsUuidTest.class, "schema.sql");
-
-  private UuidFactory uuidFactory = UuidFactoryFast.getInstance();
-  private DataChange underTest = new PopulateMetricsUuid(db.database(), uuidFactory);
-
-  @Test
-  public void populate_uuids() throws SQLException {
-    insertMetric(1L);
-    insertMetric(2L);
-    insertMetric(3L);
-
-    underTest.execute();
-
-    verifyUuidsAreNotNull();
-  }
-
-  @Test
-  public void migration_is_reentrant() throws SQLException {
-    insertMetric(1L);
-    insertMetric(2L);
-    insertMetric(3L);
-
-    underTest.execute();
-    // re-entrant
-    underTest.execute();
-
-    verifyUuidsAreNotNull();
-  }
-
-  private void verifyUuidsAreNotNull() {
-    assertThat(db.select("select uuid from metrics")
-      .stream()
-      .map(row -> row.get("UUID"))
-      .filter(Objects::isNull)
-      .collect(Collectors.toList())).isEmpty();
-  }
-
-  private void insertMetric(Long id) {
-    db.executeInsert("metrics",
-      "id", id,
-      "name", "name" + id);
-  }
-}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/AddIndexOnProjectUuidOfLiveMeasuresTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/AddIndexOnProjectUuidOfLiveMeasuresTableTest.java
new file mode 100644 (file)
index 0000000..02eaac8
--- /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.v84.metrics.livemeasures;
+
+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 AddIndexOnProjectUuidOfLiveMeasuresTableTest {
+  @Rule
+  public CoreDbTester db = CoreDbTester.createForSchema(AddIndexOnProjectUuidOfLiveMeasuresTableTest.class, "schema.sql");
+
+  private MigrationStep underTest = new AddIndexOnProjectUuidOfLiveMeasuresTable(db.database());
+
+  @Test
+  public void execute() throws SQLException {
+    underTest.execute();
+
+    db.assertIndex("live_measures", "live_measures_project", "project_uuid");
+  }
+
+  @Test
+  public void migration_is_re_entrant() throws SQLException {
+    underTest.execute();
+
+    // re-entrant
+    underTest.execute();
+
+    db.assertIndex("live_measures", "live_measures_project", "project_uuid");
+  }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/AddMetricUuidColumnToLiveMeasuresTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/AddMetricUuidColumnToLiveMeasuresTest.java
deleted file mode 100644 (file)
index cf2a329..0000000
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * 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.v84.metrics.livemeasures;
-
-import java.sql.SQLException;
-import java.sql.Types;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.sonar.db.CoreDbTester;
-import org.sonar.server.platform.db.migration.step.DdlChange;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class AddMetricUuidColumnToLiveMeasuresTest {
-  @Rule
-  public CoreDbTester db = CoreDbTester.createForSchema(AddMetricUuidColumnToLiveMeasuresTest.class, "schema.sql");
-  private DdlChange underTest = new AddMetricUuidColumnToLiveMeasures(db.database());
-
-  @Before
-  public void setup() {
-    insertLiveMeasure(1L);
-    insertLiveMeasure(2L);
-    insertLiveMeasure(3L);
-  }
-
-  @Test
-  public void add_active_rule_uuid_column() throws SQLException {
-    underTest.execute();
-
-    db.assertColumnDefinition("live_measures", "metric_uuid", Types.VARCHAR, 40, true);
-
-    assertThat(db.countRowsOfTable("live_measures"))
-      .isEqualTo(3);
-  }
-
-  private void insertLiveMeasure(Long id) {
-    db.executeInsert("live_measures",
-      "uuid", "uuid" + id,
-      "metric_id", id + 1,
-      "component_uuid", "component" + id,
-      "project_uuid", "project" + id + 2,
-      "created_at", id + 3,
-      "updated_at", id + 4
-    );
-  }
-}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/CopyLiveMeasuresTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/CopyLiveMeasuresTableTest.java
new file mode 100644 (file)
index 0000000..7c3530a
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * 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.v84.metrics.livemeasures;
+
+import java.sql.SQLException;
+import java.sql.Types;
+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.v84.rules.issues.CopyIssuesTable;
+
+public class CopyLiveMeasuresTableTest {
+  @Rule
+  public CoreDbTester db = CoreDbTester.createForSchema(CopyLiveMeasuresTableTest.class, "schema.sql");
+
+  private MigrationStep underTest = new CopyLiveMeasuresTable(db.database());
+
+  @Test
+  public void execute() throws SQLException {
+    db.assertTableExists("live_measures");
+    db.assertTableDoesNotExist("live_measures_copy");
+
+    underTest.execute();
+    db.assertTableExists("live_measures");
+    db.assertTableExists("live_measures_copy");
+    db.assertColumnDefinition("live_measures_copy", "uuid", Types.VARCHAR, 40, false);
+    db.assertColumnDefinition("live_measures_copy", "metric_uuid", Types.VARCHAR, 40, false);
+    db.assertColumnDefinition("live_measures_copy", "measure_data", Types.BLOB, null, true);
+  }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/DropIndexOnMetricIdOfLiveMeasuresTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/DropIndexOnMetricIdOfLiveMeasuresTableTest.java
deleted file mode 100644 (file)
index 042b204..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * 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.v84.metrics.livemeasures;
-
-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 DropIndexOnMetricIdOfLiveMeasuresTableTest {
-
-  @Rule
-  public CoreDbTester db = CoreDbTester.createForSchema(DropIndexOnMetricIdOfLiveMeasuresTableTest.class, "schema.sql");
-
-  private MigrationStep underTest = new DropIndexOnMetricIdOfLiveMeasuresTable(db.database());
-
-  @Test
-  public void execute() throws SQLException {
-    db.assertTableExists("live_measures");
-    db.assertUniqueIndex("live_measures", "live_measures_component", "component_uuid", "metric_id");
-
-    underTest.execute();
-
-    db.assertIndexDoesNotExist("live_measures", "live_measures_component");
-  }
-
-  @Test
-  public void migration_is_re_entrant() throws SQLException {
-    underTest.execute();
-
-    // re-entrant
-    underTest.execute();
-
-    db.assertIndexDoesNotExist("live_measures", "live_measures_component");
-  }
-}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/DropLiveMeasuresTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/DropLiveMeasuresTableTest.java
new file mode 100644 (file)
index 0000000..9e86cda
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * 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.v84.metrics.livemeasures;
+
+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.v84.rules.issues.DropIssuesTable;
+
+public class DropLiveMeasuresTableTest {
+  @Rule
+  public CoreDbTester db = CoreDbTester.createForSchema(DropLiveMeasuresTableTest.class, "schema.sql");
+
+  private MigrationStep underTest = new DropLiveMeasuresTable(db.database());
+
+  @Test
+  public void execute() throws SQLException {
+    db.assertTableExists("live_measures");
+    underTest.execute();
+    db.assertTableDoesNotExist("live_measures");
+  }
+
+  @Test
+  public void migration_is_re_entrant() throws SQLException {
+    db.assertTableExists("live_measures");
+
+    underTest.execute();
+
+    // re-entrant
+    underTest.execute();
+    db.assertTableDoesNotExist("live_measures");
+  }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/DropMetricIdColumnOfLiveMeasuresTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/DropMetricIdColumnOfLiveMeasuresTableTest.java
deleted file mode 100644 (file)
index 2991811..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * 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.v84.metrics.livemeasures;
-
-import java.sql.SQLException;
-import java.sql.Types;
-import org.junit.Rule;
-import org.junit.Test;
-import org.sonar.db.CoreDbTester;
-import org.sonar.server.platform.db.migration.step.DdlChange;
-
-import static org.assertj.core.api.Assertions.assertThatThrownBy;
-
-public class DropMetricIdColumnOfLiveMeasuresTableTest {
-  @Rule
-  public CoreDbTester db = CoreDbTester.createForSchema(DropMetricIdColumnOfLiveMeasuresTableTest.class, "schema.sql");
-
-  private DdlChange underTest = new DropMetricIdColumnOfLiveMeasuresTable(db.database());
-
-  @Test
-  public void execute() throws SQLException {
-    db.assertColumnDefinition("live_measures", "metric_id", Types.INTEGER, null, false);
-    underTest.execute();
-    db.assertColumnDoesNotExist("live_measures", "metric_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/v84/metrics/livemeasures/MakeLiveMeasuresMetricUuidNotNullableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/MakeLiveMeasuresMetricUuidNotNullableTest.java
deleted file mode 100644 (file)
index 136d837..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * 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.v84.metrics.livemeasures;
-
-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 java.sql.Types.VARCHAR;
-
-public class MakeLiveMeasuresMetricUuidNotNullableTest {
-  @Rule
-  public CoreDbTester db = CoreDbTester.createForSchema(MakeLiveMeasuresMetricUuidNotNullableTest.class, "schema.sql");
-
-  private MigrationStep underTest = new MakeLiveMeasuresMetricUuidNotNullable(db.database());
-
-  @Test
-  public void uuid_column_is_not_null() throws SQLException {
-    underTest.execute();
-
-    db.assertColumnDefinition("live_measures", "metric_uuid", VARCHAR, null, false);
-  }
-}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/PopulateLiveMeasuresMetricUuidTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/PopulateLiveMeasuresMetricUuidTest.java
deleted file mode 100644 (file)
index b3c0e3c..0000000
+++ /dev/null
@@ -1,120 +0,0 @@
-/*
- * 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.v84.metrics.livemeasures;
-
-import java.sql.SQLException;
-import java.util.List;
-import java.util.Map;
-import org.assertj.core.groups.Tuple;
-import org.junit.Rule;
-import org.junit.Test;
-import org.sonar.db.CoreDbTester;
-import org.sonar.server.platform.db.migration.step.DataChange;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.tuple;
-
-public class PopulateLiveMeasuresMetricUuidTest {
-  @Rule
-  public CoreDbTester db = CoreDbTester.createForSchema(PopulateLiveMeasuresMetricUuidTest.class, "schema.sql");
-
-  private DataChange underTest = new PopulateLiveMeasuresMetricUuid(db.database());
-
-  @Test
-  public void populate_uuids() throws SQLException {
-    insertMetric(1L);
-    insertMetric(2L);
-    insertMetric(3L);
-
-    insertLiveMeasure(4L, 1L);
-    insertLiveMeasure(5L, 2L);
-    insertLiveMeasure(6L, 3L);
-
-    underTest.execute();
-
-    assertThatTableContains(
-      tuple("uuid4", 1L, "uuid1"),
-      tuple("uuid5", 2L, "uuid2"),
-      tuple("uuid6", 3L, "uuid3")
-    );
-  }
-
-  @Test
-  public void delete_orphan_rows() throws SQLException {
-    insertMetric(1L);
-    insertMetric(2L);
-    insertMetric(3L);
-
-    insertLiveMeasure(4L, 10L);
-    insertLiveMeasure(5L, 2L);
-    insertLiveMeasure(6L, 3L);
-
-    underTest.execute();
-
-    assertThatTableContains(
-      tuple("uuid5", 2L, "uuid2"),
-      tuple("uuid6", 3L, "uuid3")
-    );
-  }
-
-  @Test
-  public void migration_is_reentrant() throws SQLException {
-    insertMetric(1L);
-    insertMetric(2L);
-    insertMetric(3L);
-
-    insertLiveMeasure(4L, 1L);
-    insertLiveMeasure(5L, 2L);
-    insertLiveMeasure(6L, 3L);
-
-    underTest.execute();
-    // re-entrant
-    underTest.execute();
-
-    assertThatTableContains(
-      tuple("uuid4", 1L, "uuid1"),
-      tuple("uuid5", 2L, "uuid2"),
-      tuple("uuid6", 3L, "uuid3")
-    );
-  }
-
-  private void assertThatTableContains(Tuple... tuples) {
-    List<Map<String, Object>> select = db.select("select uuid, metric_id, metric_uuid from live_measures");
-    assertThat(select).extracting(m -> m.get("UUID"), m -> m.get("METRIC_ID"), m -> m.get("METRIC_UUID"))
-      .containsExactlyInAnyOrder(tuples);
-  }
-
-  private void insertMetric(Long id) {
-    db.executeInsert("metrics",
-      "id", id,
-      "uuid", "uuid" + id,
-      "name", "name" + id);
-  }
-
-  private void insertLiveMeasure(Long id, Long metricId) {
-    db.executeInsert("live_measures",
-      "uuid", "uuid" + id,
-      "metric_id", metricId,
-      "component_uuid", "component" + id,
-      "project_uuid", "project" + id + 2,
-      "created_at", id + 3,
-      "updated_at", id + 4);
-  }
-}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/RenameLiveMeasuresCopyToLiveMeasuresTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/RenameLiveMeasuresCopyToLiveMeasuresTest.java
new file mode 100644 (file)
index 0000000..e10abb2
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * 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.v84.metrics.livemeasures;
+
+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.v84.rules.issues.RenameIssuesCopyToIssues;
+
+public class RenameLiveMeasuresCopyToLiveMeasuresTest {
+  @Rule
+  public CoreDbTester db = CoreDbTester.createForSchema(RenameLiveMeasuresCopyToLiveMeasuresTest.class, "schema.sql");
+
+  private MigrationStep underTest = new RenameLiveMeasuresCopyToLiveMeasures(db.database());
+
+  @Test
+  public void execute() throws SQLException {
+    db.assertTableExists("live_measures_copy");
+    db.assertTableDoesNotExist("live_measures");
+
+    underTest.execute();
+    db.assertTableDoesNotExist("live_measures_copy");
+    db.assertTableExists("live_measures");
+
+  }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/rules/PopulateRulesUuidTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/rules/PopulateRulesUuidTest.java
deleted file mode 100644 (file)
index 332b183..0000000
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * 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.v84.rules;
-
-import java.sql.SQLException;
-import java.util.Objects;
-import java.util.stream.Collectors;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.sonar.core.util.UuidFactory;
-import org.sonar.core.util.UuidFactoryFast;
-import org.sonar.db.CoreDbTester;
-import org.sonar.server.platform.db.migration.step.DataChange;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class PopulateRulesUuidTest {
-
-  @Rule
-  public CoreDbTester db = CoreDbTester.createForSchema(PopulateRulesUuidTest.class, "schema.sql");
-
-  private UuidFactory uuidFactory = UuidFactoryFast.getInstance();
-  private DataChange underTest = new PopulateRulesUuid(db.database(), uuidFactory);
-
-  @Before
-  public void setup() {
-    insertRule(1L);
-    insertRule(2L);
-    insertRule(3L);
-    insertRule(4L);
-  }
-
-  @Test
-  public void add_rule_uuid_column() throws SQLException {
-    underTest.execute();
-
-    assertThat(db.countSql("select count(*) from rules"))
-      .isEqualTo(4);
-    assertThat(db.select("select uuid from rules")
-      .stream()
-      .map(row -> row.get("UUID"))
-      .filter(Objects::isNull)
-      .collect(Collectors.toList())).isEmpty();
-  }
-
-  private void insertRule(long id) {
-    db.executeInsert("rules",
-      "id", id,
-      "plugin_rule_key", "rk" + id,
-      "plugin_name", "rn" + id,
-      "scope", "MAIN",
-      "is_ad_hoc", false,
-      "is_external", false);
-  }
-}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/AddIndexToIssuesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/AddIndexToIssuesTableTest.java
deleted file mode 100644 (file)
index 5e132b4..0000000
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * 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.v84.rules.issues;
-
-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 AddIndexToIssuesTableTest {
-
-  @Rule
-  public CoreDbTester db = CoreDbTester.createForSchema(AddIndexToIssuesTableTest.class, "schema.sql");
-
-  private MigrationStep underTest = new AddIndexToIssuesTable(db.database());
-
-  @Test
-  public void execute() throws SQLException {
-    underTest.execute();
-
-    db.assertIndex("issues", "issues_rule_uuid", "rule_uuid");
-  }
-
-  @Test
-  public void migration_is_re_entrant() throws SQLException {
-    underTest.execute();
-
-    // re-entrant
-    underTest.execute();
-
-    db.assertIndex("issues", "issues_rule_uuid", "rule_uuid");
-  }
-}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/AddIndexesToIssuesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/AddIndexesToIssuesTableTest.java
new file mode 100644 (file)
index 0000000..1432a77
--- /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.v84.rules.issues;
+
+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 AddIndexesToIssuesTableTest {
+
+  @Rule
+  public CoreDbTester db = CoreDbTester.createForSchema(AddIndexesToIssuesTableTest.class, "schema.sql");
+
+  private MigrationStep underTest = new AddIndexesToIssuesTable(db.database());
+
+  @Test
+  public void execute() throws SQLException {
+    underTest.execute();
+
+    db.assertIndex("issues", "issues_rule_uuid", "rule_uuid");
+  }
+
+  @Test
+  public void migration_is_re_entrant() throws SQLException {
+    underTest.execute();
+
+    // re-entrant
+    underTest.execute();
+
+    db.assertIndex("issues", "issues_rule_uuid", "rule_uuid");
+  }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/AddRuleUuidColumnToIssuesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/AddRuleUuidColumnToIssuesTableTest.java
deleted file mode 100644 (file)
index 11648e1..0000000
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * 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.v84.rules.issues;
-
-import java.sql.SQLException;
-import java.sql.Types;
-import javax.annotation.Nullable;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.sonar.db.CoreDbTester;
-import org.sonar.server.platform.db.migration.step.DdlChange;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class AddRuleUuidColumnToIssuesTableTest {
-
-  @Rule
-  public CoreDbTester db = CoreDbTester.createForSchema(AddRuleUuidColumnToIssuesTableTest.class, "schema.sql");
-
-  private DdlChange underTest = new AddRuleUuidColumnToIssuesTable(db.database());
-
-  @Before
-  public void setup() {
-    insertRule(1L, "uuid-rule-1");
-    insertRule(2L, "uuid-rule-2");
-    insertRule(3L, "uuid-rule-3");
-    insertRule(4L, "uuid-rule-4");
-
-    insertIssue("kee-iss-1", 1L);
-    insertIssue("kee-iss-2", 1L);
-    insertIssue("kee-iss-3", 2L);
-    insertIssue("kee-iss-4", null);
-    insertIssue("kee-iss-5", null);
-  }
-
-  @Test
-  public void add_rule_uuid_column() throws SQLException {
-    underTest.execute();
-
-    db.assertColumnDefinition("issues", "rule_uuid", Types.VARCHAR, 40, true);
-    assertThat(db.countSql("select count(*) from issues"))
-      .isEqualTo(5);
-  }
-
-  private void insertRule(long id, String uuid) {
-    db.executeInsert("rules",
-      "id", id,
-      "uuid", uuid,
-      "plugin_rule_key", "rk" + id,
-      "plugin_name", "rn" + id,
-      "scope", "MAIN",
-      "is_ad_hoc", false,
-      "is_external", false);
-  }
-
-  private void insertIssue(String kee, @Nullable Long ruleId) {
-    db.executeInsert("issues",
-      "kee", kee,
-      "rule_id", ruleId,
-      "manual_severity", false);
-  }
-
-}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/CopyIssuesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/CopyIssuesTableTest.java
new file mode 100644 (file)
index 0000000..632b04b
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * 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.v84.rules.issues;
+
+import java.sql.SQLException;
+import java.sql.Types;
+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.v84.issuechanges.CopyIssueChangesTable;
+
+public class CopyIssuesTableTest {
+  @Rule
+  public CoreDbTester db = CoreDbTester.createForSchema(CopyIssuesTableTest.class, "schema.sql");
+
+  private MigrationStep underTest = new CopyIssuesTable(db.database());
+
+  @Test
+  public void execute() throws SQLException {
+    db.assertTableExists("issues");
+    db.assertTableDoesNotExist("issues_copy");
+
+    underTest.execute();
+    db.assertTableExists("issues");
+    db.assertTableExists("issues_copy");
+    db.assertColumnDefinition("issues_copy", "kee", Types.VARCHAR, 50, false);
+    db.assertColumnDefinition("issues_copy", "message", Types.VARCHAR, 4000, true);
+    db.assertColumnDefinition("issues_copy", "issue_type", Types.TINYINT, null, true);
+  }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/DropIndexOnRuleIdColumnOfIssuesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/DropIndexOnRuleIdColumnOfIssuesTableTest.java
deleted file mode 100644 (file)
index 0838ca2..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * 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.v84.rules.issues;
-
-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 DropIndexOnRuleIdColumnOfIssuesTableTest {
-
-  @Rule
-  public CoreDbTester db = CoreDbTester.createForSchema(DropIndexOnRuleIdColumnOfIssuesTableTest.class, "schema.sql");
-
-  private MigrationStep underTest = new DropIndexOnRuleIdColumnOfIssuesTable(db.database());
-
-  @Test
-  public void execute() throws SQLException {
-    db.assertTableExists("issues");
-    db.assertIndex("issues", "issues_rule_id", "rule_id");
-
-    underTest.execute();
-
-    db.assertIndexDoesNotExist("issues", "issues_rule_id");
-  }
-
-  @Test
-  public void migration_is_re_entrant() throws SQLException {
-    underTest.execute();
-
-    // re-entrant
-    underTest.execute();
-
-    db.assertIndexDoesNotExist("issues", "issues_rule_id");
-  }
-}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/DropIssuesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/DropIssuesTableTest.java
new file mode 100644 (file)
index 0000000..a407edb
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * 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.v84.rules.issues;
+
+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.v84.issuechanges.DropIssueChangesTable;
+
+public class DropIssuesTableTest {
+  @Rule
+  public CoreDbTester db = CoreDbTester.createForSchema(DropIssuesTableTest.class, "schema.sql");
+
+  private MigrationStep underTest = new DropIssuesTable(db.database());
+
+  @Test
+  public void execute() throws SQLException {
+    db.assertTableExists("issues");
+    underTest.execute();
+    db.assertTableDoesNotExist("issues");
+  }
+
+  @Test
+  public void migration_is_re_entrant() throws SQLException {
+    db.assertTableExists("issues");
+
+    underTest.execute();
+
+    // re-entrant
+    underTest.execute();
+    db.assertTableDoesNotExist("issues");
+  }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/DropRuleIdColumnOfIssuesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/DropRuleIdColumnOfIssuesTableTest.java
deleted file mode 100644 (file)
index 66d1753..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * 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.v84.rules.issues;
-
-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.DdlChange;
-
-import static org.assertj.core.api.Assertions.assertThatThrownBy;
-
-public class DropRuleIdColumnOfIssuesTableTest {
-
-  @Rule
-  public CoreDbTester db = CoreDbTester.createForSchema(DropRuleIdColumnOfIssuesTableTest.class, "schema.sql");
-
-  private DdlChange underTest = new DropRuleIdColumnOfIssuesTable(db.database());
-
-  @Test
-  public void execute() throws SQLException {
-    underTest.execute();
-
-    db.assertColumnDoesNotExist("issues", "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/v84/rules/issues/PopulateIssuesRuleUuidColumnTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/PopulateIssuesRuleUuidColumnTest.java
deleted file mode 100644 (file)
index cc79646..0000000
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * 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.v84.rules.issues;
-
-import java.sql.SQLException;
-import javax.annotation.Nullable;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.sonar.db.CoreDbTester;
-import org.sonar.server.platform.db.migration.step.DataChange;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.tuple;
-
-public class PopulateIssuesRuleUuidColumnTest {
-
-  @Rule
-  public CoreDbTester db = CoreDbTester.createForSchema(PopulateIssuesRuleUuidColumnTest.class, "schema.sql");
-
-  private DataChange underTest = new PopulateIssuesRuleUuidColumn(db.database());
-
-  @Before
-  public void setup() {
-    insertRule(1L, "uuid-rule-1");
-    insertRule(2L, "uuid-rule-2");
-    insertRule(3L, "uuid-rule-3");
-    insertRule(4L, "uuid-rule-4");
-
-    insertIssue("kee-iss-1", 1L);
-    insertIssue("kee-iss-2", 1L);
-    insertIssue("kee-iss-3", 2L);
-    insertIssue("kee-iss-4", null);
-    insertIssue("kee-iss-5", null);
-  }
-
-  @Test
-  public void add_rule_uuid_column() throws SQLException {
-    underTest.execute();
-
-    assertThat(db.countSql("select count(*) from issues")).isEqualTo(5);
-    assertThat(db.select("select kee, rule_id, rule_uuid from issues"))
-      .extracting(m -> m.get("KEE"), m -> m.get("RULE_ID"), m -> m.get("RULE_UUID"))
-      .containsExactlyInAnyOrder(
-        tuple("kee-iss-1", 1L, "uuid-rule-1"),
-        tuple("kee-iss-2", 1L, "uuid-rule-1"),
-        tuple("kee-iss-3", 2L, "uuid-rule-2"),
-        tuple("kee-iss-4", null, null),
-        tuple("kee-iss-5", null, null));
-  }
-
-  private void insertRule(long id, String uuid) {
-    db.executeInsert("rules",
-      "id", id,
-      "uuid", uuid,
-      "plugin_rule_key", "rk" + id,
-      "plugin_name", "rn" + id,
-      "scope", "MAIN",
-      "is_ad_hoc", false,
-      "is_external", false);
-  }
-
-  private void insertIssue(String kee, @Nullable Long ruleId) {
-    db.executeInsert("issues",
-      "kee", kee,
-      "rule_id", ruleId,
-      "manual_severity", false);
-  }
-
-}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/RenameIssuesCopyToIssuesTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/RenameIssuesCopyToIssuesTest.java
new file mode 100644 (file)
index 0000000..ea3c076
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * 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.v84.rules.issues;
+
+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.v84.issuechanges.RenameIssueChangesCopyToIssueChanges;
+
+public class RenameIssuesCopyToIssuesTest {
+  @Rule
+  public CoreDbTester db = CoreDbTester.createForSchema(RenameIssuesCopyToIssuesTest.class, "schema.sql");
+
+  private MigrationStep underTest = new RenameIssuesCopyToIssues(db.database());
+
+  @Test
+  public void execute() throws SQLException {
+    db.assertTableExists("issues_copy");
+    db.assertTableDoesNotExist("issues");
+
+    underTest.execute();
+    db.assertTableDoesNotExist("issues_copy");
+    db.assertTableExists("issues");
+
+  }
+}
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/issuechanges/AddIndexOnIssueKeyOfIssueChangesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/issuechanges/AddIndexOnIssueKeyOfIssueChangesTableTest/schema.sql
new file mode 100644 (file)
index 0000000..93de1f1
--- /dev/null
@@ -0,0 +1,11 @@
+CREATE TABLE "ISSUE_CHANGES"(
+    "UUID" VARCHAR(40) NOT NULL,
+    "KEE" VARCHAR(50),
+    "ISSUE_KEY" VARCHAR(50) NOT NULL,
+    "USER_LOGIN" VARCHAR(255),
+    "CHANGE_TYPE" VARCHAR(20),
+    "CHANGE_DATA" CLOB(2147483647),
+    "CREATED_AT" BIGINT,
+    "UPDATED_AT" BIGINT,
+    "ISSUE_CHANGE_CREATION_DATE" BIGINT
+);
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/issuechanges/AddIndexOnKeeOfIssueChangesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/issuechanges/AddIndexOnKeeOfIssueChangesTableTest/schema.sql
new file mode 100644 (file)
index 0000000..93de1f1
--- /dev/null
@@ -0,0 +1,11 @@
+CREATE TABLE "ISSUE_CHANGES"(
+    "UUID" VARCHAR(40) NOT NULL,
+    "KEE" VARCHAR(50),
+    "ISSUE_KEY" VARCHAR(50) NOT NULL,
+    "USER_LOGIN" VARCHAR(255),
+    "CHANGE_TYPE" VARCHAR(20),
+    "CHANGE_DATA" CLOB(2147483647),
+    "CREATED_AT" BIGINT,
+    "UPDATED_AT" BIGINT,
+    "ISSUE_CHANGE_CREATION_DATE" BIGINT
+);
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/issuechanges/AddUuidColumnToIssueChangesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/issuechanges/AddUuidColumnToIssueChangesTableTest/schema.sql
deleted file mode 100644 (file)
index 6dea8cb..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-CREATE TABLE "ISSUE_CHANGES"(
-    "ID" BIGINT NOT NULL AUTO_INCREMENT (1,1),
-    "KEE" VARCHAR(50),
-    "ISSUE_KEY" VARCHAR(50) NOT NULL,
-    "USER_LOGIN" VARCHAR(255),
-    "CHANGE_TYPE" VARCHAR(20),
-    "CHANGE_DATA" CLOB(2147483647),
-    "CREATED_AT" BIGINT,
-    "UPDATED_AT" BIGINT,
-    "ISSUE_CHANGE_CREATION_DATE" BIGINT
-);
-ALTER TABLE "ISSUE_CHANGES" ADD CONSTRAINT "PK_ISSUE_CHANGES" PRIMARY KEY("ID");
-CREATE INDEX "ISSUE_CHANGES_ISSUE_KEY" ON "ISSUE_CHANGES"("ISSUE_KEY");
-CREATE INDEX "ISSUE_CHANGES_KEE" ON "ISSUE_CHANGES"("KEE");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/issuechanges/CopyIssueChangesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/issuechanges/CopyIssueChangesTableTest/schema.sql
new file mode 100644 (file)
index 0000000..8b3247a
--- /dev/null
@@ -0,0 +1,13 @@
+CREATE TABLE "ISSUE_CHANGES"(
+    "ID" BIGINT NOT NULL AUTO_INCREMENT (1,1),
+    "KEE" VARCHAR(50),
+    "ISSUE_KEY" VARCHAR(50) NOT NULL,
+    "USER_LOGIN" VARCHAR(255),
+    "CHANGE_TYPE" VARCHAR(20),
+    "CHANGE_DATA" CLOB(2147483647),
+    "CREATED_AT" BIGINT,
+    "UPDATED_AT" BIGINT,
+    "ISSUE_CHANGE_CREATION_DATE" BIGINT
+);
+CREATE INDEX "ISSUE_CHANGES_ISSUE_KEY" ON "ISSUE_CHANGES"("ISSUE_KEY");
+CREATE INDEX "ISSUE_CHANGES_KEE" ON "ISSUE_CHANGES"("KEE");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/issuechanges/DropIdColumnOfIssueChangesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/issuechanges/DropIdColumnOfIssueChangesTableTest/schema.sql
deleted file mode 100644 (file)
index 7b26191..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-CREATE TABLE "ISSUE_CHANGES"(
-    "ID" BIGINT NOT NULL AUTO_INCREMENT (1,1),
-    "UUID" VARCHAR(40) NOT NULL,
-    "KEE" VARCHAR(50),
-    "ISSUE_KEY" VARCHAR(50) NOT NULL,
-    "USER_LOGIN" VARCHAR(255),
-    "CHANGE_TYPE" VARCHAR(20),
-    "CHANGE_DATA" CLOB(2147483647),
-    "CREATED_AT" BIGINT,
-    "UPDATED_AT" BIGINT,
-    "ISSUE_CHANGE_CREATION_DATE" BIGINT
-);
-ALTER TABLE "ISSUE_CHANGES" ADD CONSTRAINT "PK_ISSUE_CHANGES" PRIMARY KEY("UUID");
-CREATE INDEX "ISSUE_CHANGES_ISSUE_KEY" ON "ISSUE_CHANGES"("ISSUE_KEY");
-CREATE INDEX "ISSUE_CHANGES_KEE" ON "ISSUE_CHANGES"("KEE");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/issuechanges/DropIssueChangesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/issuechanges/DropIssueChangesTableTest/schema.sql
new file mode 100644 (file)
index 0000000..a188f80
--- /dev/null
@@ -0,0 +1,26 @@
+CREATE TABLE "ISSUE_CHANGES"(
+    "ID" BIGINT NOT NULL AUTO_INCREMENT (1,1),
+    "KEE" VARCHAR(50),
+    "ISSUE_KEY" VARCHAR(50) NOT NULL,
+    "USER_LOGIN" VARCHAR(255),
+    "CHANGE_TYPE" VARCHAR(20),
+    "CHANGE_DATA" CLOB(2147483647),
+    "CREATED_AT" BIGINT,
+    "UPDATED_AT" BIGINT,
+    "ISSUE_CHANGE_CREATION_DATE" BIGINT
+);
+CREATE INDEX "ISSUE_CHANGES_ISSUE_KEY" ON "ISSUE_CHANGES"("ISSUE_KEY");
+CREATE INDEX "ISSUE_CHANGES_KEE" ON "ISSUE_CHANGES"("KEE");
+
+CREATE TABLE "ISSUE_CHANGES_COPY"(
+    "UUID" VARCHAR(40) NOT NULL,
+    "KEE" VARCHAR(50),
+    "ISSUE_KEY" VARCHAR(50) NOT NULL,
+    "USER_LOGIN" VARCHAR(255),
+    "CHANGE_TYPE" VARCHAR(20),
+    "CHANGE_DATA" CLOB(2147483647),
+    "CREATED_AT" BIGINT,
+    "UPDATED_AT" BIGINT,
+    "ISSUE_CHANGE_CREATION_DATE" BIGINT
+);
+
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/issuechanges/DropPrimaryKeyOnIdColumnOfIssueChangesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/issuechanges/DropPrimaryKeyOnIdColumnOfIssueChangesTableTest/schema.sql
deleted file mode 100644 (file)
index e19e269..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-CREATE TABLE "ISSUE_CHANGES"(
-    "ID" BIGINT NOT NULL AUTO_INCREMENT (1,1),
-    "UUID" VARCHAR(40) NOT NULL,
-    "KEE" VARCHAR(50),
-    "ISSUE_KEY" VARCHAR(50) NOT NULL,
-    "USER_LOGIN" VARCHAR(255),
-    "CHANGE_TYPE" VARCHAR(20),
-    "CHANGE_DATA" CLOB(2147483647),
-    "CREATED_AT" BIGINT,
-    "UPDATED_AT" BIGINT,
-    "ISSUE_CHANGE_CREATION_DATE" BIGINT
-);
-ALTER TABLE "ISSUE_CHANGES" ADD CONSTRAINT "PK_ISSUE_CHANGES" PRIMARY KEY("ID");
-CREATE INDEX "ISSUE_CHANGES_ISSUE_KEY" ON "ISSUE_CHANGES"("ISSUE_KEY");
-CREATE INDEX "ISSUE_CHANGES_KEE" ON "ISSUE_CHANGES"("KEE");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/issuechanges/MakeIssueChangesUuidColumnNotNullableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/issuechanges/MakeIssueChangesUuidColumnNotNullableTest/schema.sql
deleted file mode 100644 (file)
index f48647d..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-CREATE TABLE "ISSUE_CHANGES"(
-    "ID" BIGINT NOT NULL AUTO_INCREMENT (1,1),
-    "UUID" VARCHAR(40),
-    "KEE" VARCHAR(50),
-    "ISSUE_KEY" VARCHAR(50) NOT NULL,
-    "USER_LOGIN" VARCHAR(255),
-    "CHANGE_TYPE" VARCHAR(20),
-    "CHANGE_DATA" CLOB(2147483647),
-    "CREATED_AT" BIGINT,
-    "UPDATED_AT" BIGINT,
-    "ISSUE_CHANGE_CREATION_DATE" BIGINT
-);
-ALTER TABLE "ISSUE_CHANGES" ADD CONSTRAINT "PK_ISSUE_CHANGES" PRIMARY KEY("ID");
-CREATE INDEX "ISSUE_CHANGES_ISSUE_KEY" ON "ISSUE_CHANGES"("ISSUE_KEY");
-CREATE INDEX "ISSUE_CHANGES_KEE" ON "ISSUE_CHANGES"("KEE");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/issuechanges/PopulateIssueChangesUuidTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/issuechanges/PopulateIssueChangesUuidTest/schema.sql
deleted file mode 100644 (file)
index f48647d..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-CREATE TABLE "ISSUE_CHANGES"(
-    "ID" BIGINT NOT NULL AUTO_INCREMENT (1,1),
-    "UUID" VARCHAR(40),
-    "KEE" VARCHAR(50),
-    "ISSUE_KEY" VARCHAR(50) NOT NULL,
-    "USER_LOGIN" VARCHAR(255),
-    "CHANGE_TYPE" VARCHAR(20),
-    "CHANGE_DATA" CLOB(2147483647),
-    "CREATED_AT" BIGINT,
-    "UPDATED_AT" BIGINT,
-    "ISSUE_CHANGE_CREATION_DATE" BIGINT
-);
-ALTER TABLE "ISSUE_CHANGES" ADD CONSTRAINT "PK_ISSUE_CHANGES" PRIMARY KEY("ID");
-CREATE INDEX "ISSUE_CHANGES_ISSUE_KEY" ON "ISSUE_CHANGES"("ISSUE_KEY");
-CREATE INDEX "ISSUE_CHANGES_KEE" ON "ISSUE_CHANGES"("KEE");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/issuechanges/RenameIssueChangesCopyToIssueChangesTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/issuechanges/RenameIssueChangesCopyToIssueChangesTest/schema.sql
new file mode 100644 (file)
index 0000000..051df21
--- /dev/null
@@ -0,0 +1,11 @@
+CREATE TABLE "ISSUE_CHANGES_COPY"(
+    "UUID" VARCHAR(40) NOT NULL,
+    "KEE" VARCHAR(50),
+    "ISSUE_KEY" VARCHAR(50) NOT NULL,
+    "USER_LOGIN" VARCHAR(255),
+    "CHANGE_TYPE" VARCHAR(20),
+    "CHANGE_DATA" CLOB(2147483647),
+    "CREATED_AT" BIGINT,
+    "UPDATED_AT" BIGINT,
+    "ISSUE_CHANGE_CREATION_DATE" BIGINT
+);
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/issues/DropIdColumnOfIssuesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/issues/DropIdColumnOfIssuesTableTest/schema.sql
deleted file mode 100644 (file)
index 92fadc6..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-CREATE TABLE "ISSUES"(
-    "ID" BIGINT NOT NULL,
-    "KEE" VARCHAR(50) NOT NULL,
-    "RULE_ID" INTEGER,
-    "SEVERITY" VARCHAR(10),
-    "MANUAL_SEVERITY" BOOLEAN NOT NULL,
-    "MESSAGE" VARCHAR(4000),
-    "LINE" INTEGER,
-    "GAP" DOUBLE,
-    "STATUS" VARCHAR(20),
-    "RESOLUTION" VARCHAR(20),
-    "CHECKSUM" VARCHAR(1000),
-    "REPORTER" VARCHAR(255),
-    "ASSIGNEE" VARCHAR(255),
-    "AUTHOR_LOGIN" VARCHAR(255),
-    "ACTION_PLAN_KEY" VARCHAR(50),
-    "ISSUE_ATTRIBUTES" VARCHAR(4000),
-    "EFFORT" INTEGER,
-    "CREATED_AT" BIGINT,
-    "UPDATED_AT" BIGINT,
-    "ISSUE_CREATION_DATE" BIGINT,
-    "ISSUE_UPDATE_DATE" BIGINT,
-    "ISSUE_CLOSE_DATE" BIGINT,
-    "TAGS" VARCHAR(4000),
-    "COMPONENT_UUID" VARCHAR(50),
-    "PROJECT_UUID" VARCHAR(50),
-    "LOCATIONS" BLOB,
-    "ISSUE_TYPE" TINYINT,
-    "FROM_HOTSPOT" BOOLEAN
-);
-ALTER TABLE "ISSUES" ADD CONSTRAINT "PK_ISSUES" PRIMARY KEY("KEE");
-CREATE INDEX "ISSUES_ASSIGNEE" ON "ISSUES"("ASSIGNEE");
-CREATE INDEX "ISSUES_COMPONENT_UUID" ON "ISSUES"("COMPONENT_UUID");
-CREATE INDEX "ISSUES_CREATION_DATE" ON "ISSUES"("ISSUE_CREATION_DATE");
-CREATE UNIQUE INDEX "ISSUES_KEE" ON "ISSUES"("KEE");
-CREATE INDEX "ISSUES_PROJECT_UUID" ON "ISSUES"("PROJECT_UUID");
-CREATE INDEX "ISSUES_RESOLUTION" ON "ISSUES"("RESOLUTION");
-CREATE INDEX "ISSUES_RULE_ID" ON "ISSUES"("RULE_ID");
-CREATE INDEX "ISSUES_UPDATED_AT" ON "ISSUES"("UPDATED_AT");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/issues/DropPrimaryKeyOnIdColumnOfIssuesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/issues/DropPrimaryKeyOnIdColumnOfIssuesTableTest/schema.sql
deleted file mode 100644 (file)
index cf65bc4..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-CREATE TABLE "ISSUES"(
-    "ID" BIGINT NOT NULL AUTO_INCREMENT (1,1),
-    "KEE" VARCHAR(50) NOT NULL,
-    "RULE_ID" INTEGER,
-    "SEVERITY" VARCHAR(10),
-    "MANUAL_SEVERITY" BOOLEAN NOT NULL,
-    "MESSAGE" VARCHAR(4000),
-    "LINE" INTEGER,
-    "GAP" DOUBLE,
-    "STATUS" VARCHAR(20),
-    "RESOLUTION" VARCHAR(20),
-    "CHECKSUM" VARCHAR(1000),
-    "REPORTER" VARCHAR(255),
-    "ASSIGNEE" VARCHAR(255),
-    "AUTHOR_LOGIN" VARCHAR(255),
-    "ACTION_PLAN_KEY" VARCHAR(50),
-    "ISSUE_ATTRIBUTES" VARCHAR(4000),
-    "EFFORT" INTEGER,
-    "CREATED_AT" BIGINT,
-    "UPDATED_AT" BIGINT,
-    "ISSUE_CREATION_DATE" BIGINT,
-    "ISSUE_UPDATE_DATE" BIGINT,
-    "ISSUE_CLOSE_DATE" BIGINT,
-    "TAGS" VARCHAR(4000),
-    "COMPONENT_UUID" VARCHAR(50),
-    "PROJECT_UUID" VARCHAR(50),
-    "LOCATIONS" BLOB,
-    "ISSUE_TYPE" TINYINT,
-    "FROM_HOTSPOT" BOOLEAN
-);
-ALTER TABLE "ISSUES" ADD CONSTRAINT "PK_ISSUES" PRIMARY KEY("ID");
-CREATE INDEX "ISSUES_ASSIGNEE" ON "ISSUES"("ASSIGNEE");
-CREATE INDEX "ISSUES_COMPONENT_UUID" ON "ISSUES"("COMPONENT_UUID");
-CREATE INDEX "ISSUES_CREATION_DATE" ON "ISSUES"("ISSUE_CREATION_DATE");
-CREATE UNIQUE INDEX "ISSUES_KEE" ON "ISSUES"("KEE");
-CREATE INDEX "ISSUES_PROJECT_UUID" ON "ISSUES"("PROJECT_UUID");
-CREATE INDEX "ISSUES_RESOLUTION" ON "ISSUES"("RESOLUTION");
-CREATE INDEX "ISSUES_RULE_ID" ON "ISSUES"("RULE_ID");
-CREATE INDEX "ISSUES_UPDATED_AT" ON "ISSUES"("UPDATED_AT");
index b624715d6c68657fa4783c172a6e99f4b33f622a..4f1c3afd5d6607d5f311176fc44bd4e314b65fdc 100644 (file)
@@ -2,8 +2,7 @@ CREATE TABLE "LIVE_MEASURES"(
     "UUID" VARCHAR(40) NOT NULL,
     "PROJECT_UUID" VARCHAR(50) NOT NULL,
     "COMPONENT_UUID" VARCHAR(50) NOT NULL,
-    "METRIC_ID" INTEGER NOT NULL,
-    "METRIC_UUID" VARCHAR NOT NULL,
+    "METRIC_UUID" VARCHAR(40) NOT NULL,
     "VALUE" DOUBLE,
     "TEXT_VALUE" VARCHAR(4000),
     "VARIATION" DOUBLE,
@@ -12,5 +11,3 @@ CREATE TABLE "LIVE_MEASURES"(
     "CREATED_AT" BIGINT NOT NULL,
     "UPDATED_AT" BIGINT NOT NULL
 );
-ALTER TABLE "LIVE_MEASURES" ADD CONSTRAINT "PK_LIVE_MEASURES" PRIMARY KEY("UUID");
-CREATE INDEX "LIVE_MEASURES_PROJECT" ON "LIVE_MEASURES"("PROJECT_UUID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/AddIndexOnProjectUuidOfLiveMeasuresTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/AddIndexOnProjectUuidOfLiveMeasuresTableTest/schema.sql
new file mode 100644 (file)
index 0000000..4f1c3af
--- /dev/null
@@ -0,0 +1,13 @@
+CREATE TABLE "LIVE_MEASURES"(
+    "UUID" VARCHAR(40) NOT NULL,
+    "PROJECT_UUID" VARCHAR(50) NOT NULL,
+    "COMPONENT_UUID" VARCHAR(50) NOT NULL,
+    "METRIC_UUID" VARCHAR(40) NOT NULL,
+    "VALUE" DOUBLE,
+    "TEXT_VALUE" VARCHAR(4000),
+    "VARIATION" DOUBLE,
+    "MEASURE_DATA" BLOB,
+    "UPDATE_MARKER" VARCHAR(40),
+    "CREATED_AT" BIGINT NOT NULL,
+    "UPDATED_AT" BIGINT NOT NULL
+);
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/AddMetricUuidColumnToLiveMeasuresTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/AddMetricUuidColumnToLiveMeasuresTest/schema.sql
deleted file mode 100644 (file)
index e969dd3..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-CREATE TABLE "LIVE_MEASURES"(
-    "UUID" VARCHAR(40) NOT NULL,
-    "PROJECT_UUID" VARCHAR(50) NOT NULL,
-    "COMPONENT_UUID" VARCHAR(50) NOT NULL,
-    "METRIC_ID" INTEGER NOT NULL,
-    "VALUE" DOUBLE,
-    "TEXT_VALUE" VARCHAR(4000),
-    "VARIATION" DOUBLE,
-    "MEASURE_DATA" BLOB,
-    "UPDATE_MARKER" VARCHAR(40),
-    "CREATED_AT" BIGINT NOT NULL,
-    "UPDATED_AT" BIGINT NOT NULL
-);
-ALTER TABLE "LIVE_MEASURES" ADD CONSTRAINT "PK_LIVE_MEASURES" PRIMARY KEY("UUID");
-CREATE INDEX "LIVE_MEASURES_PROJECT" ON "LIVE_MEASURES"("PROJECT_UUID");
-CREATE UNIQUE INDEX "LIVE_MEASURES_COMPONENT" ON "LIVE_MEASURES"("COMPONENT_UUID", "METRIC_ID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/CopyLiveMeasuresTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/CopyLiveMeasuresTableTest/schema.sql
new file mode 100644 (file)
index 0000000..e969dd3
--- /dev/null
@@ -0,0 +1,16 @@
+CREATE TABLE "LIVE_MEASURES"(
+    "UUID" VARCHAR(40) NOT NULL,
+    "PROJECT_UUID" VARCHAR(50) NOT NULL,
+    "COMPONENT_UUID" VARCHAR(50) NOT NULL,
+    "METRIC_ID" INTEGER NOT NULL,
+    "VALUE" DOUBLE,
+    "TEXT_VALUE" VARCHAR(4000),
+    "VARIATION" DOUBLE,
+    "MEASURE_DATA" BLOB,
+    "UPDATE_MARKER" VARCHAR(40),
+    "CREATED_AT" BIGINT NOT NULL,
+    "UPDATED_AT" BIGINT NOT NULL
+);
+ALTER TABLE "LIVE_MEASURES" ADD CONSTRAINT "PK_LIVE_MEASURES" PRIMARY KEY("UUID");
+CREATE INDEX "LIVE_MEASURES_PROJECT" ON "LIVE_MEASURES"("PROJECT_UUID");
+CREATE UNIQUE INDEX "LIVE_MEASURES_COMPONENT" ON "LIVE_MEASURES"("COMPONENT_UUID", "METRIC_ID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/DropIndexOnMetricIdOfLiveMeasuresTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/DropIndexOnMetricIdOfLiveMeasuresTableTest/schema.sql
deleted file mode 100644 (file)
index 79dd9a6..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-CREATE TABLE "LIVE_MEASURES"(
-    "UUID" VARCHAR(40) NOT NULL,
-    "PROJECT_UUID" VARCHAR(50) NOT NULL,
-    "COMPONENT_UUID" VARCHAR(50) NOT NULL,
-    "METRIC_ID" INTEGER NOT NULL,
-    "METRIC_UUID" VARCHAR NOT NULL,
-    "VALUE" DOUBLE,
-    "TEXT_VALUE" VARCHAR(4000),
-    "VARIATION" DOUBLE,
-    "MEASURE_DATA" BLOB,
-    "UPDATE_MARKER" VARCHAR(40),
-    "CREATED_AT" BIGINT NOT NULL,
-    "UPDATED_AT" BIGINT NOT NULL
-);
-ALTER TABLE "LIVE_MEASURES" ADD CONSTRAINT "PK_LIVE_MEASURES" PRIMARY KEY("UUID");
-CREATE INDEX "LIVE_MEASURES_PROJECT" ON "LIVE_MEASURES"("PROJECT_UUID");
-CREATE UNIQUE INDEX "LIVE_MEASURES_COMPONENT" ON "LIVE_MEASURES"("COMPONENT_UUID", "METRIC_ID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/DropLiveMeasuresTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/DropLiveMeasuresTableTest/schema.sql
new file mode 100644 (file)
index 0000000..979f28b
--- /dev/null
@@ -0,0 +1,30 @@
+CREATE TABLE "LIVE_MEASURES"(
+    "UUID" VARCHAR(40) NOT NULL,
+    "PROJECT_UUID" VARCHAR(50) NOT NULL,
+    "COMPONENT_UUID" VARCHAR(50) NOT NULL,
+    "METRIC_ID" INTEGER NOT NULL,
+    "VALUE" DOUBLE,
+    "TEXT_VALUE" VARCHAR(4000),
+    "VARIATION" DOUBLE,
+    "MEASURE_DATA" BLOB,
+    "UPDATE_MARKER" VARCHAR(40),
+    "CREATED_AT" BIGINT NOT NULL,
+    "UPDATED_AT" BIGINT NOT NULL
+);
+ALTER TABLE "LIVE_MEASURES" ADD CONSTRAINT "PK_LIVE_MEASURES" PRIMARY KEY("UUID");
+CREATE INDEX "LIVE_MEASURES_PROJECT" ON "LIVE_MEASURES"("PROJECT_UUID");
+CREATE UNIQUE INDEX "LIVE_MEASURES_COMPONENT" ON "LIVE_MEASURES"("COMPONENT_UUID", "METRIC_ID");
+
+CREATE TABLE "LIVE_MEASURES_COPY"(
+    "UUID" VARCHAR(40) NOT NULL,
+    "PROJECT_UUID" VARCHAR(50) NOT NULL,
+    "COMPONENT_UUID" VARCHAR(50) NOT NULL,
+    "METRIC_UUID" VARCHAR(40) NOT NULL,
+    "VALUE" DOUBLE,
+    "TEXT_VALUE" VARCHAR(4000),
+    "VARIATION" DOUBLE,
+    "MEASURE_DATA" BLOB,
+    "UPDATE_MARKER" VARCHAR(40),
+    "CREATED_AT" BIGINT NOT NULL,
+    "UPDATED_AT" BIGINT NOT NULL
+);
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/DropMetricIdColumnOfLiveMeasuresTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/DropMetricIdColumnOfLiveMeasuresTableTest/schema.sql
deleted file mode 100644 (file)
index 5b750f3..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-CREATE TABLE "LIVE_MEASURES"(
-    "UUID" VARCHAR(40) NOT NULL,
-    "PROJECT_UUID" VARCHAR(50) NOT NULL,
-    "COMPONENT_UUID" VARCHAR(50) NOT NULL,
-    "METRIC_ID" INTEGER NOT NULL,
-    "METRIC_UUID" VARCHAR NOT NULL,
-    "VALUE" DOUBLE,
-    "TEXT_VALUE" VARCHAR(4000),
-    "VARIATION" DOUBLE,
-    "MEASURE_DATA" BLOB,
-    "UPDATE_MARKER" VARCHAR(40),
-    "CREATED_AT" BIGINT NOT NULL,
-    "UPDATED_AT" BIGINT NOT NULL
-);
-ALTER TABLE "LIVE_MEASURES" ADD CONSTRAINT "PK_LIVE_MEASURES" PRIMARY KEY("UUID");
-CREATE INDEX "LIVE_MEASURES_PROJECT" ON "LIVE_MEASURES"("PROJECT_UUID");
-CREATE UNIQUE INDEX "LIVE_MEASURES_COMPONENT" ON "LIVE_MEASURES"("COMPONENT_UUID", "METRIC_UUID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/MakeLiveMeasuresMetricUuidNotNullableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/MakeLiveMeasuresMetricUuidNotNullableTest/schema.sql
deleted file mode 100644 (file)
index dd1e89a..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-CREATE TABLE "LIVE_MEASURES"(
-    "UUID" VARCHAR(40) NOT NULL,
-    "PROJECT_UUID" VARCHAR(50) NOT NULL,
-    "COMPONENT_UUID" VARCHAR(50) NOT NULL,
-    "METRIC_ID" INTEGER NOT NULL,
-    "METRIC_UUID" VARCHAR(40),
-    "VALUE" DOUBLE,
-    "TEXT_VALUE" VARCHAR(4000),
-    "VARIATION" DOUBLE,
-    "MEASURE_DATA" BLOB,
-    "UPDATE_MARKER" VARCHAR(40),
-    "CREATED_AT" BIGINT NOT NULL,
-    "UPDATED_AT" BIGINT NOT NULL
-);
-ALTER TABLE "LIVE_MEASURES" ADD CONSTRAINT "PK_LIVE_MEASURES" PRIMARY KEY("UUID");
-CREATE INDEX "LIVE_MEASURES_PROJECT" ON "LIVE_MEASURES"("PROJECT_UUID");
-CREATE UNIQUE INDEX "LIVE_MEASURES_COMPONENT" ON "LIVE_MEASURES"("COMPONENT_UUID", "METRIC_ID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/PopulateLiveMeasuresMetricUuidTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/PopulateLiveMeasuresMetricUuidTest/schema.sql
deleted file mode 100644 (file)
index 85b848f..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-CREATE TABLE "LIVE_MEASURES"(
-    "UUID" VARCHAR(40) NOT NULL,
-    "PROJECT_UUID" VARCHAR(50) NOT NULL,
-    "COMPONENT_UUID" VARCHAR(50) NOT NULL,
-    "METRIC_ID" INTEGER NOT NULL,
-    "METRIC_UUID" VARCHAR(40),
-    "VALUE" DOUBLE,
-    "TEXT_VALUE" VARCHAR(4000),
-    "VARIATION" DOUBLE,
-    "MEASURE_DATA" BLOB,
-    "UPDATE_MARKER" VARCHAR(40),
-    "CREATED_AT" BIGINT NOT NULL,
-    "UPDATED_AT" BIGINT NOT NULL
-);
-ALTER TABLE "LIVE_MEASURES" ADD CONSTRAINT "PK_LIVE_MEASURES" PRIMARY KEY("UUID");
-CREATE INDEX "LIVE_MEASURES_PROJECT" ON "LIVE_MEASURES"("PROJECT_UUID");
-CREATE UNIQUE INDEX "LIVE_MEASURES_COMPONENT" ON "LIVE_MEASURES"("COMPONENT_UUID", "METRIC_ID");
-
-CREATE TABLE "METRICS"(
-    "ID" INTEGER NOT NULL,
-    "UUID" VARCHAR(40) NOT NULL,
-    "NAME" VARCHAR(64) NOT NULL,
-    "DESCRIPTION" VARCHAR(255),
-    "DIRECTION" INTEGER DEFAULT 0 NOT NULL,
-    "DOMAIN" VARCHAR(64),
-    "SHORT_NAME" VARCHAR(64),
-    "QUALITATIVE" BOOLEAN DEFAULT FALSE NOT NULL,
-    "VAL_TYPE" VARCHAR(8),
-    "USER_MANAGED" BOOLEAN DEFAULT FALSE,
-    "ENABLED" BOOLEAN DEFAULT TRUE,
-    "WORST_VALUE" DOUBLE,
-    "BEST_VALUE" DOUBLE,
-    "OPTIMIZED_BEST_VALUE" BOOLEAN,
-    "HIDDEN" BOOLEAN,
-    "DELETE_HISTORICAL_DATA" BOOLEAN,
-    "DECIMAL_SCALE" INTEGER
-);
-ALTER TABLE "METRICS" ADD CONSTRAINT "PK_METRICS" PRIMARY KEY("ID");
-CREATE UNIQUE INDEX "METRICS_UNIQUE_NAME" ON "METRICS"("NAME");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/RenameLiveMeasuresCopyToLiveMeasuresTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/RenameLiveMeasuresCopyToLiveMeasuresTest/schema.sql
new file mode 100644 (file)
index 0000000..6688560
--- /dev/null
@@ -0,0 +1,13 @@
+CREATE TABLE "LIVE_MEASURES_COPY"(
+    "UUID" VARCHAR(40) NOT NULL,
+    "PROJECT_UUID" VARCHAR(50) NOT NULL,
+    "COMPONENT_UUID" VARCHAR(50) NOT NULL,
+    "METRIC_UUID" VARCHAR(40) NOT NULL,
+    "VALUE" DOUBLE,
+    "TEXT_VALUE" VARCHAR(4000),
+    "VARIATION" DOUBLE,
+    "MEASURE_DATA" BLOB,
+    "UPDATE_MARKER" VARCHAR(40),
+    "CREATED_AT" BIGINT NOT NULL,
+    "UPDATED_AT" BIGINT NOT NULL
+);
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/rules/issues/AddIndexToIssuesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/rules/issues/AddIndexToIssuesTableTest/schema.sql
deleted file mode 100644 (file)
index d02b9c7..0000000
+++ /dev/null
@@ -1,69 +0,0 @@
-CREATE TABLE "RULES"(
-    "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
-    "NAME" VARCHAR(200),
-    "PLUGIN_RULE_KEY" VARCHAR(200) NOT NULL,
-    "PLUGIN_KEY" VARCHAR(200),
-    "PLUGIN_CONFIG_KEY" VARCHAR(200),
-    "PLUGIN_NAME" VARCHAR(255) NOT NULL,
-    "SCOPE" VARCHAR(20) NOT NULL,
-    "DESCRIPTION" CLOB(2147483647),
-    "PRIORITY" INTEGER,
-    "STATUS" VARCHAR(40),
-    "LANGUAGE" VARCHAR(20),
-    "DEF_REMEDIATION_FUNCTION" VARCHAR(20),
-    "DEF_REMEDIATION_GAP_MULT" VARCHAR(20),
-    "DEF_REMEDIATION_BASE_EFFORT" VARCHAR(20),
-    "GAP_DESCRIPTION" VARCHAR(4000),
-    "SYSTEM_TAGS" VARCHAR(4000),
-    "IS_TEMPLATE" BOOLEAN DEFAULT FALSE NOT NULL,
-    "DESCRIPTION_FORMAT" VARCHAR(20),
-    "RULE_TYPE" TINYINT,
-    "SECURITY_STANDARDS" VARCHAR(4000),
-    "IS_AD_HOC" BOOLEAN NOT NULL,
-    "IS_EXTERNAL" BOOLEAN NOT NULL,
-    "CREATED_AT" BIGINT,
-    "UPDATED_AT" BIGINT,
-    "UUID" VARCHAR(40) NOT NULL,
-    "TEMPLATE_UUID" VARCHAR(40)
-);
-ALTER TABLE "RULES" ADD CONSTRAINT "PK_RULES" PRIMARY KEY("ID");
-CREATE UNIQUE INDEX "RULES_REPO_KEY" ON "RULES"("PLUGIN_RULE_KEY", "PLUGIN_NAME");
-
-CREATE TABLE "ISSUES"(
-    "KEE" VARCHAR(50) NOT NULL,
-    "RULE_ID" INTEGER,
-    "SEVERITY" VARCHAR(10),
-    "MANUAL_SEVERITY" BOOLEAN NOT NULL,
-    "MESSAGE" VARCHAR(4000),
-    "LINE" INTEGER,
-    "GAP" DOUBLE,
-    "STATUS" VARCHAR(20),
-    "RESOLUTION" VARCHAR(20),
-    "CHECKSUM" VARCHAR(1000),
-    "REPORTER" VARCHAR(255),
-    "ASSIGNEE" VARCHAR(255),
-    "AUTHOR_LOGIN" VARCHAR(255),
-    "ACTION_PLAN_KEY" VARCHAR(50),
-    "ISSUE_ATTRIBUTES" VARCHAR(4000),
-    "EFFORT" INTEGER,
-    "CREATED_AT" BIGINT,
-    "UPDATED_AT" BIGINT,
-    "ISSUE_CREATION_DATE" BIGINT,
-    "ISSUE_UPDATE_DATE" BIGINT,
-    "ISSUE_CLOSE_DATE" BIGINT,
-    "TAGS" VARCHAR(4000),
-    "COMPONENT_UUID" VARCHAR(50),
-    "PROJECT_UUID" VARCHAR(50),
-    "LOCATIONS" BLOB,
-    "ISSUE_TYPE" TINYINT,
-    "FROM_HOTSPOT" BOOLEAN,
-    "RULE_UUID" VARCHAR(40)
-);
-ALTER TABLE "ISSUES" ADD CONSTRAINT "PK_ISSUES" PRIMARY KEY("KEE");
-CREATE INDEX "ISSUES_ASSIGNEE" ON "ISSUES"("ASSIGNEE");
-CREATE INDEX "ISSUES_COMPONENT_UUID" ON "ISSUES"("COMPONENT_UUID");
-CREATE INDEX "ISSUES_CREATION_DATE" ON "ISSUES"("ISSUE_CREATION_DATE");
-CREATE UNIQUE INDEX "ISSUES_KEE" ON "ISSUES"("KEE");
-CREATE INDEX "ISSUES_PROJECT_UUID" ON "ISSUES"("PROJECT_UUID");
-CREATE INDEX "ISSUES_RESOLUTION" ON "ISSUES"("RESOLUTION");
-CREATE INDEX "ISSUES_UPDATED_AT" ON "ISSUES"("UPDATED_AT");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/rules/issues/AddIndexesToIssuesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/rules/issues/AddIndexesToIssuesTableTest/schema.sql
new file mode 100644 (file)
index 0000000..6b6f0a9
--- /dev/null
@@ -0,0 +1,31 @@
+CREATE TABLE "ISSUES"(
+    "KEE" VARCHAR(50) NOT NULL,
+    "RULE_ID" INTEGER,
+    "SEVERITY" VARCHAR(10),
+    "MANUAL_SEVERITY" BOOLEAN NOT NULL,
+    "MESSAGE" VARCHAR(4000),
+    "LINE" INTEGER,
+    "GAP" DOUBLE,
+    "STATUS" VARCHAR(20),
+    "RESOLUTION" VARCHAR(20),
+    "CHECKSUM" VARCHAR(1000),
+    "REPORTER" VARCHAR(255),
+    "ASSIGNEE" VARCHAR(255),
+    "AUTHOR_LOGIN" VARCHAR(255),
+    "ACTION_PLAN_KEY" VARCHAR(50),
+    "ISSUE_ATTRIBUTES" VARCHAR(4000),
+    "EFFORT" INTEGER,
+    "CREATED_AT" BIGINT,
+    "UPDATED_AT" BIGINT,
+    "ISSUE_CREATION_DATE" BIGINT,
+    "ISSUE_UPDATE_DATE" BIGINT,
+    "ISSUE_CLOSE_DATE" BIGINT,
+    "TAGS" VARCHAR(4000),
+    "COMPONENT_UUID" VARCHAR(50),
+    "PROJECT_UUID" VARCHAR(50),
+    "LOCATIONS" BLOB,
+    "ISSUE_TYPE" TINYINT,
+    "FROM_HOTSPOT" BOOLEAN,
+    "RULE_UUID" VARCHAR(40)
+);
+ALTER TABLE "ISSUES" ADD CONSTRAINT "PK_ISSUES" PRIMARY KEY("KEE");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/rules/issues/AddRuleUuidColumnToIssuesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/rules/issues/AddRuleUuidColumnToIssuesTableTest/schema.sql
deleted file mode 100644 (file)
index 89488e5..0000000
+++ /dev/null
@@ -1,69 +0,0 @@
-CREATE TABLE "RULES"(
-    "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
-    "NAME" VARCHAR(200),
-    "PLUGIN_RULE_KEY" VARCHAR(200) NOT NULL,
-    "PLUGIN_KEY" VARCHAR(200),
-    "PLUGIN_CONFIG_KEY" VARCHAR(200),
-    "PLUGIN_NAME" VARCHAR(255) NOT NULL,
-    "SCOPE" VARCHAR(20) NOT NULL,
-    "DESCRIPTION" CLOB(2147483647),
-    "PRIORITY" INTEGER,
-    "STATUS" VARCHAR(40),
-    "LANGUAGE" VARCHAR(20),
-    "DEF_REMEDIATION_FUNCTION" VARCHAR(20),
-    "DEF_REMEDIATION_GAP_MULT" VARCHAR(20),
-    "DEF_REMEDIATION_BASE_EFFORT" VARCHAR(20),
-    "GAP_DESCRIPTION" VARCHAR(4000),
-    "SYSTEM_TAGS" VARCHAR(4000),
-    "IS_TEMPLATE" BOOLEAN DEFAULT FALSE NOT NULL,
-    "DESCRIPTION_FORMAT" VARCHAR(20),
-    "RULE_TYPE" TINYINT,
-    "SECURITY_STANDARDS" VARCHAR(4000),
-    "IS_AD_HOC" BOOLEAN NOT NULL,
-    "IS_EXTERNAL" BOOLEAN NOT NULL,
-    "CREATED_AT" BIGINT,
-    "UPDATED_AT" BIGINT,
-    "UUID" VARCHAR(40) NOT NULL,
-    "TEMPLATE_UUID" VARCHAR(40)
-);
-ALTER TABLE "RULES" ADD CONSTRAINT "PK_RULES" PRIMARY KEY("ID");
-CREATE UNIQUE INDEX "RULES_REPO_KEY" ON "RULES"("PLUGIN_RULE_KEY", "PLUGIN_NAME");
-
-CREATE TABLE "ISSUES"(
-    "KEE" VARCHAR(50) NOT NULL,
-    "RULE_ID" INTEGER,
-    "SEVERITY" VARCHAR(10),
-    "MANUAL_SEVERITY" BOOLEAN NOT NULL,
-    "MESSAGE" VARCHAR(4000),
-    "LINE" INTEGER,
-    "GAP" DOUBLE,
-    "STATUS" VARCHAR(20),
-    "RESOLUTION" VARCHAR(20),
-    "CHECKSUM" VARCHAR(1000),
-    "REPORTER" VARCHAR(255),
-    "ASSIGNEE" VARCHAR(255),
-    "AUTHOR_LOGIN" VARCHAR(255),
-    "ACTION_PLAN_KEY" VARCHAR(50),
-    "ISSUE_ATTRIBUTES" VARCHAR(4000),
-    "EFFORT" INTEGER,
-    "CREATED_AT" BIGINT,
-    "UPDATED_AT" BIGINT,
-    "ISSUE_CREATION_DATE" BIGINT,
-    "ISSUE_UPDATE_DATE" BIGINT,
-    "ISSUE_CLOSE_DATE" BIGINT,
-    "TAGS" VARCHAR(4000),
-    "COMPONENT_UUID" VARCHAR(50),
-    "PROJECT_UUID" VARCHAR(50),
-    "LOCATIONS" BLOB,
-    "ISSUE_TYPE" TINYINT,
-    "FROM_HOTSPOT" BOOLEAN
-);
-ALTER TABLE "ISSUES" ADD CONSTRAINT "PK_ISSUES" PRIMARY KEY("KEE");
-CREATE INDEX "ISSUES_ASSIGNEE" ON "ISSUES"("ASSIGNEE");
-CREATE INDEX "ISSUES_COMPONENT_UUID" ON "ISSUES"("COMPONENT_UUID");
-CREATE INDEX "ISSUES_CREATION_DATE" ON "ISSUES"("ISSUE_CREATION_DATE");
-CREATE UNIQUE INDEX "ISSUES_KEE" ON "ISSUES"("KEE");
-CREATE INDEX "ISSUES_PROJECT_UUID" ON "ISSUES"("PROJECT_UUID");
-CREATE INDEX "ISSUES_RESOLUTION" ON "ISSUES"("RESOLUTION");
-CREATE INDEX "ISSUES_RULE_ID" ON "ISSUES"("RULE_ID");
-CREATE INDEX "ISSUES_UPDATED_AT" ON "ISSUES"("UPDATED_AT");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/rules/issues/CopyIssuesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/rules/issues/CopyIssuesTableTest/schema.sql
new file mode 100644 (file)
index 0000000..cf65bc4
--- /dev/null
@@ -0,0 +1,39 @@
+CREATE TABLE "ISSUES"(
+    "ID" BIGINT NOT NULL AUTO_INCREMENT (1,1),
+    "KEE" VARCHAR(50) NOT NULL,
+    "RULE_ID" INTEGER,
+    "SEVERITY" VARCHAR(10),
+    "MANUAL_SEVERITY" BOOLEAN NOT NULL,
+    "MESSAGE" VARCHAR(4000),
+    "LINE" INTEGER,
+    "GAP" DOUBLE,
+    "STATUS" VARCHAR(20),
+    "RESOLUTION" VARCHAR(20),
+    "CHECKSUM" VARCHAR(1000),
+    "REPORTER" VARCHAR(255),
+    "ASSIGNEE" VARCHAR(255),
+    "AUTHOR_LOGIN" VARCHAR(255),
+    "ACTION_PLAN_KEY" VARCHAR(50),
+    "ISSUE_ATTRIBUTES" VARCHAR(4000),
+    "EFFORT" INTEGER,
+    "CREATED_AT" BIGINT,
+    "UPDATED_AT" BIGINT,
+    "ISSUE_CREATION_DATE" BIGINT,
+    "ISSUE_UPDATE_DATE" BIGINT,
+    "ISSUE_CLOSE_DATE" BIGINT,
+    "TAGS" VARCHAR(4000),
+    "COMPONENT_UUID" VARCHAR(50),
+    "PROJECT_UUID" VARCHAR(50),
+    "LOCATIONS" BLOB,
+    "ISSUE_TYPE" TINYINT,
+    "FROM_HOTSPOT" BOOLEAN
+);
+ALTER TABLE "ISSUES" ADD CONSTRAINT "PK_ISSUES" PRIMARY KEY("ID");
+CREATE INDEX "ISSUES_ASSIGNEE" ON "ISSUES"("ASSIGNEE");
+CREATE INDEX "ISSUES_COMPONENT_UUID" ON "ISSUES"("COMPONENT_UUID");
+CREATE INDEX "ISSUES_CREATION_DATE" ON "ISSUES"("ISSUE_CREATION_DATE");
+CREATE UNIQUE INDEX "ISSUES_KEE" ON "ISSUES"("KEE");
+CREATE INDEX "ISSUES_PROJECT_UUID" ON "ISSUES"("PROJECT_UUID");
+CREATE INDEX "ISSUES_RESOLUTION" ON "ISSUES"("RESOLUTION");
+CREATE INDEX "ISSUES_RULE_ID" ON "ISSUES"("RULE_ID");
+CREATE INDEX "ISSUES_UPDATED_AT" ON "ISSUES"("UPDATED_AT");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/rules/issues/DropIndexOnRuleIdColumnOfIssuesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/rules/issues/DropIndexOnRuleIdColumnOfIssuesTableTest/schema.sql
deleted file mode 100644 (file)
index d6c8f6b..0000000
+++ /dev/null
@@ -1,70 +0,0 @@
-CREATE TABLE "RULES"(
-    "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
-    "NAME" VARCHAR(200),
-    "PLUGIN_RULE_KEY" VARCHAR(200) NOT NULL,
-    "PLUGIN_KEY" VARCHAR(200),
-    "PLUGIN_CONFIG_KEY" VARCHAR(200),
-    "PLUGIN_NAME" VARCHAR(255) NOT NULL,
-    "SCOPE" VARCHAR(20) NOT NULL,
-    "DESCRIPTION" CLOB(2147483647),
-    "PRIORITY" INTEGER,
-    "STATUS" VARCHAR(40),
-    "LANGUAGE" VARCHAR(20),
-    "DEF_REMEDIATION_FUNCTION" VARCHAR(20),
-    "DEF_REMEDIATION_GAP_MULT" VARCHAR(20),
-    "DEF_REMEDIATION_BASE_EFFORT" VARCHAR(20),
-    "GAP_DESCRIPTION" VARCHAR(4000),
-    "SYSTEM_TAGS" VARCHAR(4000),
-    "IS_TEMPLATE" BOOLEAN DEFAULT FALSE NOT NULL,
-    "DESCRIPTION_FORMAT" VARCHAR(20),
-    "RULE_TYPE" TINYINT,
-    "SECURITY_STANDARDS" VARCHAR(4000),
-    "IS_AD_HOC" BOOLEAN NOT NULL,
-    "IS_EXTERNAL" BOOLEAN NOT NULL,
-    "CREATED_AT" BIGINT,
-    "UPDATED_AT" BIGINT,
-    "UUID" VARCHAR(40) NOT NULL,
-    "TEMPLATE_UUID" VARCHAR(40)
-);
-ALTER TABLE "RULES" ADD CONSTRAINT "PK_RULES" PRIMARY KEY("ID");
-CREATE UNIQUE INDEX "RULES_REPO_KEY" ON "RULES"("PLUGIN_RULE_KEY", "PLUGIN_NAME");
-
-CREATE TABLE "ISSUES"(
-    "KEE" VARCHAR(50) NOT NULL,
-    "RULE_ID" INTEGER,
-    "SEVERITY" VARCHAR(10),
-    "MANUAL_SEVERITY" BOOLEAN NOT NULL,
-    "MESSAGE" VARCHAR(4000),
-    "LINE" INTEGER,
-    "GAP" DOUBLE,
-    "STATUS" VARCHAR(20),
-    "RESOLUTION" VARCHAR(20),
-    "CHECKSUM" VARCHAR(1000),
-    "REPORTER" VARCHAR(255),
-    "ASSIGNEE" VARCHAR(255),
-    "AUTHOR_LOGIN" VARCHAR(255),
-    "ACTION_PLAN_KEY" VARCHAR(50),
-    "ISSUE_ATTRIBUTES" VARCHAR(4000),
-    "EFFORT" INTEGER,
-    "CREATED_AT" BIGINT,
-    "UPDATED_AT" BIGINT,
-    "ISSUE_CREATION_DATE" BIGINT,
-    "ISSUE_UPDATE_DATE" BIGINT,
-    "ISSUE_CLOSE_DATE" BIGINT,
-    "TAGS" VARCHAR(4000),
-    "COMPONENT_UUID" VARCHAR(50),
-    "PROJECT_UUID" VARCHAR(50),
-    "LOCATIONS" BLOB,
-    "ISSUE_TYPE" TINYINT,
-    "FROM_HOTSPOT" BOOLEAN,
-    "RULE_UUID" VARCHAR(40)
-);
-ALTER TABLE "ISSUES" ADD CONSTRAINT "PK_ISSUES" PRIMARY KEY("KEE");
-CREATE INDEX "ISSUES_ASSIGNEE" ON "ISSUES"("ASSIGNEE");
-CREATE INDEX "ISSUES_COMPONENT_UUID" ON "ISSUES"("COMPONENT_UUID");
-CREATE INDEX "ISSUES_CREATION_DATE" ON "ISSUES"("ISSUE_CREATION_DATE");
-CREATE UNIQUE INDEX "ISSUES_KEE" ON "ISSUES"("KEE");
-CREATE INDEX "ISSUES_PROJECT_UUID" ON "ISSUES"("PROJECT_UUID");
-CREATE INDEX "ISSUES_RESOLUTION" ON "ISSUES"("RESOLUTION");
-CREATE INDEX "ISSUES_RULE_ID" ON "ISSUES"("RULE_ID");
-CREATE INDEX "ISSUES_UPDATED_AT" ON "ISSUES"("UPDATED_AT");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/rules/issues/DropIssuesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/rules/issues/DropIssuesTableTest/schema.sql
new file mode 100644 (file)
index 0000000..a791fda
--- /dev/null
@@ -0,0 +1,70 @@
+CREATE TABLE "ISSUES_COPY"(
+    "KEE" VARCHAR(50) NOT NULL,
+    "RULE_ID" INTEGER,
+    "SEVERITY" VARCHAR(10),
+    "MANUAL_SEVERITY" BOOLEAN NOT NULL,
+    "MESSAGE" VARCHAR(4000),
+    "LINE" INTEGER,
+    "GAP" DOUBLE,
+    "STATUS" VARCHAR(20),
+    "RESOLUTION" VARCHAR(20),
+    "CHECKSUM" VARCHAR(1000),
+    "REPORTER" VARCHAR(255),
+    "ASSIGNEE" VARCHAR(255),
+    "AUTHOR_LOGIN" VARCHAR(255),
+    "ACTION_PLAN_KEY" VARCHAR(50),
+    "ISSUE_ATTRIBUTES" VARCHAR(4000),
+    "EFFORT" INTEGER,
+    "CREATED_AT" BIGINT,
+    "UPDATED_AT" BIGINT,
+    "ISSUE_CREATION_DATE" BIGINT,
+    "ISSUE_UPDATE_DATE" BIGINT,
+    "ISSUE_CLOSE_DATE" BIGINT,
+    "TAGS" VARCHAR(4000),
+    "COMPONENT_UUID" VARCHAR(50),
+    "PROJECT_UUID" VARCHAR(50),
+    "LOCATIONS" BLOB,
+    "ISSUE_TYPE" TINYINT,
+    "FROM_HOTSPOT" BOOLEAN,
+    "RULE_UUID" VARCHAR(40)
+);
+
+CREATE TABLE "ISSUES"(
+    "ID" BIGINT NOT NULL AUTO_INCREMENT (1,1),
+    "KEE" VARCHAR(50) NOT NULL,
+    "RULE_ID" INTEGER,
+    "SEVERITY" VARCHAR(10),
+    "MANUAL_SEVERITY" BOOLEAN NOT NULL,
+    "MESSAGE" VARCHAR(4000),
+    "LINE" INTEGER,
+    "GAP" DOUBLE,
+    "STATUS" VARCHAR(20),
+    "RESOLUTION" VARCHAR(20),
+    "CHECKSUM" VARCHAR(1000),
+    "REPORTER" VARCHAR(255),
+    "ASSIGNEE" VARCHAR(255),
+    "AUTHOR_LOGIN" VARCHAR(255),
+    "ACTION_PLAN_KEY" VARCHAR(50),
+    "ISSUE_ATTRIBUTES" VARCHAR(4000),
+    "EFFORT" INTEGER,
+    "CREATED_AT" BIGINT,
+    "UPDATED_AT" BIGINT,
+    "ISSUE_CREATION_DATE" BIGINT,
+    "ISSUE_UPDATE_DATE" BIGINT,
+    "ISSUE_CLOSE_DATE" BIGINT,
+    "TAGS" VARCHAR(4000),
+    "COMPONENT_UUID" VARCHAR(50),
+    "PROJECT_UUID" VARCHAR(50),
+    "LOCATIONS" BLOB,
+    "ISSUE_TYPE" TINYINT,
+    "FROM_HOTSPOT" BOOLEAN
+);
+ALTER TABLE "ISSUES" ADD CONSTRAINT "PK_ISSUES" PRIMARY KEY("ID");
+CREATE INDEX "ISSUES_ASSIGNEE" ON "ISSUES"("ASSIGNEE");
+CREATE INDEX "ISSUES_COMPONENT_UUID" ON "ISSUES"("COMPONENT_UUID");
+CREATE INDEX "ISSUES_CREATION_DATE" ON "ISSUES"("ISSUE_CREATION_DATE");
+CREATE UNIQUE INDEX "ISSUES_KEE" ON "ISSUES"("KEE");
+CREATE INDEX "ISSUES_PROJECT_UUID" ON "ISSUES"("PROJECT_UUID");
+CREATE INDEX "ISSUES_RESOLUTION" ON "ISSUES"("RESOLUTION");
+CREATE INDEX "ISSUES_RULE_ID" ON "ISSUES"("RULE_ID");
+CREATE INDEX "ISSUES_UPDATED_AT" ON "ISSUES"("UPDATED_AT");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/rules/issues/DropRuleIdColumnOfIssuesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/rules/issues/DropRuleIdColumnOfIssuesTableTest/schema.sql
deleted file mode 100644 (file)
index a2da652..0000000
+++ /dev/null
@@ -1,70 +0,0 @@
-CREATE TABLE "RULES"(
-    "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
-    "NAME" VARCHAR(200),
-    "PLUGIN_RULE_KEY" VARCHAR(200) NOT NULL,
-    "PLUGIN_KEY" VARCHAR(200),
-    "PLUGIN_CONFIG_KEY" VARCHAR(200),
-    "PLUGIN_NAME" VARCHAR(255) NOT NULL,
-    "SCOPE" VARCHAR(20) NOT NULL,
-    "DESCRIPTION" CLOB(2147483647),
-    "PRIORITY" INTEGER,
-    "STATUS" VARCHAR(40),
-    "LANGUAGE" VARCHAR(20),
-    "DEF_REMEDIATION_FUNCTION" VARCHAR(20),
-    "DEF_REMEDIATION_GAP_MULT" VARCHAR(20),
-    "DEF_REMEDIATION_BASE_EFFORT" VARCHAR(20),
-    "GAP_DESCRIPTION" VARCHAR(4000),
-    "SYSTEM_TAGS" VARCHAR(4000),
-    "IS_TEMPLATE" BOOLEAN DEFAULT FALSE NOT NULL,
-    "DESCRIPTION_FORMAT" VARCHAR(20),
-    "RULE_TYPE" TINYINT,
-    "SECURITY_STANDARDS" VARCHAR(4000),
-    "IS_AD_HOC" BOOLEAN NOT NULL,
-    "IS_EXTERNAL" BOOLEAN NOT NULL,
-    "CREATED_AT" BIGINT,
-    "UPDATED_AT" BIGINT,
-    "UUID" VARCHAR(40) NOT NULL,
-    "TEMPLATE_UUID" VARCHAR(40)
-);
-ALTER TABLE "RULES" ADD CONSTRAINT "PK_RULES" PRIMARY KEY("ID");
-CREATE UNIQUE INDEX "RULES_REPO_KEY" ON "RULES"("PLUGIN_RULE_KEY", "PLUGIN_NAME");
-
-CREATE TABLE "ISSUES"(
-    "KEE" VARCHAR(50) NOT NULL,
-    "RULE_ID" INTEGER,
-    "SEVERITY" VARCHAR(10),
-    "MANUAL_SEVERITY" BOOLEAN NOT NULL,
-    "MESSAGE" VARCHAR(4000),
-    "LINE" INTEGER,
-    "GAP" DOUBLE,
-    "STATUS" VARCHAR(20),
-    "RESOLUTION" VARCHAR(20),
-    "CHECKSUM" VARCHAR(1000),
-    "REPORTER" VARCHAR(255),
-    "ASSIGNEE" VARCHAR(255),
-    "AUTHOR_LOGIN" VARCHAR(255),
-    "ACTION_PLAN_KEY" VARCHAR(50),
-    "ISSUE_ATTRIBUTES" VARCHAR(4000),
-    "EFFORT" INTEGER,
-    "CREATED_AT" BIGINT,
-    "UPDATED_AT" BIGINT,
-    "ISSUE_CREATION_DATE" BIGINT,
-    "ISSUE_UPDATE_DATE" BIGINT,
-    "ISSUE_CLOSE_DATE" BIGINT,
-    "TAGS" VARCHAR(4000),
-    "COMPONENT_UUID" VARCHAR(50),
-    "PROJECT_UUID" VARCHAR(50),
-    "LOCATIONS" BLOB,
-    "ISSUE_TYPE" TINYINT,
-    "FROM_HOTSPOT" BOOLEAN,
-    "RULE_UUID" VARCHAR(40)
-);
-ALTER TABLE "ISSUES" ADD CONSTRAINT "PK_ISSUES" PRIMARY KEY("KEE");
-CREATE INDEX "ISSUES_ASSIGNEE" ON "ISSUES"("ASSIGNEE");
-CREATE INDEX "ISSUES_COMPONENT_UUID" ON "ISSUES"("COMPONENT_UUID");
-CREATE INDEX "ISSUES_CREATION_DATE" ON "ISSUES"("ISSUE_CREATION_DATE");
-CREATE UNIQUE INDEX "ISSUES_KEE" ON "ISSUES"("KEE");
-CREATE INDEX "ISSUES_PROJECT_UUID" ON "ISSUES"("PROJECT_UUID");
-CREATE INDEX "ISSUES_RESOLUTION" ON "ISSUES"("RESOLUTION");
-CREATE INDEX "ISSUES_RULE_UUID" ON "ISSUES"("RULE_UUID");
-CREATE INDEX "ISSUES_UPDATED_AT" ON "ISSUES"("UPDATED_AT");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/rules/issues/PopulateIssuesRuleUuidColumnTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/rules/issues/PopulateIssuesRuleUuidColumnTest/schema.sql
deleted file mode 100644 (file)
index d6c8f6b..0000000
+++ /dev/null
@@ -1,70 +0,0 @@
-CREATE TABLE "RULES"(
-    "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
-    "NAME" VARCHAR(200),
-    "PLUGIN_RULE_KEY" VARCHAR(200) NOT NULL,
-    "PLUGIN_KEY" VARCHAR(200),
-    "PLUGIN_CONFIG_KEY" VARCHAR(200),
-    "PLUGIN_NAME" VARCHAR(255) NOT NULL,
-    "SCOPE" VARCHAR(20) NOT NULL,
-    "DESCRIPTION" CLOB(2147483647),
-    "PRIORITY" INTEGER,
-    "STATUS" VARCHAR(40),
-    "LANGUAGE" VARCHAR(20),
-    "DEF_REMEDIATION_FUNCTION" VARCHAR(20),
-    "DEF_REMEDIATION_GAP_MULT" VARCHAR(20),
-    "DEF_REMEDIATION_BASE_EFFORT" VARCHAR(20),
-    "GAP_DESCRIPTION" VARCHAR(4000),
-    "SYSTEM_TAGS" VARCHAR(4000),
-    "IS_TEMPLATE" BOOLEAN DEFAULT FALSE NOT NULL,
-    "DESCRIPTION_FORMAT" VARCHAR(20),
-    "RULE_TYPE" TINYINT,
-    "SECURITY_STANDARDS" VARCHAR(4000),
-    "IS_AD_HOC" BOOLEAN NOT NULL,
-    "IS_EXTERNAL" BOOLEAN NOT NULL,
-    "CREATED_AT" BIGINT,
-    "UPDATED_AT" BIGINT,
-    "UUID" VARCHAR(40) NOT NULL,
-    "TEMPLATE_UUID" VARCHAR(40)
-);
-ALTER TABLE "RULES" ADD CONSTRAINT "PK_RULES" PRIMARY KEY("ID");
-CREATE UNIQUE INDEX "RULES_REPO_KEY" ON "RULES"("PLUGIN_RULE_KEY", "PLUGIN_NAME");
-
-CREATE TABLE "ISSUES"(
-    "KEE" VARCHAR(50) NOT NULL,
-    "RULE_ID" INTEGER,
-    "SEVERITY" VARCHAR(10),
-    "MANUAL_SEVERITY" BOOLEAN NOT NULL,
-    "MESSAGE" VARCHAR(4000),
-    "LINE" INTEGER,
-    "GAP" DOUBLE,
-    "STATUS" VARCHAR(20),
-    "RESOLUTION" VARCHAR(20),
-    "CHECKSUM" VARCHAR(1000),
-    "REPORTER" VARCHAR(255),
-    "ASSIGNEE" VARCHAR(255),
-    "AUTHOR_LOGIN" VARCHAR(255),
-    "ACTION_PLAN_KEY" VARCHAR(50),
-    "ISSUE_ATTRIBUTES" VARCHAR(4000),
-    "EFFORT" INTEGER,
-    "CREATED_AT" BIGINT,
-    "UPDATED_AT" BIGINT,
-    "ISSUE_CREATION_DATE" BIGINT,
-    "ISSUE_UPDATE_DATE" BIGINT,
-    "ISSUE_CLOSE_DATE" BIGINT,
-    "TAGS" VARCHAR(4000),
-    "COMPONENT_UUID" VARCHAR(50),
-    "PROJECT_UUID" VARCHAR(50),
-    "LOCATIONS" BLOB,
-    "ISSUE_TYPE" TINYINT,
-    "FROM_HOTSPOT" BOOLEAN,
-    "RULE_UUID" VARCHAR(40)
-);
-ALTER TABLE "ISSUES" ADD CONSTRAINT "PK_ISSUES" PRIMARY KEY("KEE");
-CREATE INDEX "ISSUES_ASSIGNEE" ON "ISSUES"("ASSIGNEE");
-CREATE INDEX "ISSUES_COMPONENT_UUID" ON "ISSUES"("COMPONENT_UUID");
-CREATE INDEX "ISSUES_CREATION_DATE" ON "ISSUES"("ISSUE_CREATION_DATE");
-CREATE UNIQUE INDEX "ISSUES_KEE" ON "ISSUES"("KEE");
-CREATE INDEX "ISSUES_PROJECT_UUID" ON "ISSUES"("PROJECT_UUID");
-CREATE INDEX "ISSUES_RESOLUTION" ON "ISSUES"("RESOLUTION");
-CREATE INDEX "ISSUES_RULE_ID" ON "ISSUES"("RULE_ID");
-CREATE INDEX "ISSUES_UPDATED_AT" ON "ISSUES"("UPDATED_AT");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/rules/issues/RenameIssuesCopyToIssuesTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/rules/issues/RenameIssuesCopyToIssuesTest/schema.sql
new file mode 100644 (file)
index 0000000..0c3fc02
--- /dev/null
@@ -0,0 +1,30 @@
+CREATE TABLE "ISSUES_COPY"(
+    "KEE" VARCHAR(50) NOT NULL,
+    "RULE_ID" INTEGER,
+    "SEVERITY" VARCHAR(10),
+    "MANUAL_SEVERITY" BOOLEAN NOT NULL,
+    "MESSAGE" VARCHAR(4000),
+    "LINE" INTEGER,
+    "GAP" DOUBLE,
+    "STATUS" VARCHAR(20),
+    "RESOLUTION" VARCHAR(20),
+    "CHECKSUM" VARCHAR(1000),
+    "REPORTER" VARCHAR(255),
+    "ASSIGNEE" VARCHAR(255),
+    "AUTHOR_LOGIN" VARCHAR(255),
+    "ACTION_PLAN_KEY" VARCHAR(50),
+    "ISSUE_ATTRIBUTES" VARCHAR(4000),
+    "EFFORT" INTEGER,
+    "CREATED_AT" BIGINT,
+    "UPDATED_AT" BIGINT,
+    "ISSUE_CREATION_DATE" BIGINT,
+    "ISSUE_UPDATE_DATE" BIGINT,
+    "ISSUE_CLOSE_DATE" BIGINT,
+    "TAGS" VARCHAR(4000),
+    "COMPONENT_UUID" VARCHAR(50),
+    "PROJECT_UUID" VARCHAR(50),
+    "LOCATIONS" BLOB,
+    "ISSUE_TYPE" TINYINT,
+    "FROM_HOTSPOT" BOOLEAN,
+    "RULE_UUID" VARCHAR(40)
+);