From 8b0dda072d1afbddc8cbc594f8ca868311600a75 Mon Sep 17 00:00:00 2001 From: Jacek Date: Wed, 15 Apr 2020 11:36:11 +0200 Subject: [PATCH] SONAR-13221 change PK to uuid of DUPLICATIONS_INDEX table --- .../sonar/db/duplication/DuplicationDao.java | 10 ++- .../db/duplication/DuplicationUnitDto.java | 10 +-- .../db/duplication/DuplicationMapper.xml | 8 +- server/sonar-db-dao/src/schema/schema-sq.ddl | 6 +- .../db/duplication/DuplicationDaoTest.java | 4 +- .../db/migration/version/v83/DbVersion83.java | 13 +++ ...yOnUuidColumnOfDuplicationsIndexTable.java | 38 +++++++++ .../AddUuidToDuplicationsIndexTable.java | 50 +++++++++++ .../DropIdColumnOfDuplicationsIndexTable.java | 37 ++++++++ ...KeyOnIdColumnOfDuplicationsIndexTable.java | 41 +++++++++ ...uplicationsIndexUuidColumnNotNullable.java | 50 +++++++++++ .../PopulateDuplicationsIndexUuid.java | 50 +++++++++++ ...uidColumnOfDuplicationsIndexTableTest.java | 51 +++++++++++ .../AddUuidToDuplicationsIndexTableTest.java | 70 +++++++++++++++ ...pIdColumnOfDuplicationsIndexTableTest.java | 51 +++++++++++ ...nIdColumnOfDuplicationsIndexTableTest.java | 56 ++++++++++++ ...cationsIndexUuidColumnNotNullableTest.java | 43 ++++++++++ .../PopulateDuplicationsIndexUuidTest.java | 85 +++++++++++++++++++ .../schema.sql | 12 +++ .../schema.sql | 13 +++ .../schema.sql | 13 +++ .../schema.sql | 13 +++ .../schema.sql | 13 +++ .../schema.sql | 13 +++ 24 files changed, 736 insertions(+), 14 deletions(-) create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/duplicationsindex/AddPrimaryKeyOnUuidColumnOfDuplicationsIndexTable.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/duplicationsindex/AddUuidToDuplicationsIndexTable.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/duplicationsindex/DropIdColumnOfDuplicationsIndexTable.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/duplicationsindex/DropPrimaryKeyOnIdColumnOfDuplicationsIndexTable.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/duplicationsindex/MakeDuplicationsIndexUuidColumnNotNullable.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/duplicationsindex/PopulateDuplicationsIndexUuid.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/duplicationsindex/AddPrimaryKeyOnUuidColumnOfDuplicationsIndexTableTest.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/duplicationsindex/AddUuidToDuplicationsIndexTableTest.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/duplicationsindex/DropIdColumnOfDuplicationsIndexTableTest.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/duplicationsindex/DropPrimaryKeyOnIdColumnOfDuplicationsIndexTableTest.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/duplicationsindex/MakeDuplicationsIndexUuidColumnNotNullableTest.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/duplicationsindex/PopulateDuplicationsIndexUuidTest.java create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/duplicationsindex/AddPrimaryKeyOnUuidColumnOfDuplicationsIndexTableTest/schema.sql create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/duplicationsindex/AddUuidToDuplicationsIndexTableTest/schema.sql create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/duplicationsindex/DropIdColumnOfDuplicationsIndexTableTest/schema.sql create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/duplicationsindex/DropPrimaryKeyOnIdColumnOfDuplicationsIndexTableTest/schema.sql create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/duplicationsindex/MakeDuplicationsIndexUuidColumnNotNullableTest/schema.sql create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/duplicationsindex/PopulateDuplicationsIndexUuidTest/schema.sql diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/duplication/DuplicationDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/duplication/DuplicationDao.java index 79e3ea7900e..ad8ff144119 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/duplication/DuplicationDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/duplication/DuplicationDao.java @@ -22,6 +22,7 @@ package org.sonar.db.duplication; import java.util.Collection; import java.util.List; import javax.annotation.Nullable; +import org.sonar.core.util.UuidFactory; import org.sonar.db.Dao; import org.sonar.db.DbSession; @@ -29,6 +30,12 @@ import static org.sonar.db.DatabaseUtils.executeLargeInputs; public class DuplicationDao implements Dao { + private final UuidFactory uuidFactory; + + public DuplicationDao(UuidFactory uuidFactory) { + this.uuidFactory = uuidFactory; + } + /** * @param analysisUuid snapshot id of the project from the previous analysis (islast=true) */ @@ -43,9 +50,10 @@ public class DuplicationDao implements Dao { * Note that generated ids are not returned. */ public void insert(DbSession session, DuplicationUnitDto dto) { + dto.setUuid(uuidFactory.create()); session.getMapper(DuplicationMapper.class).batchInsert(dto); } - + public List selectComponent(DbSession session, String componentUuid, String analysisUuid) { return session.getMapper(DuplicationMapper.class).selectComponent(componentUuid, analysisUuid); } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/duplication/DuplicationUnitDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/duplication/DuplicationUnitDto.java index 7c3e3ab4765..1e79f886d76 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/duplication/DuplicationUnitDto.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/duplication/DuplicationUnitDto.java @@ -21,7 +21,7 @@ package org.sonar.db.duplication; public final class DuplicationUnitDto { - private long id; + private String uuid; private String analysisUuid; private String componentUuid; @@ -33,12 +33,12 @@ public final class DuplicationUnitDto { // Return by join private String componentKey; - public long getId() { - return id; + public String getUuid() { + return uuid; } - public DuplicationUnitDto setId(long id) { - this.id = id; + public DuplicationUnitDto setUuid(String uuid) { + this.uuid = uuid; return this; } diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/duplication/DuplicationMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/duplication/DuplicationMapper.xml index 64f3fc648b5..b402cc0a498 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/duplication/DuplicationMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/duplication/DuplicationMapper.xml @@ -5,7 +5,7 @@ SELECT DISTINCT - dup.id as id, + dup.uuid as uuid, dup.analysis_uuid as analysisUuid, dup.component_uuid as componentUuid, dup.hash as hash, @@ -43,11 +43,11 @@ INSERT INTO duplications_index ( - analysis_uuid, component_uuid, hash, + uuid, analysis_uuid, component_uuid, hash, index_in_file, start_line, end_line ) VALUES ( - #{analysisUuid,jdbcType=VARCHAR}, #{componentUuid,jdbcType=VARCHAR}, #{hash,jdbcType=VARCHAR}, + #{uuid,jdbcType=VARCHAR}, #{analysisUuid,jdbcType=VARCHAR}, #{componentUuid,jdbcType=VARCHAR}, #{hash,jdbcType=VARCHAR}, #{indexInFile,jdbcType=INTEGER}, #{startLine,jdbcType=INTEGER}, #{endLine,jdbcType=INTEGER} ) diff --git a/server/sonar-db-dao/src/schema/schema-sq.ddl b/server/sonar-db-dao/src/schema/schema-sq.ddl index 7cab5a23ebd..5bfa4ce355e 100644 --- a/server/sonar-db-dao/src/schema/schema-sq.ddl +++ b/server/sonar-db-dao/src/schema/schema-sq.ddl @@ -236,15 +236,15 @@ CREATE UNIQUE INDEX "UNIQ_DEPRECATED_RULE_KEYS" ON "DEPRECATED_RULE_KEYS"("OLD_R CREATE INDEX "RULE_ID_DEPRECATED_RULE_KEYS" ON "DEPRECATED_RULE_KEYS"("RULE_ID"); CREATE TABLE "DUPLICATIONS_INDEX"( - "ID" BIGINT NOT NULL AUTO_INCREMENT (1,1), "ANALYSIS_UUID" VARCHAR(50) NOT NULL, "COMPONENT_UUID" VARCHAR(50) NOT NULL, "HASH" VARCHAR(50) NOT NULL, "INDEX_IN_FILE" INTEGER NOT NULL, "START_LINE" INTEGER NOT NULL, - "END_LINE" INTEGER NOT NULL + "END_LINE" INTEGER NOT NULL, + "UUID" VARCHAR(40) NOT NULL ); -ALTER TABLE "DUPLICATIONS_INDEX" ADD CONSTRAINT "PK_DUPLICATIONS_INDEX" PRIMARY KEY("ID"); +ALTER TABLE "DUPLICATIONS_INDEX" ADD CONSTRAINT "PK_DUPLICATIONS_INDEX" PRIMARY KEY("UUID"); CREATE INDEX "DUPLICATIONS_INDEX_HASH" ON "DUPLICATIONS_INDEX"("HASH"); CREATE INDEX "DUPLICATION_ANALYSIS_COMPONENT" ON "DUPLICATIONS_INDEX"("ANALYSIS_UUID", "COMPONENT_UUID"); diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/duplication/DuplicationDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/duplication/DuplicationDaoTest.java index e13dcf6ee0a..e938671731d 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/duplication/DuplicationDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/duplication/DuplicationDaoTest.java @@ -134,6 +134,7 @@ public class DuplicationDaoTest { assertThat(blocks).hasSize(1); DuplicationUnitDto block = blocks.get(0); + Assertions.assertThat(block.getUuid()).isNotNull(); Assertions.assertThat(block.getComponentKey()).isNull(); Assertions.assertThat(block.getComponentUuid()).isEqualTo(project3.uuid()); Assertions.assertThat(block.getHash()).isEqualTo("bb"); @@ -152,11 +153,12 @@ public class DuplicationDaoTest { insert(project, analysis, "bb", 0, 1, 2); List> rows = db.select("select " + - "analysis_uuid as \"ANALYSIS\", component_uuid as \"COMPONENT\", hash as \"HASH\", " + + "uuid as \"UUID\", analysis_uuid as \"ANALYSIS\", component_uuid as \"COMPONENT\", hash as \"HASH\", " + "index_in_file as \"INDEX\", start_line as \"START\", end_line as \"END\"" + " from duplications_index"); Assertions.assertThat(rows).hasSize(1); Map row = rows.get(0); + Assertions.assertThat(row.get("UUID")).isNotNull(); Assertions.assertThat(row.get("ANALYSIS")).isEqualTo(analysis.getUuid()); Assertions.assertThat(row.get("COMPONENT")).isEqualTo(project.uuid()); Assertions.assertThat(row.get("HASH")).isEqualTo("bb"); diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/DbVersion83.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/DbVersion83.java index f71ba9528b4..0b35213e766 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/DbVersion83.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/DbVersion83.java @@ -28,6 +28,12 @@ import org.sonar.server.platform.db.migration.version.v83.cequeue.AddPrimaryKeyO import org.sonar.server.platform.db.migration.version.v83.cequeue.DropIdColumnOfCeQueueTable; import org.sonar.server.platform.db.migration.version.v83.cequeue.DropPrimaryKeyOnIdColumnOfCeQueueTable; import org.sonar.server.platform.db.migration.version.v83.cequeue.DropUniqueIndexOnUuidColumnOfCeQueueTable; +import org.sonar.server.platform.db.migration.version.v83.duplicationsindex.AddPrimaryKeyOnUuidColumnOfDuplicationsIndexTable; +import org.sonar.server.platform.db.migration.version.v83.duplicationsindex.AddUuidToDuplicationsIndexTable; +import org.sonar.server.platform.db.migration.version.v83.duplicationsindex.DropIdColumnOfDuplicationsIndexTable; +import org.sonar.server.platform.db.migration.version.v83.duplicationsindex.DropPrimaryKeyOnIdColumnOfDuplicationsIndexTable; +import org.sonar.server.platform.db.migration.version.v83.duplicationsindex.MakeDuplicationsIndexUuidColumnNotNullable; +import org.sonar.server.platform.db.migration.version.v83.duplicationsindex.PopulateDuplicationsIndexUuid; import org.sonar.server.platform.db.migration.version.v83.events.AddPrimaryKeyOnUuidColumnOfEventsTable; import org.sonar.server.platform.db.migration.version.v83.events.DropIdColumnOfEventsTable; import org.sonar.server.platform.db.migration.version.v83.events.DropPrimaryKeyOnIdColumnOfEventsTable; @@ -95,6 +101,13 @@ public class DbVersion83 implements DbVersion { .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) + // 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) ; } } diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/duplicationsindex/AddPrimaryKeyOnUuidColumnOfDuplicationsIndexTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/duplicationsindex/AddPrimaryKeyOnUuidColumnOfDuplicationsIndexTable.java new file mode 100644 index 00000000000..1efc12e91ea --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/duplicationsindex/AddPrimaryKeyOnUuidColumnOfDuplicationsIndexTable.java @@ -0,0 +1,38 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v83.duplicationsindex; + +import java.sql.SQLException; +import org.sonar.db.Database; +import org.sonar.server.platform.db.migration.step.DdlChange; +import org.sonar.server.platform.db.migration.version.v83.util.AddPrimaryKeyBuilder; + +public class AddPrimaryKeyOnUuidColumnOfDuplicationsIndexTable extends DdlChange { + + public AddPrimaryKeyOnUuidColumnOfDuplicationsIndexTable(Database db) { + super(db); + } + + @Override + public void execute(Context context) throws SQLException { + context.execute(new AddPrimaryKeyBuilder("duplications_index", "uuid").build()); + } + +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/duplicationsindex/AddUuidToDuplicationsIndexTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/duplicationsindex/AddUuidToDuplicationsIndexTable.java new file mode 100644 index 00000000000..fa5606a9485 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/duplicationsindex/AddUuidToDuplicationsIndexTable.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.v83.duplicationsindex; + +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 AddUuidToDuplicationsIndexTable extends DdlChange { + private static final String TABLE = "duplications_index"; + + private static final VarcharColumnDef uuidColumnDefinition = newVarcharColumnDefBuilder() + .setColumnName("uuid") + .setIsNullable(true) + .setDefaultValue(null) + .setLimit(VarcharColumnDef.UUID_SIZE) + .build(); + + public AddUuidToDuplicationsIndexTable(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/v83/duplicationsindex/DropIdColumnOfDuplicationsIndexTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/duplicationsindex/DropIdColumnOfDuplicationsIndexTable.java new file mode 100644 index 00000000000..bd37e365086 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/duplicationsindex/DropIdColumnOfDuplicationsIndexTable.java @@ -0,0 +1,37 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v83.duplicationsindex; + +import java.sql.SQLException; +import org.sonar.db.Database; +import org.sonar.server.platform.db.migration.sql.DropColumnsBuilder; +import org.sonar.server.platform.db.migration.step.DdlChange; + +public class DropIdColumnOfDuplicationsIndexTable extends DdlChange { + + public DropIdColumnOfDuplicationsIndexTable(Database db) { + super(db); + } + + @Override + public void execute(Context context) throws SQLException { + context.execute(new DropColumnsBuilder(getDialect(), "duplications_index", "id").build()); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/duplicationsindex/DropPrimaryKeyOnIdColumnOfDuplicationsIndexTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/duplicationsindex/DropPrimaryKeyOnIdColumnOfDuplicationsIndexTable.java new file mode 100644 index 00000000000..1f6bdfe2911 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/duplicationsindex/DropPrimaryKeyOnIdColumnOfDuplicationsIndexTable.java @@ -0,0 +1,41 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v83.duplicationsindex; + +import java.sql.SQLException; +import org.sonar.db.Database; +import org.sonar.server.platform.db.migration.step.DdlChange; +import org.sonar.server.platform.db.migration.version.v83.util.DropPrimaryKeySqlGenerator; + +public class DropPrimaryKeyOnIdColumnOfDuplicationsIndexTable extends DdlChange { + + private final DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator; + + public DropPrimaryKeyOnIdColumnOfDuplicationsIndexTable(Database db, DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator) { + super(db); + this.dropPrimaryKeySqlGenerator = dropPrimaryKeySqlGenerator; + } + + @Override + public void execute(Context context) throws SQLException { + context.execute(dropPrimaryKeySqlGenerator.generate("duplications_index", "duplications_index", "id")); + } + +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/duplicationsindex/MakeDuplicationsIndexUuidColumnNotNullable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/duplicationsindex/MakeDuplicationsIndexUuidColumnNotNullable.java new file mode 100644 index 00000000000..279fe932995 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/duplicationsindex/MakeDuplicationsIndexUuidColumnNotNullable.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.v83.duplicationsindex; + +import java.sql.SQLException; +import org.sonar.db.Database; +import org.sonar.server.platform.db.migration.def.VarcharColumnDef; +import org.sonar.server.platform.db.migration.sql.AlterColumnsBuilder; +import org.sonar.server.platform.db.migration.step.DdlChange; + +import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder; + +public class MakeDuplicationsIndexUuidColumnNotNullable extends DdlChange { + private static final String TABLE = "duplications_index"; + + private static final VarcharColumnDef uuidColumnDefinition = newVarcharColumnDefBuilder() + .setColumnName("uuid") + .setIsNullable(false) + .setDefaultValue(null) + .setLimit(VarcharColumnDef.UUID_SIZE) + .build(); + + public MakeDuplicationsIndexUuidColumnNotNullable(Database db) { + super(db); + } + + @Override + public void execute(Context context) throws SQLException { + context.execute(new AlterColumnsBuilder(getDialect(), TABLE) + .updateColumn(uuidColumnDefinition) + .build()); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/duplicationsindex/PopulateDuplicationsIndexUuid.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/duplicationsindex/PopulateDuplicationsIndexUuid.java new file mode 100644 index 00000000000..9d6302049af --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/duplicationsindex/PopulateDuplicationsIndexUuid.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.v83.duplicationsindex; + +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 PopulateDuplicationsIndexUuid extends DataChange { + + private final UuidFactory uuidFactory; + + public PopulateDuplicationsIndexUuid(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 duplications_index where uuid is null order by id asc"); + massUpdate.update("update duplications_index 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/test/java/org/sonar/server/platform/db/migration/version/v83/duplicationsindex/AddPrimaryKeyOnUuidColumnOfDuplicationsIndexTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/duplicationsindex/AddPrimaryKeyOnUuidColumnOfDuplicationsIndexTableTest.java new file mode 100644 index 00000000000..ee7c4bfac5a --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/duplicationsindex/AddPrimaryKeyOnUuidColumnOfDuplicationsIndexTableTest.java @@ -0,0 +1,51 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v83.duplicationsindex; + +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 AddPrimaryKeyOnUuidColumnOfDuplicationsIndexTableTest { + + @Rule + public CoreDbTester db = CoreDbTester.createForSchema(AddPrimaryKeyOnUuidColumnOfDuplicationsIndexTableTest.class, "schema.sql"); + + private MigrationStep underTest = new AddPrimaryKeyOnUuidColumnOfDuplicationsIndexTable(db.database()); + + @Test + public void execute() throws SQLException { + underTest.execute(); + + db.assertPrimaryKey("duplications_index", "pk_duplications_index", "uuid"); + } + + @Test + public void migration_is_not_re_entrant() throws SQLException { + underTest.execute(); + + assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class); + } + +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/duplicationsindex/AddUuidToDuplicationsIndexTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/duplicationsindex/AddUuidToDuplicationsIndexTableTest.java new file mode 100644 index 00000000000..2cb23b81956 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/duplicationsindex/AddUuidToDuplicationsIndexTableTest.java @@ -0,0 +1,70 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v83.duplicationsindex; + +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 AddUuidToDuplicationsIndexTableTest { + + @Rule + public CoreDbTester db = CoreDbTester.createForSchema(AddUuidToDuplicationsIndexTableTest.class, "schema.sql"); + + private DdlChange underTest = new AddUuidToDuplicationsIndexTable(db.database()); + + private UuidFactoryFast uuidFactory = UuidFactoryFast.getInstance(); + + @Before + public void setup() { + insertDuplicationsIndex(1L); + insertDuplicationsIndex(2L); + insertDuplicationsIndex(3L); + } + + @Test + public void add_uuid_column_to_duplications_index() throws SQLException { + underTest.execute(); + + db.assertColumnDefinition("duplications_index", "uuid", Types.VARCHAR, 40, true); + + assertThat(db.countRowsOfTable("duplications_index")) + .isEqualTo(3); + } + + private void insertDuplicationsIndex(Long id) { + db.executeInsert("duplications_index", + "id", id, + "hash", uuidFactory.create(), + "index_in_file", id + 1, + "start_line", id + 2, + "end_line", id + 3, + "component_uuid", uuidFactory.create(), + "analysis_uuid", uuidFactory.create()); + } + +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/duplicationsindex/DropIdColumnOfDuplicationsIndexTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/duplicationsindex/DropIdColumnOfDuplicationsIndexTableTest.java new file mode 100644 index 00000000000..dbff05aa390 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/duplicationsindex/DropIdColumnOfDuplicationsIndexTableTest.java @@ -0,0 +1,51 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v83.duplicationsindex; + +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 DropIdColumnOfDuplicationsIndexTableTest { + + @Rule + public CoreDbTester db = CoreDbTester.createForSchema(DropIdColumnOfDuplicationsIndexTableTest.class, "schema.sql"); + + private MigrationStep underTest = new DropIdColumnOfDuplicationsIndexTable(db.database()); + + @Test + public void execute() throws SQLException { + underTest.execute(); + + db.assertColumnDoesNotExist("duplications_index", "id"); + } + + @Test + public void migration_is_not_re_entrant() throws SQLException { + underTest.execute(); + + assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class); + } + +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/duplicationsindex/DropPrimaryKeyOnIdColumnOfDuplicationsIndexTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/duplicationsindex/DropPrimaryKeyOnIdColumnOfDuplicationsIndexTableTest.java new file mode 100644 index 00000000000..00869d195cf --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/duplicationsindex/DropPrimaryKeyOnIdColumnOfDuplicationsIndexTableTest.java @@ -0,0 +1,56 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v83.duplicationsindex; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.CoreDbTester; +import org.sonar.server.platform.db.migration.step.MigrationStep; +import org.sonar.server.platform.db.migration.version.v83.util.DropPrimaryKeySqlGenerator; +import org.sonar.server.platform.db.migration.version.v83.util.GetConstraintHelper; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +public class DropPrimaryKeyOnIdColumnOfDuplicationsIndexTableTest { + + private static final String TABLE_NAME = "duplications_index"; + @Rule + public CoreDbTester db = CoreDbTester.createForSchema(DropPrimaryKeyOnIdColumnOfDuplicationsIndexTableTest.class, "schema.sql"); + + private DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new GetConstraintHelper(db.database())); + + private MigrationStep underTest = new DropPrimaryKeyOnIdColumnOfDuplicationsIndexTable(db.database(), dropPrimaryKeySqlGenerator); + + @Test + public void execute() throws SQLException { + underTest.execute(); + + db.assertNoPrimaryKey(TABLE_NAME); + } + + @Test + public void migration_is_not_re_entrant() throws SQLException { + underTest.execute(); + + assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class); + } + +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/duplicationsindex/MakeDuplicationsIndexUuidColumnNotNullableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/duplicationsindex/MakeDuplicationsIndexUuidColumnNotNullableTest.java new file mode 100644 index 00000000000..522166c71a6 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/duplicationsindex/MakeDuplicationsIndexUuidColumnNotNullableTest.java @@ -0,0 +1,43 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v83.duplicationsindex; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.CoreDbTester; +import org.sonar.server.platform.db.migration.step.MigrationStep; + +import static java.sql.Types.VARCHAR; + +public class MakeDuplicationsIndexUuidColumnNotNullableTest { + + @Rule + public CoreDbTester db = CoreDbTester.createForSchema(MakeDuplicationsIndexUuidColumnNotNullableTest.class, "schema.sql"); + + private MigrationStep underTest = new MakeDuplicationsIndexUuidColumnNotNullable(db.database()); + + @Test + public void created_at_and_uuid_columns_are_not_null() throws SQLException { + underTest.execute(); + + db.assertColumnDefinition("duplications_index", "uuid", VARCHAR, null, false); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/duplicationsindex/PopulateDuplicationsIndexUuidTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/duplicationsindex/PopulateDuplicationsIndexUuidTest.java new file mode 100644 index 00000000000..df4baa1c460 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/duplicationsindex/PopulateDuplicationsIndexUuidTest.java @@ -0,0 +1,85 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v83.duplicationsindex; + +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 PopulateDuplicationsIndexUuidTest { + + @Rule + public CoreDbTester db = CoreDbTester.createForSchema(PopulateDuplicationsIndexUuidTest.class, "schema.sql"); + + private UuidFactory uuidFactory = UuidFactoryFast.getInstance(); + private DataChange underTest = new PopulateDuplicationsIndexUuid(db.database(), uuidFactory); + + @Test + public void populate_uuids() throws SQLException { + insertDuplicationsIndex(1L); + insertDuplicationsIndex(2L); + insertDuplicationsIndex(3L); + + underTest.execute(); + + verifyUuidsAreNotNull(); + } + + @Test + public void migration_is_reentrant() throws SQLException { + insertDuplicationsIndex(1L); + insertDuplicationsIndex(2L); + insertDuplicationsIndex(3L); + + underTest.execute(); + // re-entrant + underTest.execute(); + + verifyUuidsAreNotNull(); + } + + private void verifyUuidsAreNotNull() { + assertThat(db.select("select uuid from duplications_index") + .stream() + .map(row -> row.get("UUID")) + .filter(Objects::isNull) + .collect(Collectors.toList())).isEmpty(); + } + + private void insertDuplicationsIndex(Long id) { + db.executeInsert("duplications_index", + "id", id, + "hash", uuidFactory.create(), + "index_in_file", id + 1, + "start_line", id + 2, + "end_line", id + 3, + "component_uuid", uuidFactory.create(), + "analysis_uuid", uuidFactory.create()); + } + +} diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/duplicationsindex/AddPrimaryKeyOnUuidColumnOfDuplicationsIndexTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/duplicationsindex/AddPrimaryKeyOnUuidColumnOfDuplicationsIndexTableTest/schema.sql new file mode 100644 index 00000000000..de4522b3c84 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/duplicationsindex/AddPrimaryKeyOnUuidColumnOfDuplicationsIndexTableTest/schema.sql @@ -0,0 +1,12 @@ +CREATE TABLE "DUPLICATIONS_INDEX"( + "ID" BIGINT NOT NULL AUTO_INCREMENT (1,1), + "ANALYSIS_UUID" VARCHAR(50) NOT NULL, + "COMPONENT_UUID" VARCHAR(50) NOT NULL, + "HASH" VARCHAR(50) NOT NULL, + "INDEX_IN_FILE" INTEGER NOT NULL, + "START_LINE" INTEGER NOT NULL, + "END_LINE" INTEGER NOT NULL, + "UUID" VARCHAR(40) NOT NULL +); +CREATE INDEX "DUPLICATIONS_INDEX_HASH" ON "DUPLICATIONS_INDEX"("HASH"); +CREATE INDEX "DUPLICATION_ANALYSIS_COMPONENT" ON "DUPLICATIONS_INDEX"("ANALYSIS_UUID", "COMPONENT_UUID"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/duplicationsindex/AddUuidToDuplicationsIndexTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/duplicationsindex/AddUuidToDuplicationsIndexTableTest/schema.sql new file mode 100644 index 00000000000..f0001521878 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/duplicationsindex/AddUuidToDuplicationsIndexTableTest/schema.sql @@ -0,0 +1,13 @@ +CREATE TABLE "DUPLICATIONS_INDEX"( + "ID" BIGINT NOT NULL AUTO_INCREMENT (1,1), + "ANALYSIS_UUID" VARCHAR(50) NOT NULL, + "COMPONENT_UUID" VARCHAR(50) NOT NULL, + "HASH" VARCHAR(50) NOT NULL, + "INDEX_IN_FILE" INTEGER NOT NULL, + "START_LINE" INTEGER NOT NULL, + "END_LINE" INTEGER NOT NULL +); +ALTER TABLE "DUPLICATIONS_INDEX" ADD CONSTRAINT "PK_DUPLICATIONS_INDEX" PRIMARY KEY("ID"); +CREATE INDEX "DUPLICATIONS_INDEX_HASH" ON "DUPLICATIONS_INDEX"("HASH"); +CREATE INDEX "DUPLICATION_ANALYSIS_COMPONENT" ON "DUPLICATIONS_INDEX"("ANALYSIS_UUID", "COMPONENT_UUID"); + diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/duplicationsindex/DropIdColumnOfDuplicationsIndexTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/duplicationsindex/DropIdColumnOfDuplicationsIndexTableTest/schema.sql new file mode 100644 index 00000000000..1399658a241 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/duplicationsindex/DropIdColumnOfDuplicationsIndexTableTest/schema.sql @@ -0,0 +1,13 @@ +CREATE TABLE "DUPLICATIONS_INDEX"( + "ID" BIGINT NOT NULL, + "ANALYSIS_UUID" VARCHAR(50) NOT NULL, + "COMPONENT_UUID" VARCHAR(50) NOT NULL, + "HASH" VARCHAR(50) NOT NULL, + "INDEX_IN_FILE" INTEGER NOT NULL, + "START_LINE" INTEGER NOT NULL, + "END_LINE" INTEGER NOT NULL, + "UUID" VARCHAR(40) NOT NULL, +); +ALTER TABLE "DUPLICATIONS_INDEX" ADD CONSTRAINT "PK_DUPLICATIONS_INDEX" PRIMARY KEY("UUID"); +CREATE INDEX "DUPLICATIONS_INDEX_HASH" ON "DUPLICATIONS_INDEX"("HASH"); +CREATE INDEX "DUPLICATION_ANALYSIS_COMPONENT" ON "DUPLICATIONS_INDEX"("ANALYSIS_UUID", "COMPONENT_UUID"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/duplicationsindex/DropPrimaryKeyOnIdColumnOfDuplicationsIndexTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/duplicationsindex/DropPrimaryKeyOnIdColumnOfDuplicationsIndexTableTest/schema.sql new file mode 100644 index 00000000000..e8f7a1414be --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/duplicationsindex/DropPrimaryKeyOnIdColumnOfDuplicationsIndexTableTest/schema.sql @@ -0,0 +1,13 @@ +CREATE TABLE "DUPLICATIONS_INDEX"( + "ID" BIGINT NOT NULL AUTO_INCREMENT (1,1), + "ANALYSIS_UUID" VARCHAR(50) NOT NULL, + "COMPONENT_UUID" VARCHAR(50) NOT NULL, + "HASH" VARCHAR(50) NOT NULL, + "INDEX_IN_FILE" INTEGER NOT NULL, + "START_LINE" INTEGER NOT NULL, + "END_LINE" INTEGER NOT NULL, + "UUID" VARCHAR(40) NOT NULL, +); +ALTER TABLE "DUPLICATIONS_INDEX" ADD CONSTRAINT "PK_DUPLICATIONS_INDEX" PRIMARY KEY("ID"); +CREATE INDEX "DUPLICATIONS_INDEX_HASH" ON "DUPLICATIONS_INDEX"("HASH"); +CREATE INDEX "DUPLICATION_ANALYSIS_COMPONENT" ON "DUPLICATIONS_INDEX"("ANALYSIS_UUID", "COMPONENT_UUID"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/duplicationsindex/MakeDuplicationsIndexUuidColumnNotNullableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/duplicationsindex/MakeDuplicationsIndexUuidColumnNotNullableTest/schema.sql new file mode 100644 index 00000000000..6432378da7b --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/duplicationsindex/MakeDuplicationsIndexUuidColumnNotNullableTest/schema.sql @@ -0,0 +1,13 @@ +CREATE TABLE "DUPLICATIONS_INDEX"( + "ID" BIGINT NOT NULL AUTO_INCREMENT (1,1), + "ANALYSIS_UUID" VARCHAR(50) NOT NULL, + "COMPONENT_UUID" VARCHAR(50) NOT NULL, + "HASH" VARCHAR(50) NOT NULL, + "INDEX_IN_FILE" INTEGER NOT NULL, + "START_LINE" INTEGER NOT NULL, + "END_LINE" INTEGER NOT NULL, + "UUID" VARCHAR(40) +); +ALTER TABLE "DUPLICATIONS_INDEX" ADD CONSTRAINT "PK_DUPLICATIONS_INDEX" PRIMARY KEY("ID"); +CREATE INDEX "DUPLICATIONS_INDEX_HASH" ON "DUPLICATIONS_INDEX"("HASH"); +CREATE INDEX "DUPLICATION_ANALYSIS_COMPONENT" ON "DUPLICATIONS_INDEX"("ANALYSIS_UUID", "COMPONENT_UUID"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/duplicationsindex/PopulateDuplicationsIndexUuidTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/duplicationsindex/PopulateDuplicationsIndexUuidTest/schema.sql new file mode 100644 index 00000000000..6432378da7b --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/duplicationsindex/PopulateDuplicationsIndexUuidTest/schema.sql @@ -0,0 +1,13 @@ +CREATE TABLE "DUPLICATIONS_INDEX"( + "ID" BIGINT NOT NULL AUTO_INCREMENT (1,1), + "ANALYSIS_UUID" VARCHAR(50) NOT NULL, + "COMPONENT_UUID" VARCHAR(50) NOT NULL, + "HASH" VARCHAR(50) NOT NULL, + "INDEX_IN_FILE" INTEGER NOT NULL, + "START_LINE" INTEGER NOT NULL, + "END_LINE" INTEGER NOT NULL, + "UUID" VARCHAR(40) +); +ALTER TABLE "DUPLICATIONS_INDEX" ADD CONSTRAINT "PK_DUPLICATIONS_INDEX" PRIMARY KEY("ID"); +CREATE INDEX "DUPLICATIONS_INDEX_HASH" ON "DUPLICATIONS_INDEX"("HASH"); +CREATE INDEX "DUPLICATION_ANALYSIS_COMPONENT" ON "DUPLICATIONS_INDEX"("ANALYSIS_UUID", "COMPONENT_UUID"); -- 2.39.5