From 919e0263bcd4955bd1ede1df2bb8211fadf05ff6 Mon Sep 17 00:00:00 2001 From: Claire Villard Date: Wed, 9 Oct 2024 11:38:19 +0200 Subject: [PATCH] SONAR-23153 Drop the live_measures table and migration flags --- .../step/PersistMeasuresStepIT.java | 20 ------- .../step/PersistMeasuresStep.java | 24 --------- .../org/sonar/db/component/BranchDaoIT.java | 21 -------- .../sonar/db/portfolio/PortfolioDaoIT.java | 24 --------- .../org/sonar/db/component/BranchDao.java | 5 -- .../org/sonar/db/component/BranchMapper.java | 2 - .../org/sonar/db/portfolio/PortfolioDao.java | 5 -- .../sonar/db/portfolio/PortfolioMapper.java | 2 - .../org/sonar/db/component/BranchMapper.xml | 9 ---- .../sonar/db/portfolio/PortfolioMapper.xml | 9 ---- server/sonar-db-dao/src/schema/schema-sq.ddl | 24 +-------- .../v100/PopulateNclocForForProjectsIT.java | 10 ++++ ...opIndexOnPortfoliosMeasuresMigratedIT.java | 52 +++++++++++++++++++ ...exOnProjectBranchesMeasuresMigratedIT.java | 52 +++++++++++++++++++ .../version/v108/DropLiveMeasuresTableIT.java | 49 +++++++++++++++++ ...opMeasuresMigratedInPortfoliosTableIT.java | 52 +++++++++++++++++++ ...suresMigratedInProjectBranchesTableIT.java | 52 +++++++++++++++++++ ...grateBranchesLiveMeasuresToMeasuresIT.java | 13 +++++ ...atePortfoliosLiveMeasuresToMeasuresIT.java | 12 +++++ .../v100/PopulateNclocForForProjects.java | 9 ++++ ...AbstractMigrateLiveMeasuresToMeasures.java | 9 ++++ .../migration/version/v108/DbVersion108.java | 8 ++- ...DropIndexOnPortfoliosMeasuresMigrated.java | 33 ++++++++++++ ...ndexOnProjectBranchesMeasuresMigrated.java | 33 ++++++++++++ .../version/v108/DropLiveMeasuresTable.java | 45 ++++++++++++++++ ...asuresMigratedColumnInPortfoliosTable.java | 35 +++++++++++++ ...sMigratedColumnInProjectBranchesTable.java | 35 +++++++++++++ 27 files changed, 500 insertions(+), 144 deletions(-) create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v108/DropIndexOnPortfoliosMeasuresMigratedIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v108/DropIndexOnProjectBranchesMeasuresMigratedIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v108/DropLiveMeasuresTableIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v108/DropMeasuresMigratedInPortfoliosTableIT.java create mode 100644 server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v108/DropMeasuresMigratedInProjectBranchesTableIT.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v108/DropIndexOnPortfoliosMeasuresMigrated.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v108/DropIndexOnProjectBranchesMeasuresMigrated.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v108/DropLiveMeasuresTable.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v108/DropMeasuresMigratedColumnInPortfoliosTable.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v108/DropMeasuresMigratedColumnInProjectBranchesTable.java diff --git a/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/PersistMeasuresStepIT.java b/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/PersistMeasuresStepIT.java index dccaf1e4920..875cdb3768b 100644 --- a/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/PersistMeasuresStepIT.java +++ b/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/PersistMeasuresStepIT.java @@ -21,7 +21,6 @@ package org.sonar.ce.task.projectanalysis.step; import java.util.LinkedList; import java.util.List; -import java.util.Map; import java.util.Optional; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -48,7 +47,6 @@ import org.sonar.db.measure.MeasureDto; import org.sonar.db.metric.MetricDto; import org.sonar.server.project.Project; -import static java.lang.String.format; import static java.util.Collections.emptyList; import static java.util.Map.entry; import static org.assertj.core.api.Assertions.assertThat; @@ -131,7 +129,6 @@ class PersistMeasuresStepIT { .hasValueSatisfying(measure -> assertThat(measure.getMetricValues()).containsEntry(STRING_METRIC.getKey(), "dir-value")); assertThat(selectMeasure("file-uuid")) .hasValueSatisfying(measure -> assertThat(measure.getMetricValues()).containsEntry(STRING_METRIC.getKey(), "file-value")); - assertThat(getBranchMigratedFlag("project-uuid")).isTrue(); verifyInsertsOrUpdates(3); } @@ -153,7 +150,6 @@ class PersistMeasuresStepIT { .hasValueSatisfying(measure -> assertThat(measure.getMetricValues()).containsEntry(STRING_METRIC.getKey(), "subview-value")); assertThat(selectMeasure("project-uuid")) .hasValueSatisfying(measure -> assertThat(measure.getMetricValues()).containsEntry(STRING_METRIC.getKey(), "project-value")); - assertThat(getPortfolioMigratedFlag("view-uuid")).isTrue(); verifyInsertsOrUpdates(3); } @@ -185,7 +181,6 @@ class PersistMeasuresStepIT { // all measures are persisted, for project and all files assertThat(db.countRowsOfTable("measures")).isEqualTo(num + 1); - assertThat(getBranchMigratedFlag("project-uuid")).isTrue(); verifyInsertsOrUpdates(num - 1); verifyUnchanged(1); verify(computeDuplicationDataMeasure, times(num)).compute(any(Component.class)); @@ -292,7 +287,6 @@ class PersistMeasuresStepIT { step().execute(context); - assertThat(getBranchMigratedFlag("project-uuid")).isTrue(); verifyInsertsOrUpdates(0); verifyUnchanged(1); } @@ -390,20 +384,6 @@ class PersistMeasuresStepIT { return new PersistMeasuresStep(dbClient, metricRepository, treeRootHolder, measureRepository, computeDuplicationDataMeasure); } - private boolean getBranchMigratedFlag(String branch) { - List> result = db.select(format("select measures_migrated as \"MIGRATED\" from project_branches where uuid = '%s'", branch)); - assertThat(result).hasSize(1); - - return (boolean) result.get(0).get("MIGRATED"); - } - - private boolean getPortfolioMigratedFlag(String portfolio) { - List> result = db.select(format("select measures_migrated as \"MIGRATED\" from portfolios where uuid = '%s'", portfolio)); - assertThat(result).hasSize(1); - - return (boolean) result.get(0).get("MIGRATED"); - } - private void verifyInsertsOrUpdates(int expectedInsertsOrUpdates) { context.getStatistics().assertValue("insertsOrUpdates", expectedInsertsOrUpdates); } diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistMeasuresStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistMeasuresStep.java index 1aabeca0ff9..7f12d96a6d5 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistMeasuresStep.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistMeasuresStep.java @@ -135,36 +135,12 @@ public class PersistMeasuresStep implements ComputationStep { } } persist(inserts, updates); - updateMeasureMigratedFlag(); context.getStatistics() .add("insertsOrUpdates", insertsOrUpdates) .add("unchanged", unchanged); } - private void updateMeasureMigratedFlag() { - Type type = treeRootHolder.getRoot().getType(); - if (type == Type.PROJECT) { - persistBranchFlag(); - } else if (type == Type.VIEW) { - persistPortfolioFlag(); - } - } - - private void persistBranchFlag() { - try (DbSession dbSession = dbClient.openSession(false)) { - dbClient.branchDao().updateMeasuresMigrated(dbSession, treeRootHolder.getRoot().getUuid(), true); - dbSession.commit(); - } - } - - private void persistPortfolioFlag() { - try (DbSession dbSession = dbClient.openSession(false)) { - dbClient.portfolioDao().updateMeasuresMigrated(dbSession, treeRootHolder.getRoot().getUuid(), true); - dbSession.commit(); - } - } - private Set getDBMeasureHashes() { try (DbSession dbSession = dbClient.openSession(false)) { return dbClient.measureDao().selectMeasureHashesForBranch(dbSession, treeRootHolder.getRoot().getUuid()); diff --git a/server/sonar-db-dao/src/it/java/org/sonar/db/component/BranchDaoIT.java b/server/sonar-db-dao/src/it/java/org/sonar/db/component/BranchDaoIT.java index 77ac376f26b..f5096c9a414 100644 --- a/server/sonar-db-dao/src/it/java/org/sonar/db/component/BranchDaoIT.java +++ b/server/sonar-db-dao/src/it/java/org/sonar/db/component/BranchDaoIT.java @@ -42,7 +42,6 @@ import org.sonar.db.metric.MetricDto; import org.sonar.db.project.ProjectDto; import org.sonar.db.protobuf.DbProjectBranches; -import static java.lang.String.format; import static java.util.Arrays.asList; import static java.util.Collections.emptyList; import static java.util.Collections.singletonList; @@ -751,26 +750,6 @@ class BranchDaoIT { } - @Test - void updateMeasuresMigrated() { - ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent(); - String uuid1 = db.components().insertProjectBranch(project, b -> b.setBranchType(BranchType.BRANCH)).uuid(); - String uuid2 = db.components().insertProjectBranch(project, b -> b.setBranchType(BranchType.BRANCH)).uuid(); - - underTest.updateMeasuresMigrated(dbSession, uuid1, true); - underTest.updateMeasuresMigrated(dbSession, uuid2, false); - - assertThat(getMeasuresMigrated(uuid1)).isTrue(); - assertThat(getMeasuresMigrated(uuid2)).isFalse(); - } - - private boolean getMeasuresMigrated(String uuid1) { - List> select = db.select(dbSession, format("select measures_migrated from project_branches where uuid = '%s'", uuid1)); - - assertThat(select).hasSize(1); - return (boolean) select.get(0).get("measures_migrated"); - } - @Test void doAnyOfComponentsNeedIssueSync() { assertThat(underTest.doAnyOfComponentsNeedIssueSync(dbSession, emptyList())).isFalse(); diff --git a/server/sonar-db-dao/src/it/java/org/sonar/db/portfolio/PortfolioDaoIT.java b/server/sonar-db-dao/src/it/java/org/sonar/db/portfolio/PortfolioDaoIT.java index 07a3db425ab..3ba8db0adde 100644 --- a/server/sonar-db-dao/src/it/java/org/sonar/db/portfolio/PortfolioDaoIT.java +++ b/server/sonar-db-dao/src/it/java/org/sonar/db/portfolio/PortfolioDaoIT.java @@ -21,7 +21,6 @@ package org.sonar.db.portfolio; import java.util.Arrays; import java.util.List; -import java.util.Map; import java.util.Set; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; @@ -39,7 +38,6 @@ import org.sonar.db.component.ProjectData; import org.sonar.db.project.ApplicationProjectDto; import org.sonar.db.project.ProjectDto; -import static java.lang.String.format; import static java.util.Collections.emptySet; import static java.util.Collections.singleton; import static org.assertj.core.api.Assertions.assertThat; @@ -250,28 +248,6 @@ class PortfolioDaoIT { verify(audit).updateComponent(any(), any()); } - @Test - void update_measures_migrated() { - PortfolioDto portfolio1 = db.components().insertPrivatePortfolioDto("name1"); - PortfolioDto portfolio2 = db.components().insertPrivatePortfolioDto("name2"); - PortfolioDto portfolio3 = db.components().insertPrivatePortfolioDto("name3", - p -> p.setRootUuid(portfolio1.getUuid()).setParentUuid(portfolio1.getUuid())); - - portfolioDao.updateMeasuresMigrated(session, portfolio1.getUuid(), true); - portfolioDao.updateMeasuresMigrated(session, portfolio2.getUuid(), false); - - assertThat(getMeasuresMigrated(portfolio1.getUuid())).isTrue(); - assertThat(getMeasuresMigrated(portfolio2.getUuid())).isFalse(); - assertThat(getMeasuresMigrated(portfolio3.getUuid())).isTrue(); - } - - private boolean getMeasuresMigrated(String uuid1) { - List> select = db.select(session, format("select measures_migrated from portfolios where uuid = '%s'", uuid1)); - - assertThat(select).hasSize(1); - return (boolean) select.get(0).get("measures_migrated"); - } - @Test void selectAllReferencesToPortfolios() { db.components().insertPrivatePortfolioDto("portfolio1"); diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchDao.java index 31479d4b5a3..0e7eb4bbb3c 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchDao.java @@ -183,11 +183,6 @@ public class BranchDao implements Dao { return mapper(dbSession).updateIsMain(branchUuid, isMain, now); } - public long updateMeasuresMigrated(DbSession dbSession, String branchUuid, boolean measuresMigrated) { - long now = system2.now(); - return mapper(dbSession).updateMeasuresMigrated(branchUuid, measuresMigrated, now); - } - public boolean doAnyOfComponentsNeedIssueSync(DbSession session, List components) { if (!components.isEmpty()) { List result = new LinkedList<>(); diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchMapper.java index 536d3cb7701..864e2b61642 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchMapper.java @@ -77,6 +77,4 @@ public interface BranchMapper { List selectMainBranchesByProjectUuids(@Param("projectUuids") Collection projectUuids); List selectBranchMeasuresWithCaycMetric(long yesterday); - - int updateMeasuresMigrated(@Param("uuid") String uuid, @Param("measuresMigrated") boolean measuresMigrated, @Param("now") long now); } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/portfolio/PortfolioDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/portfolio/PortfolioDao.java index cd3152a7ad9..2f88082ed13 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/portfolio/PortfolioDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/portfolio/PortfolioDao.java @@ -248,11 +248,6 @@ public class PortfolioDao implements Dao { return uuid; } - public long updateMeasuresMigrated(DbSession dbSession, String branchUuid, boolean measuresMigrated) { - long now = system2.now(); - return mapper(dbSession).updateMeasuresMigrated(branchUuid, measuresMigrated, now); - } - public void deleteProjects(DbSession dbSession, String portfolioUuid) { mapper(dbSession).deleteProjects(portfolioUuid); } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/portfolio/PortfolioMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/portfolio/PortfolioMapper.java index 218ecc688bf..05c6225719e 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/portfolio/PortfolioMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/portfolio/PortfolioMapper.java @@ -116,6 +116,4 @@ public interface PortfolioMapper { List selectRootOfReferencersToAppBranch(@Param("appUuid") String appUuid, @Param("appBranchKey") String appBranchKey); List selectUuidsByKey(@Param("rootKey") String rootKey); - - int updateMeasuresMigrated(@Param("uuid") String uuid, @Param("measuresMigrated") boolean measuresMigrated, @Param("now") long now); } diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/component/BranchMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/component/BranchMapper.xml index d90e2846960..b2b3993d2bf 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/component/BranchMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/component/BranchMapper.xml @@ -278,15 +278,6 @@ uuid = #{uuid, jdbcType=VARCHAR} - - update project_branches - set - measures_migrated = #{measuresMigrated, jdbcType=BOOLEAN}, - updated_at = #{now, jdbcType=BIGINT} - where - uuid = #{uuid, jdbcType=VARCHAR} - - select case when exists diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/portfolio/PortfolioMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/portfolio/PortfolioMapper.xml index c1cd7494f4c..2071d83028c 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/portfolio/PortfolioMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/portfolio/PortfolioMapper.xml @@ -560,13 +560,4 @@ WHERE uuid = #{uuid,jdbcType=VARCHAR} - - - update portfolios - set - measures_migrated = #{measuresMigrated, jdbcType=BOOLEAN}, - updated_at = #{now, jdbcType=BIGINT} - where - root_uuid = #{uuid, jdbcType=VARCHAR} - diff --git a/server/sonar-db-dao/src/schema/schema-sq.ddl b/server/sonar-db-dao/src/schema/schema-sq.ddl index 10aafb7e3af..4474390011c 100644 --- a/server/sonar-db-dao/src/schema/schema-sq.ddl +++ b/server/sonar-db-dao/src/schema/schema-sq.ddl @@ -515,22 +515,6 @@ CREATE TABLE "ISSUES_IMPACTS"( ALTER TABLE "ISSUES_IMPACTS" ADD CONSTRAINT "PK_ISSUES_IMPACTS" PRIMARY KEY("ISSUE_KEY", "SOFTWARE_QUALITY"); CREATE UNIQUE NULLS NOT DISTINCT INDEX "UNIQ_ISS_KEY_SOF_QUAL" ON "ISSUES_IMPACTS"("ISSUE_KEY" NULLS FIRST, "SOFTWARE_QUALITY" NULLS FIRST); -CREATE TABLE "LIVE_MEASURES"( - "UUID" CHARACTER VARYING(40) NOT NULL, - "PROJECT_UUID" CHARACTER VARYING(50) NOT NULL, - "COMPONENT_UUID" CHARACTER VARYING(50) NOT NULL, - "METRIC_UUID" CHARACTER VARYING(40) NOT NULL, - "VALUE" DOUBLE PRECISION, - "TEXT_VALUE" CHARACTER VARYING(4000), - "MEASURE_DATA" BINARY LARGE OBJECT, - "UPDATE_MARKER" CHARACTER VARYING(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" NULLS FIRST); -CREATE UNIQUE NULLS NOT DISTINCT INDEX "LIVE_MEASURES_COMPONENT" ON "LIVE_MEASURES"("COMPONENT_UUID" NULLS FIRST, "METRIC_UUID" NULLS FIRST); - CREATE TABLE "MEASURES"( "COMPONENT_UUID" CHARACTER VARYING(40) NOT NULL, "BRANCH_UUID" CHARACTER VARYING(40) NOT NULL, @@ -698,12 +682,10 @@ CREATE TABLE "PORTFOLIOS"( "SELECTION_EXPRESSION" CHARACTER VARYING(4000), "CREATED_AT" BIGINT NOT NULL, "UPDATED_AT" BIGINT NOT NULL, - "BRANCH_KEY" CHARACTER VARYING(255), - "MEASURES_MIGRATED" BOOLEAN DEFAULT FALSE NOT NULL + "BRANCH_KEY" CHARACTER VARYING(255) ); ALTER TABLE "PORTFOLIOS" ADD CONSTRAINT "PK_PORTFOLIOS" PRIMARY KEY("UUID"); CREATE UNIQUE NULLS NOT DISTINCT INDEX "UNIQ_PORTFOLIOS_KEE" ON "PORTFOLIOS"("KEE" NULLS FIRST); -CREATE INDEX "PORTFOLIOS_MEASURES_MIGRATED" ON "PORTFOLIOS"("MEASURES_MIGRATED" NULLS FIRST); CREATE TABLE "PROJECT_ALM_SETTINGS"( "UUID" CHARACTER VARYING(40) NOT NULL, @@ -743,13 +725,11 @@ CREATE TABLE "PROJECT_BRANCHES"( "UPDATED_AT" BIGINT NOT NULL, "EXCLUDE_FROM_PURGE" BOOLEAN DEFAULT FALSE NOT NULL, "NEED_ISSUE_SYNC" BOOLEAN NOT NULL, - "IS_MAIN" BOOLEAN NOT NULL, - "MEASURES_MIGRATED" BOOLEAN DEFAULT FALSE NOT NULL + "IS_MAIN" BOOLEAN NOT NULL ); ALTER TABLE "PROJECT_BRANCHES" ADD CONSTRAINT "PK_PROJECT_BRANCHES" PRIMARY KEY("UUID"); CREATE UNIQUE NULLS NOT DISTINCT INDEX "UNIQ_PROJECT_BRANCHES" ON "PROJECT_BRANCHES"("BRANCH_TYPE" NULLS FIRST, "PROJECT_UUID" NULLS FIRST, "KEE" NULLS FIRST); CREATE INDEX "PROJECT_BRANCHES_PROJECT_UUID" ON "PROJECT_BRANCHES"("PROJECT_UUID" NULLS FIRST); -CREATE INDEX "PB_MEASURES_MIGRATED" ON "PROJECT_BRANCHES"("MEASURES_MIGRATED" NULLS FIRST); CREATE TABLE "PROJECT_LINKS"( "UUID" CHARACTER VARYING(40) NOT NULL, diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v100/PopulateNclocForForProjectsIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v100/PopulateNclocForForProjectsIT.java index 99fbca30912..6afff8bcf7d 100644 --- a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v100/PopulateNclocForForProjectsIT.java +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v100/PopulateNclocForForProjectsIT.java @@ -31,6 +31,7 @@ import org.sonar.server.platform.db.migration.step.DataChange; import static org.apache.commons.lang3.RandomStringUtils.secure; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatCode; class PopulateNclocForForProjectsIT { @@ -48,6 +49,15 @@ class PopulateNclocForForProjectsIT { verifyNclocCorrectlyPopulatedForProjects(expectedNclocByProjectUuid); } + @Test + void migration_does_nothing_if_live_measures_table_is_missing() { + db.executeDdl("drop table live_measures"); + db.assertTableDoesNotExist("live_measures"); + + assertThatCode(underTest::execute) + .doesNotThrowAnyException(); + } + @Test void migration_should_be_reentrant() throws SQLException { Map expectedNclocByProjectUuid = populateData(); diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v108/DropIndexOnPortfoliosMeasuresMigratedIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v108/DropIndexOnPortfoliosMeasuresMigratedIT.java new file mode 100644 index 00000000000..b7d05fc68a1 --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v108/DropIndexOnPortfoliosMeasuresMigratedIT.java @@ -0,0 +1,52 @@ +/* + * SonarQube + * Copyright (C) 2009-2024 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.v108; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; +import org.sonar.db.MigrationDbTester; +import org.sonar.server.platform.db.migration.step.DdlChange; + + +class DropIndexOnPortfoliosMeasuresMigratedIT { + + private static final String TABLE_NAME = "portfolios"; + private static final String COLUMN_NAME = "measures_migrated"; + private static final String INDEX_NAME = "portfolios_measures_migrated"; + + @RegisterExtension + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(DropIndexOnPortfoliosMeasuresMigrated.class); + private final DdlChange underTest = new DropIndexOnPortfoliosMeasuresMigrated(db.database()); + + @Test + void execute_givenIndexExists_dropsIndex() throws Exception { + db.assertIndex(TABLE_NAME, INDEX_NAME, COLUMN_NAME); + underTest.execute(); + db.assertIndexDoesNotExist(TABLE_NAME, INDEX_NAME); + } + + @Test + void execute_is_reentrant() throws Exception { + db.assertIndex(TABLE_NAME, INDEX_NAME, COLUMN_NAME); + underTest.execute(); + underTest.execute(); + db.assertIndexDoesNotExist(TABLE_NAME, INDEX_NAME); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v108/DropIndexOnProjectBranchesMeasuresMigratedIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v108/DropIndexOnProjectBranchesMeasuresMigratedIT.java new file mode 100644 index 00000000000..e2d89d209f3 --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v108/DropIndexOnProjectBranchesMeasuresMigratedIT.java @@ -0,0 +1,52 @@ +/* + * SonarQube + * Copyright (C) 2009-2024 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.v108; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; +import org.sonar.db.MigrationDbTester; +import org.sonar.server.platform.db.migration.step.DdlChange; + + +class DropIndexOnProjectBranchesMeasuresMigratedIT { + + private static final String TABLE_NAME = "project_branches"; + private static final String COLUMN_NAME = "measures_migrated"; + private static final String INDEX_NAME = "pb_measures_migrated"; + + @RegisterExtension + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(DropIndexOnProjectBranchesMeasuresMigrated.class); + private final DdlChange underTest = new DropIndexOnProjectBranchesMeasuresMigrated(db.database()); + + @Test + void execute_givenIndexExists_dropsIndex() throws Exception { + db.assertIndex(TABLE_NAME, INDEX_NAME, COLUMN_NAME); + underTest.execute(); + db.assertIndexDoesNotExist(TABLE_NAME, INDEX_NAME); + } + + @Test + void execute_is_reentrant() throws Exception { + db.assertIndex(TABLE_NAME, INDEX_NAME, COLUMN_NAME); + underTest.execute(); + underTest.execute(); + db.assertIndexDoesNotExist(TABLE_NAME, INDEX_NAME); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v108/DropLiveMeasuresTableIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v108/DropLiveMeasuresTableIT.java new file mode 100644 index 00000000000..1cfaa301602 --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v108/DropLiveMeasuresTableIT.java @@ -0,0 +1,49 @@ +/* + * SonarQube + * Copyright (C) 2009-2024 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.v108; + +import java.sql.SQLException; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; +import org.sonar.db.MigrationDbTester; + + +class DropLiveMeasuresTableIT { + public static final String TABLE_NAME = "live_measures"; + + @RegisterExtension + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(DropLiveMeasuresTable.class); + private final DropLiveMeasuresTable underTest = new DropLiveMeasuresTable(db.database()); + + @Test + void execute_shouldDropTable() throws SQLException { + db.assertTableExists(TABLE_NAME); + underTest.execute(); + db.assertTableDoesNotExist(TABLE_NAME); + } + + @Test + void execute_shouldSupportReentrantMigrationExecution() throws SQLException { + db.assertTableExists(TABLE_NAME); + underTest.execute(); + underTest.execute(); + db.assertTableDoesNotExist(TABLE_NAME); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v108/DropMeasuresMigratedInPortfoliosTableIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v108/DropMeasuresMigratedInPortfoliosTableIT.java new file mode 100644 index 00000000000..880dacaf2c5 --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v108/DropMeasuresMigratedInPortfoliosTableIT.java @@ -0,0 +1,52 @@ +/* + * SonarQube + * Copyright (C) 2009-2024 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.v108; + +import java.sql.SQLException; +import java.sql.Types; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; +import org.sonar.db.MigrationDbTester; +import org.sonar.server.platform.db.migration.step.DdlChange; + +import static org.sonar.server.platform.db.migration.version.v108.DropMeasuresMigratedColumnInPortfoliosTable.COLUMN_NAME; +import static org.sonar.server.platform.db.migration.version.v108.DropMeasuresMigratedColumnInPortfoliosTable.TABLE_NAME; + +class DropMeasuresMigratedInPortfoliosTableIT { + + @RegisterExtension + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(DropMeasuresMigratedColumnInPortfoliosTable.class); + private final DdlChange underTest = new DropMeasuresMigratedColumnInPortfoliosTable(db.database()); + + @Test + void executed_whenRun_shouldDropSystemTagsColumn() throws SQLException { + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.BOOLEAN, null, false); + underTest.execute(); + db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); + } + + @Test + void execute_whenRunMoreThanOnce_shouldBeReentrant() throws SQLException { + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.BOOLEAN, null, false); + underTest.execute(); + underTest.execute(); + db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v108/DropMeasuresMigratedInProjectBranchesTableIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v108/DropMeasuresMigratedInProjectBranchesTableIT.java new file mode 100644 index 00000000000..cdc1f6c94be --- /dev/null +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v108/DropMeasuresMigratedInProjectBranchesTableIT.java @@ -0,0 +1,52 @@ +/* + * SonarQube + * Copyright (C) 2009-2024 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.v108; + +import java.sql.SQLException; +import java.sql.Types; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; +import org.sonar.db.MigrationDbTester; +import org.sonar.server.platform.db.migration.step.DdlChange; + +import static org.sonar.server.platform.db.migration.version.v108.DropMeasuresMigratedColumnInProjectBranchesTable.COLUMN_NAME; +import static org.sonar.server.platform.db.migration.version.v108.DropMeasuresMigratedColumnInProjectBranchesTable.TABLE_NAME; + +class DropMeasuresMigratedInProjectBranchesTableIT { + + @RegisterExtension + public final MigrationDbTester db = MigrationDbTester.createForMigrationStep(DropMeasuresMigratedColumnInProjectBranchesTable.class); + private final DdlChange underTest = new DropMeasuresMigratedColumnInProjectBranchesTable(db.database()); + + @Test + void executed_whenRun_shouldDropSystemTagsColumn() throws SQLException { + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.BOOLEAN, null, false); + underTest.execute(); + db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); + } + + @Test + void execute_whenRunMoreThanOnce_shouldBeReentrant() throws SQLException { + db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.BOOLEAN, null, false); + underTest.execute(); + underTest.execute(); + db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME); + } +} diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v108/MigrateBranchesLiveMeasuresToMeasuresIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v108/MigrateBranchesLiveMeasuresToMeasuresIT.java index 27d896ff796..025bcfa74a9 100644 --- a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v108/MigrateBranchesLiveMeasuresToMeasuresIT.java +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v108/MigrateBranchesLiveMeasuresToMeasuresIT.java @@ -35,6 +35,7 @@ import org.sonar.server.platform.db.migration.step.DataChange; import static java.lang.String.format; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatCode; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.assertj.core.api.Assertions.tuple; import static org.mockito.Mockito.mock; @@ -62,6 +63,18 @@ class MigrateBranchesLiveMeasuresToMeasuresIT { assertThat(db.countRowsOfTable("measures")).isZero(); } + @Test + void migration_does_nothing_if_live_measures_table_is_missing() { + db.executeDdl("drop table live_measures"); + db.assertTableDoesNotExist("live_measures"); + String branch = "branch_3"; + insertNotMigratedBranch(branch); + + assertThatCode(underTest::execute) + .doesNotThrowAnyException(); + } + + @Test void log_the_item_uuid_when_the_migration_fails() { String nclocMetricUuid = insertMetric("ncloc", "INT"); diff --git a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v108/MigratePortfoliosLiveMeasuresToMeasuresIT.java b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v108/MigratePortfoliosLiveMeasuresToMeasuresIT.java index 38d30950f09..94d2e0e0701 100644 --- a/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v108/MigratePortfoliosLiveMeasuresToMeasuresIT.java +++ b/server/sonar-db-migration/src/it/java/org/sonar/server/platform/db/migration/version/v108/MigratePortfoliosLiveMeasuresToMeasuresIT.java @@ -35,6 +35,7 @@ import org.sonar.server.platform.db.migration.step.DataChange; import static java.lang.String.format; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatCode; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.assertj.core.api.Assertions.tuple; import static org.mockito.Mockito.mock; @@ -62,6 +63,17 @@ class MigratePortfoliosLiveMeasuresToMeasuresIT { assertThat(db.countRowsOfTable("measures")).isZero(); } + @Test + void migration_does_nothing_if_live_measures_table_is_missing() { + db.executeDdl("drop table live_measures"); + db.assertTableDoesNotExist("live_measures"); + String branch = "portfolio_1"; + insertNotMigratedPortfolio(branch); + + assertThatCode(underTest::execute) + .doesNotThrowAnyException(); + } + @Test void log_the_item_uuid_when_the_migration_fails() { String nclocMetricUuid = insertMetric("ncloc", "INT"); diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v100/PopulateNclocForForProjects.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v100/PopulateNclocForForProjects.java index 69f9eb16164..67ffe2a6720 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v100/PopulateNclocForForProjects.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v100/PopulateNclocForForProjects.java @@ -19,8 +19,10 @@ */ package org.sonar.server.platform.db.migration.version.v100; +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.step.DataChange; import org.sonar.server.platform.db.migration.step.MassUpdate; @@ -42,6 +44,13 @@ public class PopulateNclocForForProjects extends DataChange { @Override protected void execute(Context context) throws SQLException { + try (Connection c = getDatabase().getDataSource().getConnection()) { + // the table is deleted in 10.8, this check ensures the migration re-entrance + if (!DatabaseUtils.tableExists("live_measures", c)) { + return; + } + } + MassUpdate massUpdate = context.prepareMassUpdate(); massUpdate.select(SELECT_QUERY); massUpdate.update("update projects set ncloc = ? where uuid = ?"); diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v108/AbstractMigrateLiveMeasuresToMeasures.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v108/AbstractMigrateLiveMeasuresToMeasures.java index 2782a74699b..58f79a98af0 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v108/AbstractMigrateLiveMeasuresToMeasures.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v108/AbstractMigrateLiveMeasuresToMeasures.java @@ -20,6 +20,7 @@ package org.sonar.server.platform.db.migration.version.v108; import com.google.gson.Gson; +import java.sql.Connection; import java.sql.SQLException; import java.util.HashMap; import java.util.List; @@ -32,6 +33,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.sonar.api.utils.System2; import org.sonar.db.Database; +import org.sonar.db.DatabaseUtils; import org.sonar.server.platform.db.migration.step.DataChange; import org.sonar.server.platform.db.migration.step.MassUpdate; import org.sonar.server.platform.db.migration.step.Select; @@ -100,6 +102,13 @@ public abstract class AbstractMigrateLiveMeasuresToMeasures extends DataChange { @Override protected void execute(Context context) throws SQLException { + try (Connection c = getDatabase().getDataSource().getConnection()) { + // the table is later deleted, this check ensures the migration re-entrance + if (!DatabaseUtils.tableExists("live_measures", c)) { + return; + } + } + List uuids = context.prepareSelect(getSelectUuidQuery()) .setBoolean(1, false) .list(row -> row.getString(1)); diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v108/DbVersion108.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v108/DbVersion108.java index 2d001f4d95e..2324f4c9541 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v108/DbVersion108.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v108/DbVersion108.java @@ -49,7 +49,13 @@ public class DbVersion108 implements DbVersion { .add(10_8_006, "Migrate the content of 'live_measures' to 'measures' for portfolios", MigratePortfoliosLiveMeasuresToMeasures.class) .add(10_8_007, "Create primary key on 'measures' table", CreatePrimaryKeyOnMeasuresTable.class) .add(10_8_008, "Create index on column 'branch_uuid' in 'measures' table", CreateIndexOnMeasuresTable.class) - .add(10_8_009, "Drop column 'from_hotspot' in the 'issues' table", DropColumnFromHotspotInIssues.class); + .add(10_8_009, "Drop column 'from_hotspot' in the 'issues' table", DropColumnFromHotspotInIssues.class) + .add(10_8_010, "Drop 'live_measures' table", DropLiveMeasuresTable.class) + .add(10_8_011, "Drop index on 'portfolios.measures_migrated'", DropIndexOnPortfoliosMeasuresMigrated.class) + .add(10_8_012, "Drop 'measures_migrated' column on 'portfolios' table", DropMeasuresMigratedColumnInPortfoliosTable.class) + .add(10_8_013, "Drop index on 'project_branches.measures_migrated'", DropIndexOnProjectBranchesMeasuresMigrated.class) + .add(10_8_014, "Drop 'measures_migrated' column on 'project_branches' table", DropMeasuresMigratedColumnInProjectBranchesTable.class) + ; } } diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v108/DropIndexOnPortfoliosMeasuresMigrated.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v108/DropIndexOnPortfoliosMeasuresMigrated.java new file mode 100644 index 00000000000..ffb67f82690 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v108/DropIndexOnPortfoliosMeasuresMigrated.java @@ -0,0 +1,33 @@ +/* + * SonarQube + * Copyright (C) 2009-2024 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.v108; + +import org.sonar.db.Database; +import org.sonar.server.platform.db.migration.step.DropIndexChange; + +public class DropIndexOnPortfoliosMeasuresMigrated extends DropIndexChange { + + private static final String TABLE_NAME = "portfolios"; + private static final String INDEX_NAME = "portfolios_measures_migrated"; + + public DropIndexOnPortfoliosMeasuresMigrated(Database db) { + super(db, INDEX_NAME, TABLE_NAME); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v108/DropIndexOnProjectBranchesMeasuresMigrated.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v108/DropIndexOnProjectBranchesMeasuresMigrated.java new file mode 100644 index 00000000000..58329b87913 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v108/DropIndexOnProjectBranchesMeasuresMigrated.java @@ -0,0 +1,33 @@ +/* + * SonarQube + * Copyright (C) 2009-2024 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.v108; + +import org.sonar.db.Database; +import org.sonar.server.platform.db.migration.step.DropIndexChange; + +public class DropIndexOnProjectBranchesMeasuresMigrated extends DropIndexChange { + + private static final String TABLE_NAME = "project_branches"; + private static final String INDEX_NAME = "pb_measures_migrated"; + + public DropIndexOnProjectBranchesMeasuresMigrated(Database db) { + super(db, INDEX_NAME, TABLE_NAME); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v108/DropLiveMeasuresTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v108/DropLiveMeasuresTable.java new file mode 100644 index 00000000000..02ebc037790 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v108/DropLiveMeasuresTable.java @@ -0,0 +1,45 @@ +/* + * SonarQube + * Copyright (C) 2009-2024 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.v108; + +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.DropTableBuilder; +import org.sonar.server.platform.db.migration.step.DdlChange; + +public class DropLiveMeasuresTable extends DdlChange { + + private static final String TABLE_NAME = "live_measures"; + + public DropLiveMeasuresTable(Database db) { + super(db); + } + + @Override + public void execute(Context context) throws SQLException { + try (Connection c = getDatabase().getDataSource().getConnection()) { + if (DatabaseUtils.tableExists(TABLE_NAME, c)) { + context.execute(new DropTableBuilder(getDialect(), TABLE_NAME).build()); + } + } + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v108/DropMeasuresMigratedColumnInPortfoliosTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v108/DropMeasuresMigratedColumnInPortfoliosTable.java new file mode 100644 index 00000000000..976462e0033 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v108/DropMeasuresMigratedColumnInPortfoliosTable.java @@ -0,0 +1,35 @@ +/* + * SonarQube + * Copyright (C) 2009-2024 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.v108; + +import com.google.common.annotations.VisibleForTesting; +import org.sonar.db.Database; +import org.sonar.server.platform.db.migration.step.DropColumnChange; + +public class DropMeasuresMigratedColumnInPortfoliosTable extends DropColumnChange { + @VisibleForTesting + static final String COLUMN_NAME = "measures_migrated"; + @VisibleForTesting + static final String TABLE_NAME = "portfolios"; + + protected DropMeasuresMigratedColumnInPortfoliosTable(Database db) { + super(db, TABLE_NAME, COLUMN_NAME); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v108/DropMeasuresMigratedColumnInProjectBranchesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v108/DropMeasuresMigratedColumnInProjectBranchesTable.java new file mode 100644 index 00000000000..b3fdaf5d639 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v108/DropMeasuresMigratedColumnInProjectBranchesTable.java @@ -0,0 +1,35 @@ +/* + * SonarQube + * Copyright (C) 2009-2024 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.v108; + +import com.google.common.annotations.VisibleForTesting; +import org.sonar.db.Database; +import org.sonar.server.platform.db.migration.step.DropColumnChange; + +public class DropMeasuresMigratedColumnInProjectBranchesTable extends DropColumnChange { + @VisibleForTesting + static final String COLUMN_NAME = "measures_migrated"; + @VisibleForTesting + static final String TABLE_NAME = "project_branches"; + + protected DropMeasuresMigratedColumnInProjectBranchesTable(Database db) { + super(db, TABLE_NAME, COLUMN_NAME); + } +} -- 2.39.5