From f3bd6c51bb1e2db5e704d755ee0a08a18d56eaf1 Mon Sep 17 00:00:00 2001 From: Duarte Meneses Date: Thu, 11 Jun 2020 10:46:57 -0500 Subject: [PATCH] Optimize database migrations --- server/sonar-db-dao/src/schema/schema-sq.ddl | 14 +- .../db/migration/sql/CreateIndexBuilder.java | 18 +- .../migration/sql/CreateTableAsBuilder.java | 118 +++++++ .../db/migration/sql/RenameTableBuilder.java | 3 +- .../db/migration/version/v84/DbVersion84.java | 315 +++++++++--------- ...ddIndexOnIssueKeyOfIssueChangesTable.java} | 42 ++- .../AddIndexOnKeeOfIssueChangesTable.java} | 24 +- .../issuechanges/CopyIssueChangesTable.java | 62 ++++ .../DropIdColumnOfIssueChangesTable.java | 31 -- ...sTable.java => DropIssueChangesTable.java} | 14 +- ...imaryKeyOnIdColumnOfIssueChangesTable.java | 32 -- .../PopulateIssueChangesUuid.java | 50 --- .../RenameIssueChangesCopyToIssueChanges.java | 39 +++ ...AddPrimaryKeyOnKeeColumnOfIssuesTable.java | 3 +- .../v84/issues/DropIdColumnOfIssuesTable.java | 31 -- ...DropPrimaryKeyOnIdColumnOfIssuesTable.java | 32 -- .../v84/metrics/PopulateMetricsUuid.java | 12 +- ...ndexOnProjectUuidOfLiveMeasuresTable.java} | 27 +- .../AddMetricUuidColumnToLiveMeasures.java | 50 --- ... => AddPKeyOnUuidOfLiveMeasuresTable.java} | 10 +- .../livemeasures/CopyLiveMeasuresTable.java | 69 ++++ .../livemeasures/DropLiveMeasuresTable.java} | 16 +- .../PopulateLiveMeasuresMetricUuid.java | 59 ---- .../RenameLiveMeasuresCopyToLiveMeasures.java | 39 +++ .../version/v84/rules/PopulateRulesUuid.java | 12 +- .../rules/issues/AddIndexesToIssuesTable.java | 105 ++++++ .../AddRuleUuidColumnToIssuesTable.java | 49 --- .../v84/rules/issues/CopyIssuesTable.java | 104 ++++++ ...fIssuesTable.java => DropIssuesTable.java} | 12 +- .../issues/PopulateIssuesRuleUuidColumn.java | 49 --- ...ble.java => RenameIssuesCopyToIssues.java} | 18 +- .../migration/sql/CreateIndexBuilderTest.java | 2 +- .../sql/CreateTableAsBuilderTest.java | 89 +++++ ...ndexOnIssueKeyOfIssueChangesTableTest.java | 50 +++ ...AddIndexOnKeeOfIssueChangesTableTest.java} | 22 +- .../AddUuidColumnToIssueChangesTableTest.java | 65 ---- .../CopyIssueChangesTableTest.java | 48 +++ ...st.java => DropIssueChangesTableTest.java} | 24 +- ...yKeyOnIdColumnOfIssueChangesTableTest.java | 55 --- .../PopulateIssueChangesUuidTest.java | 80 ----- ...meIssueChangesCopyToIssueChangesTest.java} | 16 +- ...PrimaryKeyOnIdColumnOfIssuesTableTest.java | 55 --- .../v84/metrics/PopulateMetricsUuidTest.java | 79 ----- ...xOnProjectUuidOfLiveMeasuresTableTest.java | 50 +++ ...AddMetricUuidColumnToLiveMeasuresTest.java | 64 ---- ...st.java => CopyLiveMeasuresTableTest.java} | 26 +- ...st.java => DropLiveMeasuresTableTest.java} | 18 +- .../PopulateLiveMeasuresMetricUuidTest.java | 120 ------- ...meLiveMeasuresCopyToLiveMeasuresTest.java} | 17 +- .../v84/rules/PopulateRulesUuidTest.java | 73 ---- ....java => AddIndexesToIssuesTableTest.java} | 6 +- .../AddRuleUuidColumnToIssuesTableTest.java | 81 ----- .../v84/rules/issues/CopyIssuesTableTest.java | 48 +++ ...ableTest.java => DropIssuesTableTest.java} | 18 +- .../PopulateIssuesRuleUuidColumnTest.java | 87 ----- ...java => RenameIssuesCopyToIssuesTest.java} | 23 +- .../schema.sql | 4 - .../schema.sql | 11 + .../schema.sql | 1 - .../schema.sql | 1 - .../schema.sql | 15 +- .../schema.sql | 15 - .../PopulateIssueChangesUuidTest/schema.sql | 15 - .../schema.sql | 11 + .../schema.sql | 5 +- .../schema.sql | 6 +- .../schema.sql | 0 .../schema.sql | 15 +- .../schema.sql | 17 - .../schema.sql | 39 --- .../schema.sql | 13 + .../AddIndexToIssuesTableTest/schema.sql | 69 ---- .../AddIndexesToIssuesTableTest}/schema.sql | 12 +- .../schema.sql | 69 ---- .../issues/CopyIssuesTableTest}/schema.sql | 0 .../schema.sql | 60 ++-- .../schema.sql | 70 ---- .../schema.sql | 70 ---- .../RenameIssuesCopyToIssuesTest/schema.sql | 30 ++ 79 files changed, 1307 insertions(+), 1916 deletions(-) create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/sql/CreateTableAsBuilder.java rename server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/{metrics/livemeasures/MakeLiveMeasuresMetricUuidNotNullable.java => issuechanges/AddIndexOnIssueKeyOfIssueChangesTable.java} (53%) rename server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/{metrics/livemeasures/DropIndexOnMetricIdOfLiveMeasuresTable.java => issuechanges/AddIndexOnKeeOfIssueChangesTable.java} (65%) create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/CopyIssueChangesTable.java delete mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/DropIdColumnOfIssueChangesTable.java rename server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/{AddUuidColumnToIssueChangesTable.java => DropIssueChangesTable.java} (68%) delete mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/DropPrimaryKeyOnIdColumnOfIssueChangesTable.java delete mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/PopulateIssueChangesUuid.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/RenameIssueChangesCopyToIssueChanges.java delete mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/issues/DropIdColumnOfIssuesTable.java delete mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/issues/DropPrimaryKeyOnIdColumnOfIssuesTable.java rename server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/{rules/issues/AddIndexToIssuesTable.java => metrics/livemeasures/AddIndexOnProjectUuidOfLiveMeasuresTable.java} (71%) delete mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/AddMetricUuidColumnToLiveMeasures.java rename server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/{DropMetricIdColumnOfLiveMeasuresTable.java => AddPKeyOnUuidOfLiveMeasuresTable.java} (76%) create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/CopyLiveMeasuresTable.java rename server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/{issuechanges/MakeIssueChangesUuidColumnNotNullable.java => metrics/livemeasures/DropLiveMeasuresTable.java} (63%) delete mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/PopulateLiveMeasuresMetricUuid.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/RenameLiveMeasuresCopyToLiveMeasures.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/AddIndexesToIssuesTable.java delete mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/AddRuleUuidColumnToIssuesTable.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/CopyIssuesTable.java rename server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/{DropRuleIdColumnOfIssuesTable.java => DropIssuesTable.java} (75%) delete mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/PopulateIssuesRuleUuidColumn.java rename server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/{DropIndexOnRuleIdColumnOfIssuesTable.java => RenameIssuesCopyToIssues.java} (73%) create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/sql/CreateTableAsBuilderTest.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/AddIndexOnIssueKeyOfIssueChangesTableTest.java rename server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/{issues/DropIdColumnOfIssuesTableTest.java => issuechanges/AddIndexOnKeeOfIssueChangesTableTest.java} (67%) delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/AddUuidColumnToIssueChangesTableTest.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/CopyIssueChangesTableTest.java rename server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/{DropIdColumnOfIssueChangesTableTest.java => DropIssueChangesTableTest.java} (66%) delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/DropPrimaryKeyOnIdColumnOfIssueChangesTableTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/PopulateIssueChangesUuidTest.java rename server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/{MakeIssueChangesUuidColumnNotNullableTest.java => RenameIssueChangesCopyToIssueChangesTest.java} (71%) delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/issues/DropPrimaryKeyOnIdColumnOfIssuesTableTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/metrics/PopulateMetricsUuidTest.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/AddIndexOnProjectUuidOfLiveMeasuresTableTest.java delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/AddMetricUuidColumnToLiveMeasuresTest.java rename server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/{DropMetricIdColumnOfLiveMeasuresTableTest.java => CopyLiveMeasuresTableTest.java} (59%) rename server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/{DropIndexOnMetricIdOfLiveMeasuresTableTest.java => DropLiveMeasuresTableTest.java} (72%) delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/PopulateLiveMeasuresMetricUuidTest.java rename server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/{MakeLiveMeasuresMetricUuidNotNullableTest.java => RenameLiveMeasuresCopyToLiveMeasuresTest.java} (65%) delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/rules/PopulateRulesUuidTest.java rename server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/{AddIndexToIssuesTableTest.java => AddIndexesToIssuesTableTest.java} (90%) delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/AddRuleUuidColumnToIssuesTableTest.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/CopyIssuesTableTest.java rename server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/{DropIndexOnRuleIdColumnOfIssuesTableTest.java => DropIssuesTableTest.java} (75%) delete mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/PopulateIssuesRuleUuidColumnTest.java rename server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/{DropRuleIdColumnOfIssuesTableTest.java => RenameIssuesCopyToIssuesTest.java} (64%) rename server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/issuechanges/{DropPrimaryKeyOnIdColumnOfIssueChangesTableTest => AddIndexOnIssueKeyOfIssueChangesTableTest}/schema.sql (54%) create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/issuechanges/AddIndexOnKeeOfIssueChangesTableTest/schema.sql rename server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/issuechanges/{AddUuidColumnToIssueChangesTableTest => CopyIssueChangesTableTest}/schema.sql (85%) rename server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/issuechanges/{DropIdColumnOfIssueChangesTableTest => DropIssueChangesTableTest}/schema.sql (63%) delete mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/issuechanges/MakeIssueChangesUuidColumnNotNullableTest/schema.sql delete mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/issuechanges/PopulateIssueChangesUuidTest/schema.sql create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/issuechanges/RenameIssueChangesCopyToIssueChangesTest/schema.sql rename server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/{MakeLiveMeasuresMetricUuidNotNullableTest => AddIndexOnProjectUuidOfLiveMeasuresTableTest}/schema.sql (52%) rename server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/{AddMetricUuidColumnToLiveMeasuresTest => CopyLiveMeasuresTableTest}/schema.sql (100%) rename server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/{DropIndexOnMetricIdOfLiveMeasuresTableTest => DropLiveMeasuresTableTest}/schema.sql (61%) delete mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/DropMetricIdColumnOfLiveMeasuresTableTest/schema.sql delete mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/PopulateLiveMeasuresMetricUuidTest/schema.sql create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/RenameLiveMeasuresCopyToLiveMeasuresTest/schema.sql delete mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/rules/issues/AddIndexToIssuesTableTest/schema.sql rename server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/{issues/DropIdColumnOfIssuesTableTest => rules/issues/AddIndexesToIssuesTableTest}/schema.sql (60%) delete mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/rules/issues/AddRuleUuidColumnToIssuesTableTest/schema.sql rename server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/{issues/DropPrimaryKeyOnIdColumnOfIssuesTableTest => rules/issues/CopyIssuesTableTest}/schema.sql (100%) rename server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/rules/issues/{DropIndexOnRuleIdColumnOfIssuesTableTest => DropIssuesTableTest}/schema.sql (55%) delete mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/rules/issues/DropRuleIdColumnOfIssuesTableTest/schema.sql delete mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/rules/issues/PopulateIssuesRuleUuidColumnTest/schema.sql create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/rules/issues/RenameIssuesCopyToIssuesTest/schema.sql diff --git a/server/sonar-db-dao/src/schema/schema-sq.ddl b/server/sonar-db-dao/src/schema/schema-sq.ddl index 106647743ed..8367ba17026 100644 --- a/server/sonar-db-dao/src/schema/schema-sq.ddl +++ b/server/sonar-db-dao/src/schema/schema-sq.ddl @@ -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"); diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/sql/CreateIndexBuilder.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/sql/CreateIndexBuilder.java index 4a73626554c..0d6e710f619 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/sql/CreateIndexBuilder.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/sql/CreateIndexBuilder.java @@ -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 columns = new ArrayList<>(); + private final List 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 index 00000000000..2adc1309f16 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/sql/CreateTableAsBuilder.java @@ -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 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 build() { + checkState(!columns.isEmpty(), "Columns need to be specified"); + + List 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 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; + } + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/sql/RenameTableBuilder.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/sql/RenameTableBuilder.java index a6e2453e451..c0c73e1a68e 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/sql/RenameTableBuilder.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/sql/RenameTableBuilder.java @@ -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); diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/DbVersion84.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/DbVersion84.java index 811bb596e04..af5f746ee8e 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/DbVersion84.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/DbVersion84.java @@ -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/metrics/livemeasures/MakeLiveMeasuresMetricUuidNotNullable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/AddIndexOnIssueKeyOfIssueChangesTable.java similarity index 53% rename from server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/MakeLiveMeasuresMetricUuidNotNullable.java rename to server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/AddIndexOnIssueKeyOfIssueChangesTable.java index 11b72b28723..9e39b935d50 100644 --- 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/issuechanges/AddIndexOnIssueKeyOfIssueChangesTable.java @@ -17,34 +17,44 @@ * 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; +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.server.platform.db.migration.def.VarcharColumnDef; -import org.sonar.server.platform.db.migration.sql.AlterColumnsBuilder; +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 MakeLiveMeasuresMetricUuidNotNullable extends DdlChange { - private static final String TABLE = "live_measures"; +public class AddIndexOnIssueKeyOfIssueChangesTable extends DdlChange { + private static final String TABLE_NAME = "issue_changes"; + private static final String INDEX_NAME = "issue_changes_issue_key"; - private static final VarcharColumnDef uuidColumnDefinition = newVarcharColumnDefBuilder() - .setColumnName("metric_uuid") - .setIsNullable(false) - .setDefaultValue(null) - .setLimit(VarcharColumnDef.UUID_SIZE) - .build(); - - public MakeLiveMeasuresMetricUuidNotNullable(Database db) { + public AddIndexOnIssueKeyOfIssueChangesTable(Database db) { super(db); } @Override public void execute(Context context) throws SQLException { - context.execute(new AlterColumnsBuilder(getDialect(), TABLE) - .updateColumn(uuidColumnDefinition) - .build()); + 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/metrics/livemeasures/DropIndexOnMetricIdOfLiveMeasuresTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/AddIndexOnKeeOfIssueChangesTable.java similarity index 65% rename from server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/DropIndexOnMetricIdOfLiveMeasuresTable.java rename to server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/AddIndexOnKeeOfIssueChangesTable.java index 08b63ea0caf..56cb5019ae1 100644 --- 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/issuechanges/AddIndexOnKeeOfIssueChangesTable.java @@ -17,29 +17,37 @@ * 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; +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.DropIndexBuilder; +import org.sonar.server.platform.db.migration.sql.CreateIndexBuilder; 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"; +import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder; - public DropIndexOnMetricIdOfLiveMeasuresTable(Database db) { +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 DropIndexBuilder(getDialect()) + if (!indexExists()) { + context.execute(new CreateIndexBuilder() + .setUnique(false) .setTable(TABLE_NAME) .setName(INDEX_NAME) + .addColumn(newVarcharColumnDefBuilder() + .setColumnName("kee") + .setIsNullable(true) + .setLimit(50) + .build()) .build()); } } 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 index 00000000000..344f9842f43 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/CopyIssueChangesTable.java @@ -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 index 3855775af41..00000000000 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/DropIdColumnOfIssueChangesTable.java +++ /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/AddUuidColumnToIssueChangesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/DropIssueChangesTable.java similarity index 68% rename from server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/AddUuidColumnToIssueChangesTable.java rename to server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/DropIssueChangesTable.java index 5e230a55fac..7584e1ff473 100644 --- 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/DropIssueChangesTable.java @@ -19,13 +19,17 @@ */ 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.version.v84.common.AddUuidColumnToTable; +import org.sonar.server.platform.db.migration.sql.DropTableBuilder; +import org.sonar.server.platform.db.migration.step.DdlChange; -public class AddUuidColumnToIssueChangesTable extends AddUuidColumnToTable { - private static final String TABLE = "issue_changes"; +public class DropIssueChangesTable extends DdlChange { + public DropIssueChangesTable(Database db) { + super(db); + } - public AddUuidColumnToIssueChangesTable(Database db) { - super(db, TABLE); + @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 index 99e83714900..00000000000 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/DropPrimaryKeyOnIdColumnOfIssueChangesTable.java +++ /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/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 index d965a14170e..00000000000 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/PopulateIssueChangesUuid.java +++ /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 index 00000000000..5f9d698f9b7 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/RenameIssueChangesCopyToIssueChanges.java @@ -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()); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/issues/AddPrimaryKeyOnKeeColumnOfIssuesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/issues/AddPrimaryKeyOnKeeColumnOfIssuesTable.java index 71d552a0b21..9210d878ee2 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/issues/AddPrimaryKeyOnKeeColumnOfIssuesTable.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/issues/AddPrimaryKeyOnKeeColumnOfIssuesTable.java @@ -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 index 22726ff29f3..00000000000 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/issues/DropIdColumnOfIssuesTable.java +++ /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 index 59427acb800..00000000000 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/issues/DropPrimaryKeyOnIdColumnOfIssuesTable.java +++ /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); - } -} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/metrics/PopulateMetricsUuid.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/metrics/PopulateMetricsUuid.java index 55579431c54..132769bba16 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/metrics/PopulateMetricsUuid.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/metrics/PopulateMetricsUuid.java @@ -20,18 +20,13 @@ 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/rules/issues/AddIndexToIssuesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/AddIndexOnProjectUuidOfLiveMeasuresTable.java similarity index 71% rename from server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/AddIndexToIssuesTable.java rename to server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/AddIndexOnProjectUuidOfLiveMeasuresTable.java index 91d8ba9152e..0a257945a07 100644 --- 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/metrics/livemeasures/AddIndexOnProjectUuidOfLiveMeasuresTable.java @@ -17,7 +17,7 @@ * 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; +package org.sonar.server.platform.db.migration.version.v84.metrics.livemeasures; import java.sql.Connection; import java.sql.SQLException; @@ -29,17 +29,11 @@ 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"; +public class AddIndexOnProjectUuidOfLiveMeasuresTable extends DdlChange { + private static final String TABLE_NAME = "live_measures"; + private static final String INDEX_NAME = "live_measures_project"; - private static final VarcharColumnDef uuidColumnDefinition = newVarcharColumnDefBuilder() - .setColumnName("rule_uuid") - .setIsNullable(true) - .setLimit(VarcharColumnDef.UUID_SIZE) - .build(); - - public AddIndexToIssuesTable(Database db) { + public AddIndexOnProjectUuidOfLiveMeasuresTable(Database db) { super(db); } @@ -47,16 +41,21 @@ public class AddIndexToIssuesTable extends DdlChange { public void execute(Context context) throws SQLException { if (!indexExists()) { context.execute(new CreateIndexBuilder() - .setTable(TABLE) + .setUnique(false) + .setTable(TABLE_NAME) .setName(INDEX_NAME) - .addColumn(uuidColumnDefinition) + .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, INDEX_NAME, connection); + 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 index bd0a5488e2b..00000000000 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/AddMetricUuidColumnToLiveMeasures.java +++ /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/DropMetricIdColumnOfLiveMeasuresTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/AddPKeyOnUuidOfLiveMeasuresTable.java similarity index 76% rename from server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/DropMetricIdColumnOfLiveMeasuresTable.java rename to server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/AddPKeyOnUuidOfLiveMeasuresTable.java index 708532d5e9e..b1fefefb145 100644 --- 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/AddPKeyOnUuidOfLiveMeasuresTable.java @@ -21,16 +21,18 @@ 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; +import org.sonar.server.platform.db.migration.version.v84.util.AddPrimaryKeyBuilder; -public class DropMetricIdColumnOfLiveMeasuresTable extends DdlChange { - public DropMetricIdColumnOfLiveMeasuresTable(Database db) { +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 DropColumnsBuilder(getDialect(), "live_measures", "metric_id").build()); + 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 index 00000000000..380469ee3ca --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/CopyLiveMeasuresTable.java @@ -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/issuechanges/MakeIssueChangesUuidColumnNotNullable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/DropLiveMeasuresTable.java similarity index 63% rename from server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/MakeIssueChangesUuidColumnNotNullable.java rename to server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/DropLiveMeasuresTable.java index 348213722c5..db77363fe00 100644 --- 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/metrics/livemeasures/DropLiveMeasuresTable.java @@ -17,15 +17,19 @@ * 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; +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.version.v84.common.MakeUuidColumnNotNullable; +import org.sonar.server.platform.db.migration.sql.DropTableBuilder; +import org.sonar.server.platform.db.migration.step.DdlChange; -public class MakeIssueChangesUuidColumnNotNullable extends MakeUuidColumnNotNullable { - private static final String TABLE = "issue_changes"; +public class DropLiveMeasuresTable extends DdlChange { + public DropLiveMeasuresTable(Database db) { + super(db); + } - public MakeIssueChangesUuidColumnNotNullable(Database db) { - super(db, TABLE); + @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/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 index 7170806661a..00000000000 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/PopulateLiveMeasuresMetricUuid.java +++ /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 index 00000000000..4758826aff3 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/RenameLiveMeasuresCopyToLiveMeasures.java @@ -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()); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rules/PopulateRulesUuid.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rules/PopulateRulesUuid.java index b21c99813f2..d889e1c7cfc 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rules/PopulateRulesUuid.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rules/PopulateRulesUuid.java @@ -20,18 +20,13 @@ 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/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 index 00000000000..f0f8aa59a2f --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/AddIndexesToIssuesTable.java @@ -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 index 037cf2f9837..00000000000 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/AddRuleUuidColumnToIssuesTable.java +++ /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 index 00000000000..324839b858d --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/CopyIssuesTable.java @@ -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/DropRuleIdColumnOfIssuesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/DropIssuesTable.java similarity index 75% rename from server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/DropRuleIdColumnOfIssuesTable.java rename to server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/DropIssuesTable.java index 18a1e15f674..a1d440b1e6e 100644 --- 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/DropIssuesTable.java @@ -21,17 +21,15 @@ 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.sql.DropTableBuilder; import org.sonar.server.platform.db.migration.step.DdlChange; -public class DropRuleIdColumnOfIssuesTable extends DdlChange { - - public DropRuleIdColumnOfIssuesTable(Database db) { +public class DropIssuesTable extends DdlChange { + public DropIssuesTable(Database db) { super(db); } - @Override - public void execute(Context context) throws SQLException { - context.execute(new DropColumnsBuilder(getDialect(), "issues", "rule_id").build()); + @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/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 index fe8ba94786e..00000000000 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/PopulateIssuesRuleUuidColumn.java +++ /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/DropIndexOnRuleIdColumnOfIssuesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/RenameIssuesCopyToIssues.java similarity index 73% rename from server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/DropIndexOnRuleIdColumnOfIssuesTable.java rename to server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/RenameIssuesCopyToIssues.java index 623e33c5ffd..a9147d47a9c 100644 --- 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/RenameIssuesCopyToIssues.java @@ -21,21 +21,19 @@ 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.sql.RenameTableBuilder; import org.sonar.server.platform.db.migration.step.DdlChange; -public class DropIndexOnRuleIdColumnOfIssuesTable extends DdlChange { - - public DropIndexOnRuleIdColumnOfIssuesTable(Database db) { +public class RenameIssuesCopyToIssues extends DdlChange { + public RenameIssuesCopyToIssues(Database db) { super(db); } - @Override - public void execute(Context context) throws SQLException { - context.execute(new DropIndexBuilder(getDialect()) - .setTable("issues") - .setName("issues_rule_id") + @Override public void execute(Context context) throws SQLException { + context.execute(new RenameTableBuilder(getDialect()) + .setName("issues_copy") + .setNewName("issues") + .setAutoGeneratedId(false) .build()); } - } diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/sql/CreateIndexBuilderTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/sql/CreateIndexBuilderTest.java index d0f6704fc88..9371374dd67 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/sql/CreateIndexBuilderTest.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/sql/CreateIndexBuilderTest.java @@ -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 index 00000000000..8ed75c437ed --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/sql/CreateTableAsBuilderTest.java @@ -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 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 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 index 00000000000..307dd0c83ba --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/AddIndexOnIssueKeyOfIssueChangesTableTest.java @@ -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/issues/DropIdColumnOfIssuesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/AddIndexOnKeeOfIssueChangesTableTest.java similarity index 67% rename from server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/issues/DropIdColumnOfIssuesTableTest.java rename to server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/AddIndexOnKeeOfIssueChangesTableTest.java index 2bc4ddb096a..0d7aea5fccc 100644 --- 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/issuechanges/AddIndexOnKeeOfIssueChangesTableTest.java @@ -17,34 +17,34 @@ * 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; +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 org.assertj.core.api.Assertions.assertThatThrownBy; - -public class DropIdColumnOfIssuesTableTest { - +public class AddIndexOnKeeOfIssueChangesTableTest { @Rule - public CoreDbTester db = CoreDbTester.createForSchema(DropIdColumnOfIssuesTableTest.class, "schema.sql"); + public CoreDbTester db = CoreDbTester.createForSchema(AddIndexOnKeeOfIssueChangesTableTest.class, "schema.sql"); - private DropIdColumnOfIssuesTable underTest = new DropIdColumnOfIssuesTable(db.database()); + private MigrationStep underTest = new AddIndexOnKeeOfIssueChangesTable(db.database()); @Test public void execute() throws SQLException { underTest.execute(); - db.assertColumnDoesNotExist("issues", "id"); + db.assertIndex("issue_changes", "issue_changes_kee", "kee"); } @Test - public void migration_is_not_re_entrant() throws SQLException { + public void migration_is_re_entrant() throws SQLException { underTest.execute(); - assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class); - } + // 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 index 3111075056c..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/AddUuidColumnToIssueChangesTableTest.java +++ /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 index 00000000000..a1960359d45 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/CopyIssueChangesTableTest.java @@ -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/DropIssueChangesTableTest.java similarity index 66% rename from server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/DropIdColumnOfIssueChangesTableTest.java rename to server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/DropIssueChangesTableTest.java index 87f32b9338c..4a6189d9bb9 100644 --- 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/DropIssueChangesTableTest.java @@ -23,29 +23,29 @@ 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 { +import org.sonar.server.platform.db.migration.step.MigrationStep; +public class DropIssueChangesTableTest { @Rule - public CoreDbTester db = CoreDbTester.createForSchema(DropIdColumnOfIssueChangesTableTest.class, "schema.sql"); + public CoreDbTester db = CoreDbTester.createForSchema(DropIssueChangesTableTest.class, "schema.sql"); - private DdlChange underTest = new DropIdColumnOfIssueChangesTable(db.database()); + private MigrationStep underTest = new DropIssueChangesTable(db.database()); @Test public void execute() throws SQLException { + db.assertTableExists("issue_changes"); underTest.execute(); - - db.assertColumnDoesNotExist("issue_changes", "id"); + db.assertTableDoesNotExist("issue_changes"); } @Test - public void migration_is_not_re_entrant() throws SQLException { + public void migration_is_re_entrant() throws SQLException { + db.assertTableExists("issue_changes"); + underTest.execute(); - assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class); + // 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 index f72a917f9f9..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/DropPrimaryKeyOnIdColumnOfIssueChangesTableTest.java +++ /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/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 index f1bc28029d6..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/PopulateIssueChangesUuidTest.java +++ /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/MakeIssueChangesUuidColumnNotNullableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/RenameIssueChangesCopyToIssueChangesTest.java similarity index 71% rename from server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/MakeIssueChangesUuidColumnNotNullableTest.java rename to server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/issuechanges/RenameIssueChangesCopyToIssueChangesTest.java index 140028755f2..f383c464bd4 100644 --- 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/RenameIssueChangesCopyToIssueChangesTest.java @@ -25,18 +25,18 @@ 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 { +public class RenameIssueChangesCopyToIssueChangesTest { @Rule - public CoreDbTester db = CoreDbTester.createForSchema(MakeIssueChangesUuidColumnNotNullableTest.class, "schema.sql"); + public CoreDbTester db = CoreDbTester.createForSchema(RenameIssueChangesCopyToIssueChangesTest.class, "schema.sql"); - private MigrationStep underTest = new MakeIssueChangesUuidColumnNotNullable(db.database()); + private MigrationStep underTest = new RenameIssueChangesCopyToIssueChanges(db.database()); @Test - public void uuid_column_is_not_nullable() throws SQLException { - underTest.execute(); + public void execute() throws SQLException { + db.assertTableExists("issue_changes_copy"); + db.assertTableDoesNotExist("issue_changes"); - db.assertColumnDefinition("issue_changes", "uuid", VARCHAR, null, false); + 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/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 index 19d47da9c77..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/issues/DropPrimaryKeyOnIdColumnOfIssuesTableTest.java +++ /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 index 49d55677a45..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/metrics/PopulateMetricsUuidTest.java +++ /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 index 00000000000..02eaac8e7fe --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/AddIndexOnProjectUuidOfLiveMeasuresTableTest.java @@ -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 index cf2a3298f11..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/AddMetricUuidColumnToLiveMeasuresTest.java +++ /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/DropMetricIdColumnOfLiveMeasuresTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/CopyLiveMeasuresTableTest.java similarity index 59% rename from server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/DropMetricIdColumnOfLiveMeasuresTableTest.java rename to server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/CopyLiveMeasuresTableTest.java index 2991811ff20..7c3530a06fe 100644 --- 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/CopyLiveMeasuresTableTest.java @@ -24,27 +24,25 @@ 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 org.sonar.server.platform.db.migration.step.MigrationStep; +import org.sonar.server.platform.db.migration.version.v84.rules.issues.CopyIssuesTable; -import static org.assertj.core.api.Assertions.assertThatThrownBy; - -public class DropMetricIdColumnOfLiveMeasuresTableTest { +public class CopyLiveMeasuresTableTest { @Rule - public CoreDbTester db = CoreDbTester.createForSchema(DropMetricIdColumnOfLiveMeasuresTableTest.class, "schema.sql"); + public CoreDbTester db = CoreDbTester.createForSchema(CopyLiveMeasuresTableTest.class, "schema.sql"); - private DdlChange underTest = new DropMetricIdColumnOfLiveMeasuresTable(db.database()); + private MigrationStep underTest = new CopyLiveMeasuresTable(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"); - } + db.assertTableExists("live_measures"); + db.assertTableDoesNotExist("live_measures_copy"); - @Test - public void migration_is_not_re_entrant() throws SQLException { underTest.execute(); - - assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class); + 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/DropLiveMeasuresTableTest.java similarity index 72% rename from server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/DropIndexOnMetricIdOfLiveMeasuresTableTest.java rename to server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/DropLiveMeasuresTableTest.java index 042b2045a80..9e86cda3ee7 100644 --- 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/DropLiveMeasuresTableTest.java @@ -24,31 +24,29 @@ 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 DropIndexOnMetricIdOfLiveMeasuresTableTest { - +public class DropLiveMeasuresTableTest { @Rule - public CoreDbTester db = CoreDbTester.createForSchema(DropIndexOnMetricIdOfLiveMeasuresTableTest.class, "schema.sql"); + public CoreDbTester db = CoreDbTester.createForSchema(DropLiveMeasuresTableTest.class, "schema.sql"); - private MigrationStep underTest = new DropIndexOnMetricIdOfLiveMeasuresTable(db.database()); + private MigrationStep underTest = new DropLiveMeasuresTable(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"); + db.assertTableDoesNotExist("live_measures"); } @Test public void migration_is_re_entrant() throws SQLException { + db.assertTableExists("live_measures"); + underTest.execute(); // re-entrant underTest.execute(); - - db.assertIndexDoesNotExist("live_measures", "live_measures_component"); + db.assertTableDoesNotExist("live_measures"); } } 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 index b3c0e3c076c..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/PopulateLiveMeasuresMetricUuidTest.java +++ /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> 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/MakeLiveMeasuresMetricUuidNotNullableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/RenameLiveMeasuresCopyToLiveMeasuresTest.java similarity index 65% rename from server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/MakeLiveMeasuresMetricUuidNotNullableTest.java rename to server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/RenameLiveMeasuresCopyToLiveMeasuresTest.java index 136d8375fb0..e10abb28184 100644 --- 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/RenameLiveMeasuresCopyToLiveMeasuresTest.java @@ -24,19 +24,22 @@ 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; -import static java.sql.Types.VARCHAR; - -public class MakeLiveMeasuresMetricUuidNotNullableTest { +public class RenameLiveMeasuresCopyToLiveMeasuresTest { @Rule - public CoreDbTester db = CoreDbTester.createForSchema(MakeLiveMeasuresMetricUuidNotNullableTest.class, "schema.sql"); + public CoreDbTester db = CoreDbTester.createForSchema(RenameLiveMeasuresCopyToLiveMeasuresTest.class, "schema.sql"); - private MigrationStep underTest = new MakeLiveMeasuresMetricUuidNotNullable(db.database()); + private MigrationStep underTest = new RenameLiveMeasuresCopyToLiveMeasures(db.database()); @Test - public void uuid_column_is_not_null() throws SQLException { + 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"); - 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/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 index 332b18315bd..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/rules/PopulateRulesUuidTest.java +++ /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/AddIndexesToIssuesTableTest.java similarity index 90% rename from server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/AddIndexToIssuesTableTest.java rename to server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/AddIndexesToIssuesTableTest.java index 5e132b4c0b5..1432a773897 100644 --- 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/AddIndexesToIssuesTableTest.java @@ -25,12 +25,12 @@ import org.junit.Test; import org.sonar.db.CoreDbTester; import org.sonar.server.platform.db.migration.step.MigrationStep; -public class AddIndexToIssuesTableTest { +public class AddIndexesToIssuesTableTest { @Rule - public CoreDbTester db = CoreDbTester.createForSchema(AddIndexToIssuesTableTest.class, "schema.sql"); + public CoreDbTester db = CoreDbTester.createForSchema(AddIndexesToIssuesTableTest.class, "schema.sql"); - private MigrationStep underTest = new AddIndexToIssuesTable(db.database()); + private MigrationStep underTest = new AddIndexesToIssuesTable(db.database()); @Test public void execute() throws SQLException { 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 index 11648e1d21e..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/AddRuleUuidColumnToIssuesTableTest.java +++ /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 index 00000000000..632b04b1cbb --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/CopyIssuesTableTest.java @@ -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/DropIssuesTableTest.java similarity index 75% rename from server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/DropIndexOnRuleIdColumnOfIssuesTableTest.java rename to server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/DropIssuesTableTest.java index 0838ca20372..a407edbfba8 100644 --- 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/DropIssuesTableTest.java @@ -24,31 +24,29 @@ 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 DropIndexOnRuleIdColumnOfIssuesTableTest { - +public class DropIssuesTableTest { @Rule - public CoreDbTester db = CoreDbTester.createForSchema(DropIndexOnRuleIdColumnOfIssuesTableTest.class, "schema.sql"); + public CoreDbTester db = CoreDbTester.createForSchema(DropIssuesTableTest.class, "schema.sql"); - private MigrationStep underTest = new DropIndexOnRuleIdColumnOfIssuesTable(db.database()); + private MigrationStep underTest = new DropIssuesTable(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"); + db.assertTableDoesNotExist("issues"); } @Test public void migration_is_re_entrant() throws SQLException { + db.assertTableExists("issues"); + underTest.execute(); // re-entrant underTest.execute(); - - db.assertIndexDoesNotExist("issues", "issues_rule_id"); + db.assertTableDoesNotExist("issues"); } } 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 index cc796467624..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/PopulateIssuesRuleUuidColumnTest.java +++ /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/DropRuleIdColumnOfIssuesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/RenameIssuesCopyToIssuesTest.java similarity index 64% rename from server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/DropRuleIdColumnOfIssuesTableTest.java rename to server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/rules/issues/RenameIssuesCopyToIssuesTest.java index 66d175380c1..ea3c076579b 100644 --- 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/RenameIssuesCopyToIssuesTest.java @@ -23,28 +23,23 @@ 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 { +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(DropRuleIdColumnOfIssuesTableTest.class, "schema.sql"); + public CoreDbTester db = CoreDbTester.createForSchema(RenameIssuesCopyToIssuesTest.class, "schema.sql"); - private DdlChange underTest = new DropRuleIdColumnOfIssuesTable(db.database()); + private MigrationStep underTest = new RenameIssuesCopyToIssues(db.database()); @Test public void execute() throws SQLException { - underTest.execute(); + db.assertTableExists("issues_copy"); + db.assertTableDoesNotExist("issues"); - db.assertColumnDoesNotExist("issues", "id"); - } - - @Test - public void migration_is_not_re_entrant() throws SQLException { underTest.execute(); + db.assertTableDoesNotExist("issues_copy"); + db.assertTableExists("issues"); - assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class); } } 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/AddIndexOnIssueKeyOfIssueChangesTableTest/schema.sql similarity index 54% rename from server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/issuechanges/DropPrimaryKeyOnIdColumnOfIssueChangesTableTest/schema.sql rename to server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/issuechanges/AddIndexOnIssueKeyOfIssueChangesTableTest/schema.sql index e19e2691124..93de1f11d37 100644 --- 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/AddIndexOnIssueKeyOfIssueChangesTableTest/schema.sql @@ -1,5 +1,4 @@ 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, @@ -10,6 +9,3 @@ CREATE TABLE "ISSUE_CHANGES"( "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/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 index 00000000000..93de1f11d37 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/issuechanges/AddIndexOnKeeOfIssueChangesTableTest/schema.sql @@ -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/AddPrimaryKeyOnUuidColumnOfIssueChangesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/issuechanges/AddPrimaryKeyOnUuidColumnOfIssueChangesTableTest/schema.sql index 5b74206accb..1d8a73f53d7 100644 --- a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/issuechanges/AddPrimaryKeyOnUuidColumnOfIssueChangesTableTest/schema.sql +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/issuechanges/AddPrimaryKeyOnUuidColumnOfIssueChangesTableTest/schema.sql @@ -1,5 +1,4 @@ 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, 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/CopyIssueChangesTableTest/schema.sql similarity index 85% rename from server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/issuechanges/AddUuidColumnToIssueChangesTableTest/schema.sql rename to server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/issuechanges/CopyIssueChangesTableTest/schema.sql index 6dea8cb9711..8b3247ab396 100644 --- 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/CopyIssueChangesTableTest/schema.sql @@ -9,6 +9,5 @@ CREATE TABLE "ISSUE_CHANGES"( "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/DropIdColumnOfIssueChangesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/issuechanges/DropIssueChangesTableTest/schema.sql similarity index 63% rename from server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/issuechanges/DropIdColumnOfIssueChangesTableTest/schema.sql rename to server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/issuechanges/DropIssueChangesTableTest/schema.sql index 7b26191fc16..a188f8096fa 100644 --- 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/DropIssueChangesTableTest/schema.sql @@ -1,6 +1,5 @@ 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), @@ -10,6 +9,18 @@ CREATE TABLE "ISSUE_CHANGES"( "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"); + +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/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 index f48647de321..00000000000 --- a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/issuechanges/MakeIssueChangesUuidColumnNotNullableTest/schema.sql +++ /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 index f48647de321..00000000000 --- a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/issuechanges/PopulateIssueChangesUuidTest/schema.sql +++ /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 index 00000000000..051df21ef50 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/issuechanges/RenameIssueChangesCopyToIssueChangesTest/schema.sql @@ -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/metrics/livemeasures/AddIndexOnMetricUuidOfLiveMeasuresTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/AddIndexOnMetricUuidOfLiveMeasuresTableTest/schema.sql index b624715d6c6..4f1c3afd5d6 100644 --- a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/AddIndexOnMetricUuidOfLiveMeasuresTableTest/schema.sql +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/AddIndexOnMetricUuidOfLiveMeasuresTableTest/schema.sql @@ -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/MakeLiveMeasuresMetricUuidNotNullableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/AddIndexOnProjectUuidOfLiveMeasuresTableTest/schema.sql similarity index 52% rename from server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/MakeLiveMeasuresMetricUuidNotNullableTest/schema.sql rename to server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/AddIndexOnProjectUuidOfLiveMeasuresTableTest/schema.sql index dd1e89afe4c..4f1c3afd5d6 100644 --- 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/AddIndexOnProjectUuidOfLiveMeasuresTableTest/schema.sql @@ -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(40), + "METRIC_UUID" VARCHAR(40) NOT NULL, "VALUE" DOUBLE, "TEXT_VALUE" VARCHAR(4000), "VARIATION" DOUBLE, @@ -12,6 +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"); -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/AddMetricUuidColumnToLiveMeasuresTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/CopyLiveMeasuresTableTest/schema.sql similarity index 100% rename from server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/AddMetricUuidColumnToLiveMeasuresTest/schema.sql rename to server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/CopyLiveMeasuresTableTest/schema.sql 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/DropLiveMeasuresTableTest/schema.sql similarity index 61% rename from server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/DropIndexOnMetricIdOfLiveMeasuresTableTest/schema.sql rename to server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/DropLiveMeasuresTableTest/schema.sql index 79dd9a63064..979f28bb677 100644 --- 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/DropLiveMeasuresTableTest/schema.sql @@ -3,7 +3,6 @@ CREATE TABLE "LIVE_MEASURES"( "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, @@ -15,3 +14,17 @@ CREATE TABLE "LIVE_MEASURES"( 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 index 5b750f3ece5..00000000000 --- a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/DropMetricIdColumnOfLiveMeasuresTableTest/schema.sql +++ /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/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 index 85b848f4614..00000000000 --- a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/PopulateLiveMeasuresMetricUuidTest/schema.sql +++ /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 index 00000000000..6688560c8be --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/metrics/livemeasures/RenameLiveMeasuresCopyToLiveMeasuresTest/schema.sql @@ -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 index d02b9c74ec2..00000000000 --- a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/rules/issues/AddIndexToIssuesTableTest/schema.sql +++ /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/issues/DropIdColumnOfIssuesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/rules/issues/AddIndexesToIssuesTableTest/schema.sql similarity index 60% rename from server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/issues/DropIdColumnOfIssuesTableTest/schema.sql rename to server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/rules/issues/AddIndexesToIssuesTableTest/schema.sql index 92fadc6580c..6b6f0a98684 100644 --- 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/rules/issues/AddIndexesToIssuesTableTest/schema.sql @@ -1,5 +1,4 @@ CREATE TABLE "ISSUES"( - "ID" BIGINT NOT NULL, "KEE" VARCHAR(50) NOT NULL, "RULE_ID" INTEGER, "SEVERITY" VARCHAR(10), @@ -26,14 +25,7 @@ CREATE TABLE "ISSUES"( "PROJECT_UUID" VARCHAR(50), "LOCATIONS" BLOB, "ISSUE_TYPE" TINYINT, - "FROM_HOTSPOT" BOOLEAN + "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/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 index 89488e5506f..00000000000 --- a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/rules/issues/AddRuleUuidColumnToIssuesTableTest/schema.sql +++ /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/issues/DropPrimaryKeyOnIdColumnOfIssuesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/rules/issues/CopyIssuesTableTest/schema.sql similarity index 100% rename from server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/issues/DropPrimaryKeyOnIdColumnOfIssuesTableTest/schema.sql rename to server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/rules/issues/CopyIssuesTableTest/schema.sql 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/DropIssuesTableTest/schema.sql similarity index 55% rename from server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/rules/issues/DropIndexOnRuleIdColumnOfIssuesTableTest/schema.sql rename to server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/rules/issues/DropIssuesTableTest/schema.sql index d6c8f6b855e..a791fda4a80 100644 --- 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/DropIssuesTableTest/schema.sql @@ -1,35 +1,36 @@ -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, +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, - "UUID" VARCHAR(40) NOT NULL, - "TEMPLATE_UUID" VARCHAR(40) + "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 "RULES" ADD CONSTRAINT "PK_RULES" PRIMARY KEY("ID"); -CREATE UNIQUE INDEX "RULES_REPO_KEY" ON "RULES"("PLUGIN_RULE_KEY", "PLUGIN_NAME"); CREATE TABLE "ISSUES"( + "ID" BIGINT NOT NULL AUTO_INCREMENT (1,1), "KEE" VARCHAR(50) NOT NULL, "RULE_ID" INTEGER, "SEVERITY" VARCHAR(10), @@ -56,10 +57,9 @@ 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"); +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"); 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 index a2da6523742..00000000000 --- a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/rules/issues/DropRuleIdColumnOfIssuesTableTest/schema.sql +++ /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 index d6c8f6b855e..00000000000 --- a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/rules/issues/PopulateIssuesRuleUuidColumnTest/schema.sql +++ /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 index 00000000000..0c3fc02ca51 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v84/rules/issues/RenameIssuesCopyToIssuesTest/schema.sql @@ -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) +); -- 2.39.5