aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2020-04-27 12:42:10 -0500
committersonartech <sonartech@sonarsource.com>2020-05-25 20:05:20 +0000
commit6b41a01454b98c413889dc2400a9cddb3b390847 (patch)
tree6ccca99e10d77b453abc252835d6c70cfdb41d6c
parent65e12a8ca01341c1ad00809d807bb8db0f5bf4b2 (diff)
downloadsonarqube-6b41a01454b98c413889dc2400a9cddb3b390847.tar.gz
sonarqube-6b41a01454b98c413889dc2400a9cddb3b390847.zip
SONAR-13221 Metrics
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/MeasureToMeasureDto.java4
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/metric/Metric.java4
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/metric/MetricDtoToMetric.java2
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/metric/MetricImpl.java16
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/metric/MetricRepository.java10
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/metric/MetricRepositoryImpl.java14
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/organization/package-info.java2
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/purge/ProjectCleaner.java4
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/purge/package-info.java2
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/qualitygate/QualityGateServiceImpl.java2
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/CustomMeasuresCopyStep.java2
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistLiveMeasuresStep.java6
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/api/measurecomputer/MeasureComputerContextImplTest.java12
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/BatchMeasureToMeasureTest.java12
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/BestValueOptimizationTest.java2
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/LiveMeasureDtoToMeasureTest.java14
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MapBasedRawMeasureRepositoryTest.java6
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureDtoToMeasureTest.java14
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureRepositoryImplTest.java16
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureToMeasureDtoTest.java14
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/qualitygatedetails/QualityGateDetailsDataTest.java4
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/metric/MetricDtoToMetricTest.java6
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/metric/MetricImplTest.java36
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/metric/MetricRepositoryImplTest.java30
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualitygate/ConditionEvaluatorTest.java4
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualitygate/EvaluationResultTextConverterTest.java4
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualitygate/QualityGateServiceImplTest.java24
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/CustomMeasuresCopyStepTest.java28
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ExecuteVisitorsStepTest.java4
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/LoadQualityGateStepTest.java4
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistDuplicationDataStepTest.java2
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistLiveMeasuresStepTest.java12
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistMeasuresStepTest.java6
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/QualityGateMeasuresStepTest.java2
-rw-r--r--server/sonar-ce-task-projectanalysis/src/testFixtures/java/org/sonar/ce/task/projectanalysis/metric/MetricRepositoryRule.java32
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/measure/LiveMeasureComparator.java2
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/measure/LiveMeasureDao.java16
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/measure/LiveMeasureDto.java12
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/measure/LiveMeasureMapper.java8
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/measure/MeasureDto.java12
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/measure/MeasureTreeQuery.java16
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/measure/PastMeasureDto.java10
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/measure/PastMeasureQuery.java10
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/measure/ProjectMeasuresIndexerIterator.java2
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/measure/custom/CustomMeasureDao.java12
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/measure/custom/CustomMeasureDto.java13
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/measure/custom/CustomMeasureMapper.java6
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/metric/MetricDao.java12
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/metric/MetricDto.java10
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/metric/MetricMapper.java6
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateConditionDto.java10
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml2
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/measure/LiveMeasureMapper.xml50
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/measure/MeasureMapper.xml14
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/measure/custom/CustomMeasureMapper.xml24
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/metric/MetricMapper.xml33
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/organization/OrganizationMapper.xml2
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/qualitygate/QualityGateConditionMapper.xml10
-rw-r--r--server/sonar-db-dao/src/schema/schema-sq.ddl26
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/measure/LiveMeasureDaoTest.java106
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/measure/MeasureDaoTest.java30
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/measure/MeasureTreeQueryTest.java10
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/measure/PastMeasureDtoTest.java8
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/measure/custom/CustomMeasureDaoTest.java18
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/metric/MetricDaoTest.java28
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/metric/MetricDtoTest.java4
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeCommandsTest.java2
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeDaoTest.java16
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/qualitygate/QualityGateConditionDaoTest.java24
-rw-r--r--server/sonar-db-dao/src/testFixtures/java/org/sonar/db/measure/MeasureDbTester.java2
-rw-r--r--server/sonar-db-dao/src/testFixtures/java/org/sonar/db/measure/MeasureTesting.java10
-rw-r--r--server/sonar-db-dao/src/testFixtures/java/org/sonar/db/measure/custom/CustomMeasureTesting.java4
-rw-r--r--server/sonar-db-dao/src/testFixtures/java/org/sonar/db/metric/MetricTesting.java2
-rw-r--r--server/sonar-db-dao/src/testFixtures/java/org/sonar/db/qualitygate/QualityGateDbTester.java2
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/DbVersion83.java64
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/AddPrimaryKeyOnUuidColumnOfMetricsTable.java38
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/AddUuidColumnToMetricsTable.java31
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/DropIdColumnOfMetricsTable.java31
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/DropPrimaryKeyOnIdColumnOfMetricsTable.java32
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/MakeMetricsUuidColumnNotNullable.java31
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/PopulateMetricsUuid.java50
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/livemeasures/AddIndexOnMetricUuidOfLiveMeasuresTable.java66
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/livemeasures/AddMetricUuidColumnToLiveMeasures.java50
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/livemeasures/DropIndexOnMetricIdOfLiveMeasuresTable.java52
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/livemeasures/DropMetricIdColumnOfLiveMeasuresTable.java36
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/livemeasures/MakeLiveMeasuresMetricUuidNotNullable.java50
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/livemeasures/PopulateLiveMeasuresMetricUuid.java49
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/manualmeasures/AddMetricUuidColumnToManualMeasures.java50
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/manualmeasures/DropMetricIdColumnOfManualMeasuresTable.java36
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/manualmeasures/MakeManualMeasuresMetricUuidNotNullable.java50
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/manualmeasures/PopulateManualMeasuresMetricUuid.java49
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/projectmeasures/AddIndexOnMetricUuidOfProjectMeasuresTable.java66
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/projectmeasures/AddMetricUuidColumnToProjectMeasures.java50
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/projectmeasures/DropIndexOnMetricIdOfProjectMeasuresTable.java52
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/projectmeasures/DropMetricIdColumnOfProjectMeasuresTable.java36
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/projectmeasures/MakeProjectMeasuresMetricUuidNotNullable.java50
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/projectmeasures/PopulateProjectMeasuresMetricUuid.java49
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/qualitygateconditions/AddMetricUuidColumnToQualityGateConditions.java50
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/qualitygateconditions/DropMetricIdColumnOfQualityGateConditionsTable.java36
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/qualitygateconditions/MakeQualityGateConditionsMetricUuidNotNullable.java50
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/qualitygateconditions/PopulateQualityGateConditionsMetricUuid.java52
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/AddPrimaryKeyOnUuidColumnOfMetricsTableTest.java50
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/AddUuidColumnToMetricsTableTest.java60
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/DropIdColumnOfMetricsTableTest.java51
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/DropPrimaryKeyOnIdColumnOfMetricsTableTest.java56
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/MakeMetricsUuidColumnNotNullableTest.java42
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/PopulateMetricsUuidTest.java79
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/livemeasures/AddIndexOnMetricUuidOfLiveMeasuresTableTest.java50
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/livemeasures/AddMetricUuidColumnToLiveMeasuresTest.java64
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/livemeasures/DropIndexOnMetricIdOfLiveMeasuresTableTest.java54
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/livemeasures/DropMetricIdColumnOfLiveMeasuresTableTest.java50
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/livemeasures/MakeLiveMeasuresMetricUuidNotNullableTest.java42
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/livemeasures/PopulateLiveMeasuresMetricUuidTest.java102
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/manualmeasures/AddMetricUuidColumnToManualMeasuresTest.java60
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/manualmeasures/DropMetricIdColumnOfManualMeasuresTableTest.java50
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/manualmeasures/MakeManualMeasuresMetricUuidNotNullableTest.java42
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/manualmeasures/PopulateManualMeasuresMetricUuidTest.java99
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/projectmeasures/AddIndexOnMetricUuidOfProjectMeasuresTableTest.java50
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/projectmeasures/AddMetricUuidColumnToProjectMeasuresTest.java61
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/projectmeasures/DropIndexOnMetricIdOfProjectMeasuresTableTest.java54
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/projectmeasures/DropMetricIdColumnOfProjectMeasuresTableTest.java50
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/projectmeasures/MakeProjectMeasuresMetricUuidNotNullableTest.java42
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/projectmeasures/PopulateProjectMeasuresMetricUuidTest.java100
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/qualitygateconditions/AddMetricUuidColumnToQualityGateConditionsTest.java59
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/qualitygateconditions/DropMetricIdColumnOfQualityGateConditionsTableTest.java50
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/qualitygateconditions/MakeQualityGateConditionsMetricUuidNotNullableTest.java42
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/qualitygateconditions/PopulateQualityGateConditionsMetricUuidTest.java118
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/AddPrimaryKeyOnUuidColumnOfMetricsTableTest/schema.sql20
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/AddUuidColumnToMetricsTableTest/schema.sql20
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/DropIdColumnOfMetricsTableTest/schema.sql21
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/DropPrimaryKeyOnIdColumnOfMetricsTableTest/schema.sql21
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/MakeMetricsUuidColumnNotNullableTest/schema.sql21
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/PopulateMetricsUuidTest/schema.sql21
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/livemeasures/AddIndexOnMetricUuidOfLiveMeasuresTableTest/schema.sql16
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/livemeasures/AddMetricUuidColumnToLiveMeasuresTest/schema.sql16
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/livemeasures/DropIndexOnMetricIdOfLiveMeasuresTableTest/schema.sql17
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/livemeasures/DropMetricIdColumnOfLiveMeasuresTableTest/schema.sql17
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/livemeasures/MakeLiveMeasuresMetricUuidNotNullableTest/schema.sql17
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/livemeasures/PopulateLiveMeasuresMetricUuidTest/schema.sql39
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/manualmeasures/AddMetricUuidColumnToManualMeasuresTest/schema.sql35
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/manualmeasures/DropMetricIdColumnOfManualMeasuresTableTest/schema.sql36
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/manualmeasures/MakeManualMeasuresMetricUuidNotNullableTest/schema.sql36
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/manualmeasures/PopulateManualMeasuresMetricUuidTest/schema.sql36
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/projectmeasures/AddIndexOnMetricUuidOfProjectMeasuresTableTest/schema.sql21
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/projectmeasures/AddMetricUuidColumnToProjectMeasuresTest/schema.sql21
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/projectmeasures/DropIndexOnMetricIdOfProjectMeasuresTableTest/schema.sql22
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/projectmeasures/DropMetricIdColumnOfProjectMeasuresTableTest/schema.sql22
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/projectmeasures/MakeProjectMeasuresMetricUuidNotNullableTest/schema.sql22
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/projectmeasures/PopulateProjectMeasuresMetricUuidTest/schema.sql44
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/qualitygateconditions/AddMetricUuidColumnToQualityGateConditionsTest/schema.sql34
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/qualitygateconditions/DropMetricIdColumnOfQualityGateConditionsTableTest/schema.sql35
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/qualitygateconditions/MakeQualityGateConditionsMetricUuidNotNullableTest/schema.sql35
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/qualitygateconditions/PopulateQualityGateConditionsMetricUuidTest/schema.sql35
-rw-r--r--server/sonar-server-common/src/main/java/org/sonar/server/metric/DefaultMetricFinder.java6
-rw-r--r--server/sonar-server-common/src/main/java/org/sonar/server/metric/MetricToDto.java2
-rw-r--r--server/sonar-server-common/src/main/java/org/sonar/server/notification/DefaultNotificationManager.java2
-rw-r--r--server/sonar-server-common/src/test/java/org/sonar/server/metric/DefaultMetricFinderTest.java2
-rw-r--r--server/sonar-webserver-core/src/main/java/org/sonar/server/startup/RegisterMetrics.java12
-rw-r--r--server/sonar-webserver-core/src/test/java/org/sonar/server/startup/RegisterMetricsTest.java19
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/badge/ws/MeasureAction.java1
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/badge/ws/QualityGateAction.java1
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/ComponentViewerJsonWriter.java6
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/hotspot/ws/DeleteCommentAction.java1
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/custom/ws/CreateAction.java14
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/custom/ws/SearchAction.java43
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/custom/ws/UpdateAction.java6
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/LiveMeasureComputerImpl.java8
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/LiveQualityGateComputerImpl.java10
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/MeasureMatrix.java12
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentAction.java12
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentTreeAction.java6
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/MetricDtoWithBestValue.java2
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/PrMeasureFix.java6
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/SearchAction.java8
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/SearchHistoryAction.java2
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/SearchHistoryResponseFactory.java4
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/SearchHistoryResult.java8
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/metric/ws/CreateAction.java10
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/metric/ws/DeleteAction.java23
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/metric/ws/MetricJsonWriter.java2
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/metric/ws/UpdateAction.java18
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/QualityGateConditionsUpdater.java6
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/QualityGateUpdater.java2
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/RegisterQualityGates.java10
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/ShowAction.java24
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/user/ws/DeactivateAction.java2
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/duplication/ws/ShowActionTest.java2
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/custom/ws/CreateActionTest.java78
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/custom/ws/MetricsActionTest.java4
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/custom/ws/SearchActionTest.java6
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/custom/ws/UpdateActionTest.java10
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/live/LiveMeasureComputerImplTest.java8
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/live/LiveQualityGateComputerImplTest.java6
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/live/MeasureMatrixTest.java12
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/prMeasureFixTest.java28
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/metric/ws/CreateActionTest.java11
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/metric/ws/DeleteActionTest.java8
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/metric/ws/MetricsWsTest.java5
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/metric/ws/UpdateActionTest.java50
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/QualityGateConditionsUpdaterTest.java4
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/RegisterQualityGatesTest.java16
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/CopyActionTest.java4
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/CreateConditionActionTest.java4
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/DeleteConditionActionTest.java2
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/ShowActionTest.java2
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/UpdateConditionActionTest.java8
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/measures/Metric.java10
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/measures/MetricFinder.java2
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/measures/MetricTest.java2
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/DefaultMetricsRepositoryLoader.java8
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/ScannerMediumTester.java2
211 files changed, 4270 insertions, 765 deletions
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/MeasureToMeasureDto.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/MeasureToMeasureDto.java
index 03b53f9b63d..d729a7257ff 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/MeasureToMeasureDto.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/MeasureToMeasureDto.java
@@ -39,7 +39,7 @@ public class MeasureToMeasureDto {
public MeasureDto toMeasureDto(Measure measure, Metric metric, Component component) {
MeasureDto out = new MeasureDto();
- out.setMetricId(metric.getId());
+ out.setMetricUuid(metric.getUuid());
out.setComponentUuid(component.getUuid());
out.setAnalysisUuid(analysisMetadataHolder.getUuid());
if (measure.hasVariation()) {
@@ -55,7 +55,7 @@ public class MeasureToMeasureDto {
public LiveMeasureDto toLiveMeasureDto(Measure measure, Metric metric, Component component) {
LiveMeasureDto out = new LiveMeasureDto();
- out.setMetricId(metric.getId());
+ out.setMetricUuid(metric.getUuid());
out.setComponentUuid(component.getUuid());
out.setProjectUuid(treeRootHolder.getRoot().getUuid());
if (measure.hasVariation()) {
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/metric/Metric.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/metric/Metric.java
index 4b9602c8abd..1f7d985d7d1 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/metric/Metric.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/metric/Metric.java
@@ -24,9 +24,9 @@ import org.sonar.ce.task.projectanalysis.measure.Measure;
public interface Metric {
/**
- * The metric's id (ie. its database identifier)
+ * The metric's uuid (ie. its database identifier)
*/
- int getId();
+ String getUuid();
/**
* The Metric's key is its domain identifier.
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/metric/MetricDtoToMetric.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/metric/MetricDtoToMetric.java
index b1591256b53..d1699ff5118 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/metric/MetricDtoToMetric.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/metric/MetricDtoToMetric.java
@@ -42,7 +42,7 @@ public enum MetricDtoToMetric implements Function<MetricDto, Metric> {
}
return new MetricImpl(
- metricDto.getId(), metricDto.getKey(), metricDto.getShortName(), metricType,
+ metricDto.getUuid(), metricDto.getKey(), metricDto.getShortName(), metricType,
decimalScale,
DoubleCache.intern(metricDto.getBestValue()), metricDto.isOptimizedBestValue(),
metricDto.isDeleteHistoricalData());
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/metric/MetricImpl.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/metric/MetricImpl.java
index 4d88d3491b3..b0ec7f39517 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/metric/MetricImpl.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/metric/MetricImpl.java
@@ -34,7 +34,7 @@ import static com.google.common.base.Preconditions.checkState;
@Immutable
public final class MetricImpl implements Metric {
- private final int id;
+ private final String uuid;
private final String key;
private final String name;
private final MetricType type;
@@ -43,14 +43,14 @@ public final class MetricImpl implements Metric {
private final boolean bestValueOptimized;
private boolean deleteHistoricalData;
- public MetricImpl(int id, String key, String name, MetricType type) {
- this(id, key, name, type, null, null, false, false);
+ public MetricImpl(String uuid, String key, String name, MetricType type) {
+ this(uuid, key, name, type, null, null, false, false);
}
- public MetricImpl(int id, String key, String name, MetricType type, @Nullable Integer decimalScale,
+ public MetricImpl(String uuid, String key, String name, MetricType type, @Nullable Integer decimalScale,
@Nullable Double bestValue, boolean bestValueOptimized, boolean deleteHistoricalData) {
checkArgument(!bestValueOptimized || bestValue != null, "A BestValue must be specified if Metric is bestValueOptimized");
- this.id = id;
+ this.uuid = uuid;
this.key = checkNotNull(key);
this.name = checkNotNull(name);
this.type = checkNotNull(type);
@@ -65,8 +65,8 @@ public final class MetricImpl implements Metric {
}
@Override
- public int getId() {
- return id;
+ public String getUuid() {
+ return uuid;
}
@Override
@@ -126,7 +126,7 @@ public final class MetricImpl implements Metric {
@Override
public String toString() {
return toStringHelper(this)
- .add("id", id)
+ .add("uuid", uuid)
.add("key", key)
.add("name", name)
.add("type", type)
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/metric/MetricRepository.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/metric/MetricRepository.java
index c5772764981..ac10fc234d1 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/metric/MetricRepository.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/metric/MetricRepository.java
@@ -35,16 +35,16 @@ public interface MetricRepository {
Metric getByKey(String key);
/**
- * Gets the {@link Metric} with the specific id.
+ * Gets the {@link Metric} with the specific uuid.
*
- * @throws IllegalStateException if no Metric with the specified id is found
+ * @throws IllegalStateException if no Metric with the specified uuid is found
*/
- Metric getById(long id);
+ Metric getByUuid(String uuid);
/**
- * Gets the {@link Metric} with the specific id if it exists in the repository.
+ * Gets the {@link Metric} with the specific uuid if it exists in the repository.
*/
- Optional<Metric> getOptionalById(long id);
+ Optional<Metric> getOptionalByUuid(String uuid);
/**
* Get iterable of all {@link Metric}.
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/metric/MetricRepositoryImpl.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/metric/MetricRepositoryImpl.java
index adc72db9031..2330182024d 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/metric/MetricRepositoryImpl.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/metric/MetricRepositoryImpl.java
@@ -37,7 +37,7 @@ public class MetricRepositoryImpl implements MetricRepository, Startable {
@CheckForNull
private Map<String, Metric> metricsByKey;
@CheckForNull
- private Map<Long, Metric> metricsById;
+ private Map<String, Metric> metricsByUuid;
public MetricRepositoryImpl(DbClient dbClient) {
this.dbClient = dbClient;
@@ -48,7 +48,7 @@ public class MetricRepositoryImpl implements MetricRepository, Startable {
try (DbSession dbSession = dbClient.openSession(false)) {
List<MetricDto> metricList = dbClient.metricDao().selectEnabled(dbSession);
this.metricsByKey = metricList.stream().map(MetricDtoToMetric.INSTANCE).collect(Collectors.toMap(Metric::getKey, x -> x));
- this.metricsById = metricList.stream().map(MetricDtoToMetric.INSTANCE).collect(Collectors.toMap(m -> (long) m.getId(), x -> x));
+ this.metricsByUuid = metricList.stream().map(MetricDtoToMetric.INSTANCE).collect(Collectors.toMap(Metric::getUuid, x -> x));
}
}
@@ -70,16 +70,16 @@ public class MetricRepositoryImpl implements MetricRepository, Startable {
}
@Override
- public Metric getById(long id) {
- return getOptionalById(id)
- .orElseThrow(() -> new IllegalStateException(String.format("Metric with id '%s' does not exist", id)));
+ public Metric getByUuid(String uuid) {
+ return getOptionalByUuid(uuid)
+ .orElseThrow(() -> new IllegalStateException(String.format("Metric with uuid '%s' does not exist", uuid)));
}
@Override
- public Optional<Metric> getOptionalById(long id) {
+ public Optional<Metric> getOptionalByUuid(String uuid) {
verifyMetricsInitialized();
- return Optional.ofNullable(this.metricsById.get(id));
+ return Optional.ofNullable(this.metricsByUuid.get(uuid));
}
@Override
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/organization/package-info.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/organization/package-info.java
index d7e9b084775..ca7f2753dfb 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/organization/package-info.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/organization/package-info.java
@@ -18,6 +18,6 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
@ParametersAreNonnullByDefault
-package org.sonar.ce.task.organization;
+package org.sonar.ce.task.projectanalysis.organization;
import javax.annotation.ParametersAreNonnullByDefault;
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/purge/ProjectCleaner.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/purge/ProjectCleaner.java
index 4ba6e4242bf..3643f501c5a 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/purge/ProjectCleaner.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/purge/ProjectCleaner.java
@@ -20,13 +20,9 @@
package org.sonar.ce.task.projectanalysis.purge;
import java.util.Set;
-import org.sonar.api.CoreProperties;
import org.sonar.api.ce.ComputeEngineSide;
import org.sonar.api.config.Configuration;
import org.sonar.api.server.ServerSide;
-import org.sonar.api.utils.TimeUtils;
-import org.sonar.api.utils.log.Logger;
-import org.sonar.api.utils.log.Loggers;
import org.sonar.db.DbSession;
import org.sonar.db.purge.PurgeConfiguration;
import org.sonar.db.purge.PurgeDao;
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/purge/package-info.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/purge/package-info.java
index 83a3efb902a..e7ac5540212 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/purge/package-info.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/purge/package-info.java
@@ -18,6 +18,6 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
@ParametersAreNonnullByDefault
-package org.sonar.ce.task.dbcleaner;
+package org.sonar.ce.task.projectanalysis.purge;
import javax.annotation.ParametersAreNonnullByDefault;
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/qualitygate/QualityGateServiceImpl.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/qualitygate/QualityGateServiceImpl.java
index e9bb1337d5a..51135a6ec7f 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/qualitygate/QualityGateServiceImpl.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/qualitygate/QualityGateServiceImpl.java
@@ -79,7 +79,7 @@ public class QualityGateServiceImpl implements QualityGateService {
Collection<QualityGateConditionDto> dtos = dbClient.gateConditionDao().selectForQualityGate(dbSession, qualityGateDto.getId());
Iterable<Condition> conditions = dtos.stream()
- .map(input -> metricRepository.getOptionalById(input.getMetricId())
+ .map(input -> metricRepository.getOptionalByUuid(input.getMetricUuid())
.map(metric -> new Condition(metric, input.getOperator(), input.getErrorThreshold()))
.orElse(null))
.filter(Objects::nonNull)
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/CustomMeasuresCopyStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/CustomMeasuresCopyStep.java
index ac0962fd017..1b48554601d 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/CustomMeasuresCopyStep.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/CustomMeasuresCopyStep.java
@@ -69,7 +69,7 @@ public class CustomMeasuresCopyStep implements ComputationStep {
private void copy(Component component, DbSession session) {
for (CustomMeasureDto dto : loadCustomMeasures(component, session)) {
- Metric metric = metricRepository.getById(dto.getMetricId());
+ Metric metric = metricRepository.getByUuid(dto.getMetricUuid());
// else metric is not found and an exception is raised
Measure measure = dtoToMeasure(dto, metric);
measureRepository.add(component, metric, measure);
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistLiveMeasuresStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistLiveMeasuresStep.java
index 277fb40f9d4..c7f8f410784 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistLiveMeasuresStep.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistLiveMeasuresStep.java
@@ -103,7 +103,7 @@ public class PersistLiveMeasuresStep implements ComputationStep {
@Override
public void visitAny(Component component) {
- List<Integer> metricIds = new ArrayList<>();
+ List<String> metricUuids = new ArrayList<>();
Map<String, Measure> measures = measureRepository.getRawMeasures(component);
List<LiveMeasureDto> dtos = new ArrayList<>();
for (Map.Entry<String, Measure> measuresByMetricKey : measures.entrySet()) {
@@ -120,7 +120,7 @@ public class PersistLiveMeasuresStep implements ComputationStep {
LiveMeasureDto lm = measureToMeasureDto.toLiveMeasureDto(m, metric, component);
dtos.add(lm);
- metricIds.add(metric.getId());
+ metricUuids.add(metric.getUuid());
}
if (supportUpsert) {
@@ -130,7 +130,7 @@ public class PersistLiveMeasuresStep implements ComputationStep {
// The measures that no longer exist on the component must be deleted, for example
// when the coverage on a file goes to the "best value" 100%.
// The measures on deleted components are deleted by the step PurgeDatastoresStep
- dbClient.liveMeasureDao().deleteByComponentUuidExcludingMetricIds(dbSession, component.getUuid(), metricIds);
+ dbClient.liveMeasureDao().deleteByComponentUuidExcludingMetricUuids(dbSession, component.getUuid(), metricUuids);
} else {
dbClient.liveMeasureDao().deleteByComponent(dbSession, component.getUuid());
dtos.forEach(dto -> dbClient.liveMeasureDao().insert(dbSession, dto));
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/api/measurecomputer/MeasureComputerContextImplTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/api/measurecomputer/MeasureComputerContextImplTest.java
index 885d68fcc84..391581f1267 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/api/measurecomputer/MeasureComputerContextImplTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/api/measurecomputer/MeasureComputerContextImplTest.java
@@ -81,12 +81,12 @@ public class MeasureComputerContextImplTest {
@Rule
public MetricRepositoryRule metricRepository = new MetricRepositoryRule()
- .add(1, CoreMetrics.NCLOC)
- .add(new MetricImpl(2, INT_METRIC_KEY, "int metric", Metric.MetricType.INT))
- .add(new MetricImpl(3, DOUBLE_METRIC_KEY, "double metric", Metric.MetricType.FLOAT))
- .add(new MetricImpl(4, LONG_METRIC_KEY, "long metric", Metric.MetricType.MILLISEC))
- .add(new MetricImpl(5, STRING_METRIC_KEY, "string metric", Metric.MetricType.STRING))
- .add(new MetricImpl(6, BOOLEAN_METRIC_KEY, "boolean metric", Metric.MetricType.BOOL));
+ .add("1", CoreMetrics.NCLOC)
+ .add(new MetricImpl("2", INT_METRIC_KEY, "int metric", Metric.MetricType.INT))
+ .add(new MetricImpl("3", DOUBLE_METRIC_KEY, "double metric", Metric.MetricType.FLOAT))
+ .add(new MetricImpl("4", LONG_METRIC_KEY, "long metric", Metric.MetricType.MILLISEC))
+ .add(new MetricImpl("5", STRING_METRIC_KEY, "string metric", Metric.MetricType.STRING))
+ .add(new MetricImpl("6", BOOLEAN_METRIC_KEY, "boolean metric", Metric.MetricType.BOOL));
@Rule
public MeasureRepositoryRule measureRepository = MeasureRepositoryRule.create(treeRootHolder, metricRepository);
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/BatchMeasureToMeasureTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/BatchMeasureToMeasureTest.java
index 490784f2252..12f2854179d 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/BatchMeasureToMeasureTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/BatchMeasureToMeasureTest.java
@@ -37,12 +37,12 @@ import static org.assertj.core.api.Assertions.assertThat;
@RunWith(DataProviderRunner.class)
public class BatchMeasureToMeasureTest {
- private static final Metric SOME_INT_METRIC = new MetricImpl(42, "int", "name", Metric.MetricType.INT);
- private static final Metric SOME_LONG_METRIC = new MetricImpl(42, "long", "name", Metric.MetricType.WORK_DUR);
- private static final Metric SOME_DOUBLE_METRIC = new MetricImpl(42, "double", "name", Metric.MetricType.FLOAT);
- private static final Metric SOME_STRING_METRIC = new MetricImpl(42, "string", "name", Metric.MetricType.STRING);
- private static final Metric SOME_BOOLEAN_METRIC = new MetricImpl(42, "boolean", "name", Metric.MetricType.BOOL);
- private static final Metric SOME_LEVEL_METRIC = new MetricImpl(42, "level", "name", Metric.MetricType.LEVEL);
+ private static final Metric SOME_INT_METRIC = new MetricImpl("42", "int", "name", Metric.MetricType.INT);
+ private static final Metric SOME_LONG_METRIC = new MetricImpl("42", "long", "name", Metric.MetricType.WORK_DUR);
+ private static final Metric SOME_DOUBLE_METRIC = new MetricImpl("42", "double", "name", Metric.MetricType.FLOAT);
+ private static final Metric SOME_STRING_METRIC = new MetricImpl("42", "string", "name", Metric.MetricType.STRING);
+ private static final Metric SOME_BOOLEAN_METRIC = new MetricImpl("42", "boolean", "name", Metric.MetricType.BOOL);
+ private static final Metric SOME_LEVEL_METRIC = new MetricImpl("42", "level", "name", Metric.MetricType.LEVEL);
private static final String SOME_DATA = "some_data man!";
private static final ScannerReport.Measure EMPTY_BATCH_MEASURE = ScannerReport.Measure.newBuilder().build();
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/BestValueOptimizationTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/BestValueOptimizationTest.java
index eddc5f2bebf..b89fe5d4be5 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/BestValueOptimizationTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/BestValueOptimizationTest.java
@@ -175,7 +175,7 @@ public class BestValueOptimizationTest {
}
private static MetricImpl createMetric(Metric.MetricType metricType, double bestValue) {
- return new MetricImpl(metricType.hashCode() + (int) bestValue, "key" + metricType + bestValue, "name" + metricType + bestValue, metricType, null,
+ return new MetricImpl(metricType.name() + bestValue, "key" + metricType + bestValue, "name" + metricType + bestValue, metricType, null,
bestValue, true, false);
}
}
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/LiveMeasureDtoToMeasureTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/LiveMeasureDtoToMeasureTest.java
index d58da081c93..03597999c70 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/LiveMeasureDtoToMeasureTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/LiveMeasureDtoToMeasureTest.java
@@ -37,12 +37,12 @@ import static org.assertj.core.api.Assertions.assertThat;
@RunWith(DataProviderRunner.class)
public class LiveMeasureDtoToMeasureTest {
- private static final Metric SOME_INT_METRIC = new MetricImpl(42, "int", "name", Metric.MetricType.INT);
- private static final Metric SOME_LONG_METRIC = new MetricImpl(42, "long", "name", Metric.MetricType.WORK_DUR);
- private static final Metric SOME_DOUBLE_METRIC = new MetricImpl(42, "double", "name", Metric.MetricType.FLOAT);
- private static final Metric SOME_STRING_METRIC = new MetricImpl(42, "string", "name", Metric.MetricType.STRING);
- private static final Metric SOME_BOOLEAN_METRIC = new MetricImpl(42, "boolean", "name", Metric.MetricType.BOOL);
- private static final Metric SOME_LEVEL_METRIC = new MetricImpl(42, "level", "name", Metric.MetricType.LEVEL);
+ private static final Metric SOME_INT_METRIC = new MetricImpl("42", "int", "name", Metric.MetricType.INT);
+ private static final Metric SOME_LONG_METRIC = new MetricImpl("42", "long", "name", Metric.MetricType.WORK_DUR);
+ private static final Metric SOME_DOUBLE_METRIC = new MetricImpl("42", "double", "name", Metric.MetricType.FLOAT);
+ private static final Metric SOME_STRING_METRIC = new MetricImpl("42", "string", "name", Metric.MetricType.STRING);
+ private static final Metric SOME_BOOLEAN_METRIC = new MetricImpl("42", "boolean", "name", Metric.MetricType.BOOL);
+ private static final Metric SOME_LEVEL_METRIC = new MetricImpl("42", "level", "name", Metric.MetricType.LEVEL);
private static final String SOME_DATA = "some_data man!";
private static final String SOME_ALERT_TEXT = "some alert text_be_careFul!";
@@ -228,7 +228,7 @@ public class LiveMeasureDtoToMeasureTest {
@Test
public void toMeasure_should_not_loose_decimals_of_float_values() {
- MetricImpl metric = new MetricImpl(42, "double", "name", Metric.MetricType.FLOAT, 5, null, false, false);
+ MetricImpl metric = new MetricImpl("42", "double", "name", Metric.MetricType.FLOAT, 5, null, false, false);
LiveMeasureDto LiveMeasureDto = new LiveMeasureDto()
.setValue(0.12345);
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MapBasedRawMeasureRepositoryTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MapBasedRawMeasureRepositoryTest.java
index 4b5b4ca3ef4..ab8b04dd67d 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MapBasedRawMeasureRepositoryTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MapBasedRawMeasureRepositoryTest.java
@@ -157,7 +157,7 @@ public class MapBasedRawMeasureRepositoryTest {
@Test
public void add_accepts_NO_VALUE_as_measure_arg() {
for (Metric.MetricType metricType : Metric.MetricType.values()) {
- underTest.add(FILE_COMPONENT, new MetricImpl(1, "key" + metricType, "name" + metricType, metricType), Measure.newMeasureBuilder().createNoValue());
+ underTest.add(FILE_COMPONENT, new MetricImpl("1", "key" + metricType, "name" + metricType, metricType), Measure.newMeasureBuilder().createNoValue());
}
}
@@ -170,7 +170,7 @@ public class MapBasedRawMeasureRepositoryTest {
}
try {
- final MetricImpl metric = new MetricImpl(1, "key" + metricType, "name" + metricType, metricType);
+ final MetricImpl metric = new MetricImpl("1", "key" + metricType, "name" + metricType, metricType);
underTest.add(FILE_COMPONENT, metric, getSomeMeasureByValueType(metricType));
underTest.update(FILE_COMPONENT, metric, measure);
fail("An IllegalArgumentException should have been raised");
@@ -185,7 +185,7 @@ public class MapBasedRawMeasureRepositoryTest {
@Test
public void update_accepts_NO_VALUE_as_measure_arg() {
for (Metric.MetricType metricType : Metric.MetricType.values()) {
- MetricImpl metric = new MetricImpl(1, "key" + metricType, "name" + metricType, metricType);
+ MetricImpl metric = new MetricImpl("1", "key" + metricType, "name" + metricType, metricType);
underTest.add(FILE_COMPONENT, metric, getSomeMeasureByValueType(metricType));
underTest.update(FILE_COMPONENT, metric, Measure.newMeasureBuilder().createNoValue());
}
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureDtoToMeasureTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureDtoToMeasureTest.java
index 56df4a21555..6410bda72ec 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureDtoToMeasureTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureDtoToMeasureTest.java
@@ -37,12 +37,12 @@ import static org.assertj.core.api.Assertions.assertThat;
@RunWith(DataProviderRunner.class)
public class MeasureDtoToMeasureTest {
- private static final Metric SOME_INT_METRIC = new MetricImpl(42, "int", "name", Metric.MetricType.INT);
- private static final Metric SOME_LONG_METRIC = new MetricImpl(42, "long", "name", Metric.MetricType.WORK_DUR);
- private static final Metric SOME_DOUBLE_METRIC = new MetricImpl(42, "double", "name", Metric.MetricType.FLOAT);
- private static final Metric SOME_STRING_METRIC = new MetricImpl(42, "string", "name", Metric.MetricType.STRING);
- private static final Metric SOME_BOOLEAN_METRIC = new MetricImpl(42, "boolean", "name", Metric.MetricType.BOOL);
- private static final Metric SOME_LEVEL_METRIC = new MetricImpl(42, "level", "name", Metric.MetricType.LEVEL);
+ private static final Metric SOME_INT_METRIC = new MetricImpl("42", "int", "name", Metric.MetricType.INT);
+ private static final Metric SOME_LONG_METRIC = new MetricImpl("42", "long", "name", Metric.MetricType.WORK_DUR);
+ private static final Metric SOME_DOUBLE_METRIC = new MetricImpl("42", "double", "name", Metric.MetricType.FLOAT);
+ private static final Metric SOME_STRING_METRIC = new MetricImpl("42", "string", "name", Metric.MetricType.STRING);
+ private static final Metric SOME_BOOLEAN_METRIC = new MetricImpl("42", "boolean", "name", Metric.MetricType.BOOL);
+ private static final Metric SOME_LEVEL_METRIC = new MetricImpl("42", "level", "name", Metric.MetricType.LEVEL);
private static final String SOME_DATA = "some_data man!";
private static final String SOME_ALERT_TEXT = "some alert text_be_careFul!";
@@ -321,7 +321,7 @@ public class MeasureDtoToMeasureTest {
@Test
public void toMeasure_should_not_loose_decimals_of_float_values() {
- MetricImpl metric = new MetricImpl(42, "double", "name", Metric.MetricType.FLOAT, 5, null, false, false);
+ MetricImpl metric = new MetricImpl("42", "double", "name", Metric.MetricType.FLOAT, 5, null, false, false);
MeasureDto measureDto = new MeasureDto()
.setValue(0.12345);
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureRepositoryImplTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureRepositoryImplTest.java
index de490d77095..a43a7a4b006 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureRepositoryImplTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureRepositoryImplTest.java
@@ -148,8 +148,8 @@ public class MeasureRepositoryImplTest {
SnapshotDto oldAnalysis = dbTester.components().insertSnapshot(project, t -> t.setLast(false));
MetricDto metric1 = dbTester.measures().insertMetric(t -> t.setValueType(org.sonar.api.measures.Metric.ValueType.STRING.name()));
MetricDto metric2 = dbTester.measures().insertMetric(t -> t.setValueType(org.sonar.api.measures.Metric.ValueType.STRING.name()));
- dbClient.measureDao().insert(dbSession, createMeasureDto(metric1.getId(), FILE_COMPONENT.getUuid(), lastAnalysis.getUuid()));
- dbClient.measureDao().insert(dbSession, createMeasureDto(metric1.getId(), FILE_COMPONENT.getUuid(), oldAnalysis.getUuid()));
+ dbClient.measureDao().insert(dbSession, createMeasureDto(metric1.getUuid(), FILE_COMPONENT.getUuid(), lastAnalysis.getUuid()));
+ dbClient.measureDao().insert(dbSession, createMeasureDto(metric1.getUuid(), FILE_COMPONENT.getUuid(), oldAnalysis.getUuid()));
dbSession.commit();
// metric 1 is associated to snapshot with "last=true"
@@ -162,7 +162,7 @@ public class MeasureRepositoryImplTest {
private Metric metricOf(MetricDto metricDto) {
Metric res = mock(Metric.class);
when(res.getKey()).thenReturn(metricDto.getKey());
- when(res.getId()).thenReturn(metricDto.getId());
+ when(res.getUuid()).thenReturn(metricDto.getUuid());
when(res.getType()).thenReturn(Metric.MetricType.valueOf(metricDto.getValueType()));
return res;
}
@@ -241,7 +241,7 @@ public class MeasureRepositoryImplTest {
@Test
public void add_accepts_NO_VALUE_as_measure_arg() {
for (Metric.MetricType metricType : Metric.MetricType.values()) {
- underTest.add(FILE_COMPONENT, new MetricImpl(1, "key" + metricType, "name" + metricType, metricType), Measure.newMeasureBuilder().createNoValue());
+ underTest.add(FILE_COMPONENT, new MetricImpl("1", "key" + metricType, "name" + metricType, metricType), Measure.newMeasureBuilder().createNoValue());
}
}
@@ -254,7 +254,7 @@ public class MeasureRepositoryImplTest {
}
try {
- final MetricImpl metric = new MetricImpl(1, "key" + metricType, "name" + metricType, metricType);
+ final MetricImpl metric = new MetricImpl("1", "key" + metricType, "name" + metricType, metricType);
underTest.add(FILE_COMPONENT, metric, getSomeMeasureByValueType(metricType));
underTest.update(FILE_COMPONENT, metric, measure);
fail("An IllegalArgumentException should have been raised");
@@ -269,7 +269,7 @@ public class MeasureRepositoryImplTest {
@Test
public void update_accepts_NO_VALUE_as_measure_arg() {
for (Metric.MetricType metricType : Metric.MetricType.values()) {
- MetricImpl metric = new MetricImpl(1, "key" + metricType, "name" + metricType, metricType);
+ MetricImpl metric = new MetricImpl("1", "key" + metricType, "name" + metricType, metricType);
underTest.add(FILE_COMPONENT, metric, getSomeMeasureByValueType(metricType));
underTest.update(FILE_COMPONENT, metric, Measure.newMeasureBuilder().createNoValue());
}
@@ -405,11 +405,11 @@ public class MeasureRepositoryImplTest {
assertThat(rawMeasures.get(METRIC_KEY_2)).extracting(Measure::getStringValue).isEqualTo("some value");
}
- private static MeasureDto createMeasureDto(int metricId, String componentUuid, String analysisUuid) {
+ private static MeasureDto createMeasureDto(String metricUuid, String componentUuid, String analysisUuid) {
return new MeasureDto()
.setComponentUuid(componentUuid)
.setAnalysisUuid(analysisUuid)
.setData(SOME_DATA)
- .setMetricId(metricId);
+ .setMetricUuid(metricUuid);
}
}
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureToMeasureDtoTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureToMeasureDtoTest.java
index 0d371c70921..e843a3b8b56 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureToMeasureDtoTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureToMeasureDtoTest.java
@@ -39,16 +39,16 @@ import static org.assertj.core.api.Assertions.assertThat;
@RunWith(DataProviderRunner.class)
public class MeasureToMeasureDtoTest {
- private static final MetricImpl SOME_METRIC = new MetricImpl(42, "metric_key", "metric_name", Metric.MetricType.STRING);
+ private static final MetricImpl SOME_METRIC = new MetricImpl("42", "metric_key", "metric_name", Metric.MetricType.STRING);
private static final String SOME_DATA = "some_data";
private static final String SOME_STRING = "some_string";
private static final double SOME_VARIATIONS = 1d;
- private static final MetricImpl SOME_BOOLEAN_METRIC = new MetricImpl(1, "1", "1", Metric.MetricType.BOOL);
- private static final MetricImpl SOME_INT_METRIC = new MetricImpl(2, "2", "2", Metric.MetricType.INT);
- private static final MetricImpl SOME_LONG_METRIC = new MetricImpl(3, "3", "3", Metric.MetricType.DISTRIB);
- private static final MetricImpl SOME_DOUBLE_METRIC = new MetricImpl(4, "4", "4", Metric.MetricType.FLOAT);
- private static final MetricImpl SOME_STRING_METRIC = new MetricImpl(5, "5", "5", Metric.MetricType.STRING);
- private static final MetricImpl SOME_LEVEL_METRIC = new MetricImpl(6, "6", "6", Metric.MetricType.LEVEL);
+ private static final MetricImpl SOME_BOOLEAN_METRIC = new MetricImpl("1", "1", "1", Metric.MetricType.BOOL);
+ private static final MetricImpl SOME_INT_METRIC = new MetricImpl("2", "2", "2", Metric.MetricType.INT);
+ private static final MetricImpl SOME_LONG_METRIC = new MetricImpl("3", "3", "3", Metric.MetricType.DISTRIB);
+ private static final MetricImpl SOME_DOUBLE_METRIC = new MetricImpl("4", "4", "4", Metric.MetricType.FLOAT);
+ private static final MetricImpl SOME_STRING_METRIC = new MetricImpl("5", "5", "5", Metric.MetricType.STRING);
+ private static final MetricImpl SOME_LEVEL_METRIC = new MetricImpl("6", "6", "6", Metric.MetricType.LEVEL);
private static final String ANALYSIS_UUID = "a1";
private static final Component SOME_COMPONENT = ReportComponent.builder(Component.Type.PROJECT, 1).setUuid("uuid_1").build();
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/qualitygatedetails/QualityGateDetailsDataTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/qualitygatedetails/QualityGateDetailsDataTest.java
index 8beec66f3f4..508dff3a3cc 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/qualitygatedetails/QualityGateDetailsDataTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/qualitygatedetails/QualityGateDetailsDataTest.java
@@ -52,7 +52,7 @@ public class QualityGateDetailsDataTest {
@Test
public void verify_json_for_each_type_of_condition() {
String value = "actualValue";
- Condition condition = new Condition(new MetricImpl(1, "key1", "name1", Metric.MetricType.STRING), Condition.Operator.GREATER_THAN.getDbValue(), "errorTh");
+ Condition condition = new Condition(new MetricImpl("1", "key1", "name1", Metric.MetricType.STRING), Condition.Operator.GREATER_THAN.getDbValue(), "errorTh");
ImmutableList<EvaluatedCondition> evaluatedConditions = ImmutableList.of(
new EvaluatedCondition(condition, Measure.Level.OK, value),
new EvaluatedCondition(condition, Measure.Level.ERROR, value));
@@ -82,7 +82,7 @@ public class QualityGateDetailsDataTest {
@Test
public void verify_json_for_condition_on_leak_metric() {
String value = "actualValue";
- Condition condition = new Condition(new MetricImpl(1, "new_key1", "name1", Metric.MetricType.STRING), Condition.Operator.GREATER_THAN.getDbValue(), "errorTh");
+ Condition condition = new Condition(new MetricImpl("1", "new_key1", "name1", Metric.MetricType.STRING), Condition.Operator.GREATER_THAN.getDbValue(), "errorTh");
ImmutableList<EvaluatedCondition> evaluatedConditions = ImmutableList.of(
new EvaluatedCondition(condition, Measure.Level.OK, value),
new EvaluatedCondition(condition, Measure.Level.ERROR, value));
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/metric/MetricDtoToMetricTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/metric/MetricDtoToMetricTest.java
index 91148afc82e..a92e99a9582 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/metric/MetricDtoToMetricTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/metric/MetricDtoToMetricTest.java
@@ -41,7 +41,7 @@ public class MetricDtoToMetricTest {
MetricDto metricDto = createMetricDto(metricType);
Metric metric = underTest.apply(metricDto);
- assertThat(metric.getId()).isEqualTo(metricDto.getId());
+ assertThat(metric.getUuid()).isEqualTo(metricDto.getUuid());
assertThat(metric.getKey()).isEqualTo(metricDto.getKey());
assertThat(metric.getName()).isEqualTo(metricDto.getShortName());
assertThat(metric.getType()).isEqualTo(metricType);
@@ -59,12 +59,12 @@ public class MetricDtoToMetricTest {
@Test(expected = IllegalArgumentException.class)
public void apply_throws_IAE_if_valueType_can_not_be_parsed() {
- underTest.apply(new MetricDto().setId(1).setKey("key").setValueType("trololo"));
+ underTest.apply(new MetricDto().setUuid("1").setKey("key").setValueType("trololo"));
}
private static MetricDto createMetricDto(Metric.MetricType metricType) {
return new MetricDto()
- .setId(metricType.name().hashCode())
+ .setUuid(metricType.name())
.setKey(metricType.name() + "_key")
.setShortName(metricType.name() + "_name")
.setValueType(metricType.name())
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/metric/MetricImplTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/metric/MetricImplTest.java
index b04dbf15400..9fbc02a32cd 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/metric/MetricImplTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/metric/MetricImplTest.java
@@ -29,23 +29,23 @@ public class MetricImplTest {
@Rule
public ExpectedException expectedException = ExpectedException.none();
- private static final int SOME_ID = 42;
+ private static final String SOME_UUID = "uuid";
private static final String SOME_KEY = "key";
private static final String SOME_NAME = "name";
@Test(expected = NullPointerException.class)
public void constructor_throws_NPE_if_key_arg_is_null() {
- new MetricImpl(SOME_ID, null, SOME_NAME, Metric.MetricType.BOOL);
+ new MetricImpl(SOME_UUID, null, SOME_NAME, Metric.MetricType.BOOL);
}
@Test(expected = NullPointerException.class)
public void constructor_throws_NPE_if_name_arg_is_null() {
- new MetricImpl(SOME_ID, SOME_KEY, null, Metric.MetricType.BOOL);
+ new MetricImpl(SOME_UUID, SOME_KEY, null, Metric.MetricType.BOOL);
}
@Test(expected = NullPointerException.class)
public void constructor_throws_NPE_if_valueType_arg_is_null() {
- new MetricImpl(SOME_ID, SOME_KEY, SOME_NAME, null);
+ new MetricImpl(SOME_UUID, SOME_KEY, SOME_NAME, null);
}
@Test
@@ -53,14 +53,14 @@ public class MetricImplTest {
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("A BestValue must be specified if Metric is bestValueOptimized");
- new MetricImpl(SOME_ID, SOME_KEY, SOME_NAME, Metric.MetricType.INT, 1, null, true, false);
+ new MetricImpl(SOME_UUID, SOME_KEY, SOME_NAME, Metric.MetricType.INT, 1, null, true, false);
}
@Test
public void verify_getters() {
- MetricImpl metric = new MetricImpl(SOME_ID, SOME_KEY, SOME_NAME, Metric.MetricType.FLOAT);
+ MetricImpl metric = new MetricImpl(SOME_UUID, SOME_KEY, SOME_NAME, Metric.MetricType.FLOAT);
- assertThat(metric.getId()).isEqualTo(SOME_ID);
+ assertThat(metric.getUuid()).isEqualTo(SOME_UUID);
assertThat(metric.getKey()).isEqualTo(SOME_KEY);
assertThat(metric.getName()).isEqualTo(SOME_NAME);
assertThat(metric.getType()).isEqualTo(Metric.MetricType.FLOAT);
@@ -68,27 +68,27 @@ public class MetricImplTest {
@Test
public void equals_uses_only_key() {
- MetricImpl expected = new MetricImpl(SOME_ID, SOME_KEY, SOME_NAME, Metric.MetricType.FLOAT);
+ MetricImpl expected = new MetricImpl(SOME_UUID, SOME_KEY, SOME_NAME, Metric.MetricType.FLOAT);
- assertThat(new MetricImpl(SOME_ID, SOME_KEY, SOME_NAME, Metric.MetricType.FLOAT)).isEqualTo(expected);
- assertThat(new MetricImpl(SOME_ID, SOME_KEY, SOME_NAME, Metric.MetricType.STRING)).isEqualTo(expected);
- assertThat(new MetricImpl(SOME_ID, SOME_KEY, SOME_NAME, Metric.MetricType.STRING, null, 0d, true, true)).isEqualTo(expected);
- assertThat(new MetricImpl(SOME_ID, SOME_KEY, SOME_NAME, Metric.MetricType.STRING, null, null, false, false)).isEqualTo(expected);
- assertThat(new MetricImpl(SOME_ID, "some other key", SOME_NAME, Metric.MetricType.FLOAT)).isNotEqualTo(expected);
+ assertThat(new MetricImpl(SOME_UUID, SOME_KEY, SOME_NAME, Metric.MetricType.FLOAT)).isEqualTo(expected);
+ assertThat(new MetricImpl(SOME_UUID, SOME_KEY, SOME_NAME, Metric.MetricType.STRING)).isEqualTo(expected);
+ assertThat(new MetricImpl(SOME_UUID, SOME_KEY, SOME_NAME, Metric.MetricType.STRING, null, 0d, true, true)).isEqualTo(expected);
+ assertThat(new MetricImpl(SOME_UUID, SOME_KEY, SOME_NAME, Metric.MetricType.STRING, null, null, false, false)).isEqualTo(expected);
+ assertThat(new MetricImpl(SOME_UUID, "some other key", SOME_NAME, Metric.MetricType.FLOAT)).isNotEqualTo(expected);
}
@Test
public void hashcode_uses_only_key() {
- int expected = new MetricImpl(SOME_ID, SOME_KEY, SOME_NAME, Metric.MetricType.FLOAT).hashCode();
+ int expected = new MetricImpl(SOME_UUID, SOME_KEY, SOME_NAME, Metric.MetricType.FLOAT).hashCode();
- assertThat(new MetricImpl(SOME_ID, SOME_KEY, "some other name", Metric.MetricType.FLOAT).hashCode()).isEqualTo(expected);
- assertThat(new MetricImpl(SOME_ID, SOME_KEY, "some other name", Metric.MetricType.BOOL).hashCode()).isEqualTo(expected);
+ assertThat(new MetricImpl(SOME_UUID, SOME_KEY, "some other name", Metric.MetricType.FLOAT).hashCode()).isEqualTo(expected);
+ assertThat(new MetricImpl(SOME_UUID, SOME_KEY, "some other name", Metric.MetricType.BOOL).hashCode()).isEqualTo(expected);
}
@Test
public void all_fields_are_displayed_in_toString() {
- assertThat(new MetricImpl(SOME_ID, SOME_KEY, SOME_NAME, Metric.MetricType.FLOAT, 1, 951d, true, false).toString())
- .isEqualTo("MetricImpl{id=42, key=key, name=name, type=FLOAT, bestValue=951.0, bestValueOptimized=true, deleteHistoricalData=false}");
+ assertThat(new MetricImpl(SOME_UUID, SOME_KEY, SOME_NAME, Metric.MetricType.FLOAT, 1, 951d, true, false).toString())
+ .isEqualTo("MetricImpl{uuid=uuid, key=key, name=name, type=FLOAT, bestValue=951.0, bestValueOptimized=true, deleteHistoricalData=false}");
}
}
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/metric/MetricRepositoryImplTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/metric/MetricRepositoryImplTest.java
index d2558965afe..2664e20d12d 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/metric/MetricRepositoryImplTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/metric/MetricRepositoryImplTest.java
@@ -35,7 +35,7 @@ import static org.assertj.core.api.Assertions.assertThat;
public class MetricRepositoryImplTest {
private static final String SOME_KEY = "some_key";
- private static final long SOME_ID = 156;
+ private static final String SOME_UUID = "uuid";
@Rule
public DbTester dbTester = DbTester.create(System2.INSTANCE);
@@ -87,8 +87,8 @@ public class MetricRepositoryImplTest {
underTest.start();
- assertThat(underTest.getByKey("ncloc").getId()).isEqualTo(ncloc.getId());
- assertThat(underTest.getByKey("coverage").getId()).isEqualTo(coverage.getId());
+ assertThat(underTest.getByKey("ncloc").getUuid()).isEqualTo(ncloc.getUuid());
+ assertThat(underTest.getByKey("coverage").getUuid()).isEqualTo(coverage.getUuid());
}
@Test
@@ -96,7 +96,7 @@ public class MetricRepositoryImplTest {
expectedException.expect(IllegalStateException.class);
expectedException.expectMessage("Metric cache has not been initialized");
- underTest.getById(SOME_ID);
+ underTest.getByUuid(SOME_UUID);
}
@Test
@@ -104,9 +104,9 @@ public class MetricRepositoryImplTest {
underTest.start();
expectedException.expect(IllegalStateException.class);
- expectedException.expectMessage(String.format("Metric with id '%s' does not exist", SOME_ID));
+ expectedException.expectMessage(String.format("Metric with uuid '%s' does not exist", SOME_UUID));
- underTest.getById(SOME_ID);
+ underTest.getByUuid(SOME_UUID);
}
@Test
@@ -116,9 +116,9 @@ public class MetricRepositoryImplTest {
underTest.start();
expectedException.expect(IllegalStateException.class);
- expectedException.expectMessage(String.format("Metric with id '%s' does not exist", SOME_ID));
+ expectedException.expectMessage(String.format("Metric with uuid '%s' does not exist", SOME_UUID));
- underTest.getById(SOME_ID);
+ underTest.getByUuid(SOME_UUID);
}
@Test
@@ -128,8 +128,8 @@ public class MetricRepositoryImplTest {
underTest.start();
- assertThat(underTest.getById(ncloc.getId()).getKey()).isEqualTo("ncloc");
- assertThat(underTest.getById(coverage.getId()).getKey()).isEqualTo("coverage");
+ assertThat(underTest.getByUuid(ncloc.getUuid()).getKey()).isEqualTo("ncloc");
+ assertThat(underTest.getByUuid(coverage.getUuid()).getKey()).isEqualTo("coverage");
}
@Test
@@ -137,14 +137,14 @@ public class MetricRepositoryImplTest {
expectedException.expect(IllegalStateException.class);
expectedException.expectMessage("Metric cache has not been initialized");
- underTest.getOptionalById(SOME_ID);
+ underTest.getOptionalByUuid(SOME_UUID);
}
@Test
public void getOptionalById_returns_empty_of_Metric_does_not_exist() {
underTest.start();
- assertThat(underTest.getOptionalById(SOME_ID)).isEmpty();
+ assertThat(underTest.getOptionalByUuid(SOME_UUID)).isEmpty();
}
@Test
@@ -153,7 +153,7 @@ public class MetricRepositoryImplTest {
underTest.start();
- assertThat(underTest.getOptionalById(SOME_ID)).isEmpty();
+ assertThat(underTest.getOptionalByUuid(SOME_UUID)).isEmpty();
}
@Test
@@ -163,8 +163,8 @@ public class MetricRepositoryImplTest {
underTest.start();
- assertThat(underTest.getOptionalById(ncloc.getId()).get().getKey()).isEqualTo("ncloc");
- assertThat(underTest.getOptionalById(coverage.getId()).get().getKey()).isEqualTo("coverage");
+ assertThat(underTest.getOptionalByUuid(ncloc.getUuid()).get().getKey()).isEqualTo("ncloc");
+ assertThat(underTest.getOptionalByUuid(coverage.getUuid()).get().getKey()).isEqualTo("coverage");
}
@Test
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualitygate/ConditionEvaluatorTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualitygate/ConditionEvaluatorTest.java
index 84f358b9c58..c3d542a2efa 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualitygate/ConditionEvaluatorTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualitygate/ConditionEvaluatorTest.java
@@ -216,10 +216,10 @@ public class ConditionEvaluatorTest {
}
private static MetricImpl createMetric(MetricType metricType) {
- return new MetricImpl(1, "key", "name", metricType);
+ return new MetricImpl("1", "key", "name", metricType);
}
private static MetricImpl createNewMetric(MetricType metricType) {
- return new MetricImpl(1, "new_key", "name", metricType);
+ return new MetricImpl("1", "new_key", "name", metricType);
}
}
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualitygate/EvaluationResultTextConverterTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualitygate/EvaluationResultTextConverterTest.java
index fa22401668e..1c9fdb11e6e 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualitygate/EvaluationResultTextConverterTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualitygate/EvaluationResultTextConverterTest.java
@@ -40,8 +40,8 @@ import static org.sonar.ce.task.projectanalysis.measure.Measure.Level.ERROR;
@RunWith(DataProviderRunner.class)
public class EvaluationResultTextConverterTest {
- private static final Metric INT_METRIC = new MetricImpl(1, "key", "int_metric_name", Metric.MetricType.INT);
- private static final Metric SOME_VARIATION_METRIC = new MetricImpl(2, "new_variation_of_trololo", "variation_of_trololo_name", Metric.MetricType.INT);
+ private static final Metric INT_METRIC = new MetricImpl("1", "key", "int_metric_name", Metric.MetricType.INT);
+ private static final Metric SOME_VARIATION_METRIC = new MetricImpl("2", "new_variation_of_trololo", "variation_of_trololo_name", Metric.MetricType.INT);
private static final Condition LT_10_CONDITION = new Condition(INT_METRIC, Condition.Operator.LESS_THAN.getDbValue(), "10");
private static final EvaluationResult OK_EVALUATION_RESULT = new EvaluationResult(Measure.Level.OK, null);
private static final String ERROR_THRESHOLD = "error_threshold";
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualitygate/QualityGateServiceImplTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualitygate/QualityGateServiceImplTest.java
index 29e1fff586c..2e559ec8d95 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualitygate/QualityGateServiceImplTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualitygate/QualityGateServiceImplTest.java
@@ -45,13 +45,13 @@ public class QualityGateServiceImplTest {
private static final long SOME_ID = 123;
private static final String SOME_NAME = "some name";
private static final QualityGateDto QUALITY_GATE_DTO = new QualityGateDto().setId(SOME_ID).setName(SOME_NAME);
- private static final long METRIC_ID_1 = 951;
- private static final long METRIC_ID_2 = 753;
+ private static final String METRIC_UUID_1 = "uuid1";
+ private static final String METRIC_UUID_2 = "uuid2";
private static final Metric METRIC_1 = mock(Metric.class);
private static final Metric METRIC_2 = mock(Metric.class);
- private static final QualityGateConditionDto CONDITION_1 = new QualityGateConditionDto().setUuid("321").setMetricId(METRIC_ID_1).setOperator("LT")
+ private static final QualityGateConditionDto CONDITION_1 = new QualityGateConditionDto().setUuid("321").setMetricUuid(METRIC_UUID_1).setOperator("LT")
.setErrorThreshold("error_th");
- private static final QualityGateConditionDto CONDITION_2 = new QualityGateConditionDto().setUuid("456").setMetricId(METRIC_ID_2).setOperator("GT")
+ private static final QualityGateConditionDto CONDITION_2 = new QualityGateConditionDto().setUuid("456").setMetricUuid(METRIC_UUID_2).setOperator("GT")
.setErrorThreshold("error_th");
private QualityGateDao qualityGateDao = mock(QualityGateDao.class);
@@ -92,8 +92,8 @@ public class QualityGateServiceImplTest {
when(qualityGateDao.selectById(any(), eq(SOME_ID))).thenReturn(QUALITY_GATE_DTO);
when(qualityGateConditionDao.selectForQualityGate(any(), eq(SOME_ID))).thenReturn(ImmutableList.of(CONDITION_1, CONDITION_2));
// metrics are always supposed to be there
- when(metricRepository.getOptionalById(METRIC_ID_1)).thenReturn(Optional.of(METRIC_1));
- when(metricRepository.getOptionalById(METRIC_ID_2)).thenReturn(Optional.of(METRIC_2));
+ when(metricRepository.getOptionalByUuid(METRIC_UUID_1)).thenReturn(Optional.of(METRIC_1));
+ when(metricRepository.getOptionalByUuid(METRIC_UUID_2)).thenReturn(Optional.of(METRIC_2));
Optional<QualityGate> res = underTest.findById(SOME_ID);
@@ -110,8 +110,8 @@ public class QualityGateServiceImplTest {
when(qualityGateDao.selectById(any(), eq(SOME_ID))).thenReturn(QUALITY_GATE_DTO);
when(qualityGateConditionDao.selectForQualityGate(any(), eq(SOME_ID))).thenReturn(ImmutableList.of(CONDITION_1, CONDITION_2));
// metrics are always supposed to be there
- when(metricRepository.getOptionalById(METRIC_ID_1)).thenReturn(Optional.empty());
- when(metricRepository.getOptionalById(METRIC_ID_2)).thenReturn(Optional.of(METRIC_2));
+ when(metricRepository.getOptionalByUuid(METRIC_UUID_1)).thenReturn(Optional.empty());
+ when(metricRepository.getOptionalByUuid(METRIC_UUID_2)).thenReturn(Optional.of(METRIC_2));
Optional<QualityGate> res = underTest.findById(SOME_ID);
@@ -136,8 +136,8 @@ public class QualityGateServiceImplTest {
qGateWithOrgDto.setName(QUALITY_GATE_DTO.getName());
when(qualityGateDao.selectByOrganizationAndUuid(any(), any(), any())).thenReturn(qGateWithOrgDto);
when(qualityGateConditionDao.selectForQualityGate(any(), eq(SOME_ID))).thenReturn(ImmutableList.of(CONDITION_1, CONDITION_2));
- when(metricRepository.getOptionalById(METRIC_ID_1)).thenReturn(Optional.empty());
- when(metricRepository.getOptionalById(METRIC_ID_2)).thenReturn(Optional.of(METRIC_2));
+ when(metricRepository.getOptionalByUuid(METRIC_UUID_1)).thenReturn(Optional.empty());
+ when(metricRepository.getOptionalByUuid(METRIC_UUID_2)).thenReturn(Optional.of(METRIC_2));
QualityGate result = underTest.findDefaultQualityGate(mock(Organization.class));
@@ -161,8 +161,8 @@ public class QualityGateServiceImplTest {
qGateWithOrgDto.setName(QUALITY_GATE_DTO.getName());
when(qualityGateDao.selectByProjectUuid(any(), any())).thenReturn(qGateWithOrgDto);
when(qualityGateConditionDao.selectForQualityGate(any(), eq(SOME_ID))).thenReturn(ImmutableList.of(CONDITION_1, CONDITION_2));
- when(metricRepository.getOptionalById(METRIC_ID_1)).thenReturn(Optional.empty());
- when(metricRepository.getOptionalById(METRIC_ID_2)).thenReturn(Optional.of(METRIC_2));
+ when(metricRepository.getOptionalByUuid(METRIC_UUID_1)).thenReturn(Optional.empty());
+ when(metricRepository.getOptionalByUuid(METRIC_UUID_2)).thenReturn(Optional.of(METRIC_2));
Optional<QualityGate> result = underTest.findQualityGate(mock(Project.class));
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/CustomMeasuresCopyStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/CustomMeasuresCopyStepTest.java
index da468a57707..2945418a715 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/CustomMeasuresCopyStepTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/CustomMeasuresCopyStepTest.java
@@ -70,8 +70,8 @@ public class CustomMeasuresCopyStepTest {
private static final int SUBVIEW_REF = 101;
private static final int PROJECT_VIEW_REF = 1011;
- private static final Metric FLOAT_METRIC = new MetricImpl(10, "float_metric", "Float Metric", Metric.MetricType.FLOAT);
- private static final Metric STRING_METRIC = new MetricImpl(11, "string_metric", "String Metric", Metric.MetricType.STRING);
+ private static final Metric FLOAT_METRIC = new MetricImpl("10", "float_metric", "Float Metric", Metric.MetricType.FLOAT);
+ private static final Metric STRING_METRIC = new MetricImpl("11", "string_metric", "String Metric", Metric.MetricType.STRING);
@Rule
public DbTester dbTester = DbTester.create(System2.INSTANCE);
@@ -144,35 +144,35 @@ public class CustomMeasuresCopyStepTest {
public void test_float_metric_type() {
CustomMeasureDto dto = new CustomMeasureDto();
dto.setValue(10.0);
- assertThat(dtoToMeasure(dto, new MetricImpl(1, "m", "M", Metric.MetricType.FLOAT)).getDoubleValue()).isEqualTo(10.0);
+ assertThat(dtoToMeasure(dto, new MetricImpl("1", "m", "M", Metric.MetricType.FLOAT)).getDoubleValue()).isEqualTo(10.0);
}
@Test
public void test_int_metric_type() {
CustomMeasureDto dto = new CustomMeasureDto();
dto.setValue(10.0);
- assertThat(dtoToMeasure(dto, new MetricImpl(1, "m", "M", Metric.MetricType.INT)).getIntValue()).isEqualTo(10);
+ assertThat(dtoToMeasure(dto, new MetricImpl("1", "m", "M", Metric.MetricType.INT)).getIntValue()).isEqualTo(10);
}
@Test
public void test_long_metric_type() {
CustomMeasureDto dto = new CustomMeasureDto();
dto.setValue(10.0);
- assertThat(dtoToMeasure(dto, new MetricImpl(1, "m", "M", Metric.MetricType.WORK_DUR)).getLongValue()).isEqualTo(10);
+ assertThat(dtoToMeasure(dto, new MetricImpl("1", "m", "M", Metric.MetricType.WORK_DUR)).getLongValue()).isEqualTo(10);
}
@Test
public void test_percent_metric_type() {
CustomMeasureDto dto = new CustomMeasureDto();
dto.setValue(10.0);
- assertThat(dtoToMeasure(dto, new MetricImpl(1, "m", "M", Metric.MetricType.PERCENT)).getDoubleValue()).isEqualTo(10);
+ assertThat(dtoToMeasure(dto, new MetricImpl("1", "m", "M", Metric.MetricType.PERCENT)).getDoubleValue()).isEqualTo(10);
}
@Test
public void test_string_metric_type() {
CustomMeasureDto dto = new CustomMeasureDto();
dto.setTextValue("foo");
- assertThat(dtoToMeasure(dto, new MetricImpl(1, "m", "M", Metric.MetricType.STRING)).getStringValue()).isEqualTo("foo");
+ assertThat(dtoToMeasure(dto, new MetricImpl("1", "m", "M", Metric.MetricType.STRING)).getStringValue()).isEqualTo("foo");
}
@Test
@@ -180,7 +180,7 @@ public class CustomMeasuresCopyStepTest {
CustomMeasureDto dto = new CustomMeasureDto();
dto.setTextValue(null);
- Measure measure = dtoToMeasure(dto, new MetricImpl(1, "m", "M", Metric.MetricType.STRING));
+ Measure measure = dtoToMeasure(dto, new MetricImpl("1", "m", "M", Metric.MetricType.STRING));
assertThat(measure.getValueType()).isEqualTo(Measure.ValueType.NO_VALUE);
}
@@ -189,7 +189,7 @@ public class CustomMeasuresCopyStepTest {
CustomMeasureDto dto = new CustomMeasureDto();
dto.setTextValue(null);
- Measure measure = dtoToMeasure(dto, new MetricImpl(1, "m", "M", Metric.MetricType.DATA));
+ Measure measure = dtoToMeasure(dto, new MetricImpl("1", "m", "M", Metric.MetricType.DATA));
assertThat(measure.getValueType()).isEqualTo(Measure.ValueType.NO_VALUE);
}
@@ -198,7 +198,7 @@ public class CustomMeasuresCopyStepTest {
CustomMeasureDto dto = new CustomMeasureDto();
dto.setTextValue(null);
- Measure measure = dtoToMeasure(dto, new MetricImpl(1, "m", "M", Metric.MetricType.DISTRIB));
+ Measure measure = dtoToMeasure(dto, new MetricImpl("1", "m", "M", Metric.MetricType.DISTRIB));
assertThat(measure.getValueType()).isEqualTo(Measure.ValueType.NO_VALUE);
}
@@ -206,12 +206,12 @@ public class CustomMeasuresCopyStepTest {
public void test_LEVEL_metric_type() {
CustomMeasureDto dto = new CustomMeasureDto();
dto.setTextValue("OK");
- assertThat(dtoToMeasure(dto, new MetricImpl(1, "m", "M", Metric.MetricType.LEVEL)).getLevelValue()).isEqualTo(Measure.Level.OK);
+ assertThat(dtoToMeasure(dto, new MetricImpl("1", "m", "M", Metric.MetricType.LEVEL)).getLevelValue()).isEqualTo(Measure.Level.OK);
}
@Test
public void test_boolean_metric_type() {
- MetricImpl booleanMetric = new MetricImpl(1, "m", "M", Metric.MetricType.BOOL);
+ MetricImpl booleanMetric = new MetricImpl("1", "m", "M", Metric.MetricType.BOOL);
CustomMeasureDto dto = new CustomMeasureDto();
assertThat(dtoToMeasure(dto.setValue(1.0), booleanMetric).getBooleanValue()).isTrue();
assertThat(dtoToMeasure(dto.setValue(0.0), booleanMetric).getBooleanValue()).isFalse();
@@ -232,7 +232,7 @@ public class CustomMeasuresCopyStepTest {
private void insertCustomMeasure(String componentUuid, Metric metric, double value) {
dbTester.getDbClient().customMeasureDao().insert(dbTester.getSession(), CustomMeasureTesting.newCustomMeasureDto()
.setComponentUuid(componentUuid)
- .setMetricId(metric.getId())
+ .setMetricUuid(metric.getUuid())
.setValue(value));
dbTester.getSession().commit();
}
@@ -240,7 +240,7 @@ public class CustomMeasuresCopyStepTest {
private void insertCustomMeasure(String componentUuid, Metric metric, String value) {
dbTester.getDbClient().customMeasureDao().insert(dbTester.getSession(), CustomMeasureTesting.newCustomMeasureDto()
.setComponentUuid(componentUuid)
- .setMetricId(metric.getId())
+ .setMetricUuid(metric.getUuid())
.setTextValue(value));
dbTester.getSession().commit();
}
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ExecuteVisitorsStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ExecuteVisitorsStepTest.java
index f4affe8eaf0..343008874ad 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ExecuteVisitorsStepTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ExecuteVisitorsStepTest.java
@@ -62,8 +62,8 @@ public class ExecuteVisitorsStepTest {
public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule();
@Rule
public MetricRepositoryRule metricRepository = new MetricRepositoryRule()
- .add(1, NCLOC)
- .add(new MetricImpl(2, TEST_METRIC_KEY, "name", Metric.MetricType.INT));
+ .add("1", NCLOC)
+ .add(new MetricImpl("2", TEST_METRIC_KEY, "name", Metric.MetricType.INT));
@Rule
public MeasureRepositoryRule measureRepository = MeasureRepositoryRule.create(treeRootHolder, metricRepository);
@Rule
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/LoadQualityGateStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/LoadQualityGateStepTest.java
index 8e1723ca81f..56ccfae2e96 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/LoadQualityGateStepTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/LoadQualityGateStepTest.java
@@ -61,8 +61,8 @@ public class LoadQualityGateStepTest {
@Test
public void filter_conditions_on_pull_request() {
- Metric newMetric = new MetricImpl(1, "new_key", "name", Metric.MetricType.INT);
- Metric metric = new MetricImpl(2, "key", "name", Metric.MetricType.INT);
+ Metric newMetric = new MetricImpl("1", "new_key", "name", Metric.MetricType.INT);
+ Metric metric = new MetricImpl("2", "key", "name", Metric.MetricType.INT);
Condition variation = new Condition(newMetric, Condition.Operator.GREATER_THAN.getDbValue(), "1.0");
Condition condition = new Condition(metric, Condition.Operator.GREATER_THAN.getDbValue(), "1.0");
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistDuplicationDataStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistDuplicationDataStepTest.java
index 6beeacc4581..a5c16b02745 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistDuplicationDataStepTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistDuplicationDataStepTest.java
@@ -85,7 +85,7 @@ public class PersistDuplicationDataStepTest extends BaseStepTest {
insertComponent(FILE_1_KEY, FILE_1_UUID);
insertComponent(FILE_2_KEY, FILE_2_UUID);
db.commit();
- metricRepository.add(metric.getId(), new Metric.Builder(DUPLICATIONS_DATA_KEY, DUPLICATIONS_DATA_KEY, Metric.ValueType.STRING).create());
+ metricRepository.add(metric.getUuid(), new Metric.Builder(DUPLICATIONS_DATA_KEY, DUPLICATIONS_DATA_KEY, Metric.ValueType.STRING).create());
}
@Override
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistLiveMeasuresStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistLiveMeasuresStepTest.java
index 9a6c5d8bca7..1a4d2716938 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistLiveMeasuresStepTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistLiveMeasuresStepTest.java
@@ -86,9 +86,9 @@ public class PersistLiveMeasuresStepTest extends BaseStepTest {
MetricDto intMetricDto = db.measures().insertMetric(m -> m.setKey(INT_METRIC.getKey()).setValueType(Metric.ValueType.INT.name()));
MetricDto bestValueMMetricDto = db.measures()
.insertMetric(m -> m.setKey(METRIC_WITH_BEST_VALUE.getKey()).setValueType(Metric.ValueType.INT.name()).setOptimizedBestValue(true).setBestValue(0.0));
- metricRepository.add(stringMetricDto.getId(), STRING_METRIC);
- metricRepository.add(intMetricDto.getId(), INT_METRIC);
- metricRepository.add(bestValueMMetricDto.getId(), METRIC_WITH_BEST_VALUE);
+ metricRepository.add(stringMetricDto.getUuid(), STRING_METRIC);
+ metricRepository.add(intMetricDto.getUuid(), INT_METRIC);
+ metricRepository.add(bestValueMMetricDto.getUuid(), METRIC_WITH_BEST_VALUE);
}
@Test
@@ -204,14 +204,14 @@ public class PersistLiveMeasuresStepTest extends BaseStepTest {
LiveMeasureDto measure = newLiveMeasure()
.setComponentUuid(componentUuid)
.setProjectUuid(projectUuid)
- .setMetricId(metricRepository.getByKey(metric.getKey()).getId());
+ .setMetricUuid(metricRepository.getByKey(metric.getKey()).getUuid());
dbClient.liveMeasureDao().insertOrUpdate(db.getSession(), measure);
return measure;
}
private void assertThatMeasureHasValue(LiveMeasureDto template, int expectedValue) {
Optional<LiveMeasureDto> persisted = dbClient.liveMeasureDao().selectMeasure(db.getSession(),
- template.getComponentUuid(), metricRepository.getById(template.getMetricId()).getKey());
+ template.getComponentUuid(), metricRepository.getByUuid(template.getMetricUuid()).getKey());
assertThat(persisted).isPresent();
assertThat(persisted.get().getValue()).isEqualTo((double) expectedValue);
}
@@ -225,7 +225,7 @@ public class PersistLiveMeasuresStepTest extends BaseStepTest {
private void assertThatMeasureDoesNotExist(LiveMeasureDto template) {
assertThat(dbClient.liveMeasureDao().selectMeasure(db.getSession(),
- template.getComponentUuid(), metricRepository.getById(template.getMetricId()).getKey()))
+ template.getComponentUuid(), metricRepository.getByUuid(template.getMetricUuid()).getKey()))
.isEmpty();
}
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistMeasuresStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistMeasuresStepTest.java
index 58a9f094078..9ffa01abcad 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistMeasuresStepTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistMeasuresStepTest.java
@@ -82,9 +82,9 @@ public class PersistMeasuresStepTest extends BaseStepTest {
MetricDto stringMetricDto = db.measures().insertMetric(m -> m.setKey(STRING_METRIC.getKey()).setValueType(Metric.ValueType.STRING.name()));
MetricDto intMetricDto = db.measures().insertMetric(m -> m.setKey(INT_METRIC.getKey()).setValueType(Metric.ValueType.INT.name()));
MetricDto nhMetricDto = db.measures().insertMetric(m -> m.setKey(NON_HISTORICAL_METRIC.getKey()).setValueType(Metric.ValueType.INT.name()));
- metricRepository.add(stringMetricDto.getId(), STRING_METRIC);
- metricRepository.add(intMetricDto.getId(), INT_METRIC);
- metricRepository.add(nhMetricDto.getId(), NON_HISTORICAL_METRIC);
+ metricRepository.add(stringMetricDto.getUuid(), STRING_METRIC);
+ metricRepository.add(intMetricDto.getUuid(), INT_METRIC);
+ metricRepository.add(nhMetricDto.getUuid(), NON_HISTORICAL_METRIC);
}
@Test
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/QualityGateMeasuresStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/QualityGateMeasuresStepTest.java
index 8657135ce4c..2a4f77aec44 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/QualityGateMeasuresStepTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/QualityGateMeasuresStepTest.java
@@ -286,7 +286,7 @@ public class QualityGateMeasuresStepTest {
}
private static MetricImpl createIntMetric(int index) {
- return new MetricImpl(index, "metricKey" + index, "metricName" + index, Metric.MetricType.INT);
+ return new MetricImpl("uuid" + index, "metricKey" + index, "metricName" + index, Metric.MetricType.INT);
}
private static class QualityGateStatusHolderAssertions extends AbstractAssert<QualityGateStatusHolderAssertions, QualityGateStatusHolder> {
diff --git a/server/sonar-ce-task-projectanalysis/src/testFixtures/java/org/sonar/ce/task/projectanalysis/metric/MetricRepositoryRule.java b/server/sonar-ce-task-projectanalysis/src/testFixtures/java/org/sonar/ce/task/projectanalysis/metric/MetricRepositoryRule.java
index 151eb479c8f..6fa8c22b912 100644
--- a/server/sonar-ce-task-projectanalysis/src/testFixtures/java/org/sonar/ce/task/projectanalysis/metric/MetricRepositoryRule.java
+++ b/server/sonar-ce-task-projectanalysis/src/testFixtures/java/org/sonar/ce/task/projectanalysis/metric/MetricRepositoryRule.java
@@ -30,14 +30,14 @@ import static java.util.Objects.requireNonNull;
public class MetricRepositoryRule extends ExternalResource implements MetricRepository {
private final Map<String, Metric> metricsByKey = new HashMap<>();
- private final Map<Long, Metric> metricsById = new HashMap<>();
+ private final Map<String, Metric> metricsByUuid = new HashMap<>();
/**
* Convenience method to add a {@link Metric} to the repository created from a {@link org.sonar.api.measures.Metric},
* most of the time it will be a constant of the {@link org.sonar.api.measures.CoreMetrics} class.
* <p>
* For the id of the created metric, this method uses the hashCode of the metric's key. If you want to specify
- * the id of the create {@link Metric}, use {@link #add(int, org.sonar.api.measures.Metric)}
+ * the id of the create {@link Metric}, use {@link #add(String, org.sonar.api.measures.Metric)}
* </p>
*/
public MetricRepositoryRule add(org.sonar.api.measures.Metric<?> coreMetric) {
@@ -50,18 +50,18 @@ public class MetricRepositoryRule extends ExternalResource implements MetricRepo
* and with the specified id, most of the time it will be a constant of the {@link org.sonar.api.measures.CoreMetrics}
* class.
*/
- public MetricRepositoryRule add(int id, org.sonar.api.measures.Metric<?> coreMetric) {
- add(from(id, coreMetric));
+ public MetricRepositoryRule add(String uuid, org.sonar.api.measures.Metric<?> coreMetric) {
+ add(from(uuid, coreMetric));
return this;
}
private static Metric from(org.sonar.api.measures.Metric<?> coreMetric) {
- return from(coreMetric.getKey().hashCode(), coreMetric);
+ return from(Long.toString(coreMetric.getKey().hashCode()), coreMetric);
}
- private static Metric from(int id, org.sonar.api.measures.Metric<?> coreMetric) {
+ private static Metric from(String uuid, org.sonar.api.measures.Metric<?> coreMetric) {
return new MetricImpl(
- id, coreMetric.getKey(), coreMetric.getName(),
+ uuid, coreMetric.getKey(), coreMetric.getName(),
convert(coreMetric.getType()),
coreMetric.getDecimalScale(),
coreMetric.getBestValue(), coreMetric.isOptimizedBestValue(), coreMetric.getDeleteHistoricalData());
@@ -75,18 +75,18 @@ public class MetricRepositoryRule extends ExternalResource implements MetricRepo
requireNonNull(metric.getKey(), "key can not be null");
checkState(!metricsByKey.containsKey(metric.getKey()), format("Repository already contains a metric for key %s", metric.getKey()));
- checkState(!metricsById.containsKey((long) metric.getId()), format("Repository already contains a metric for id %s", metric.getId()));
+ checkState(!metricsByUuid.containsKey(metric.getUuid()), format("Repository already contains a metric for id %s", metric.getUuid()));
metricsByKey.put(metric.getKey(), metric);
- metricsById.put((long) metric.getId(), metric);
+ metricsByUuid.put(metric.getUuid(), metric);
return this;
}
@Override
protected void after() {
- this.metricsById.clear();
- this.metricsById.clear();
+ this.metricsByUuid.clear();
+ this.metricsByUuid.clear();
}
@Override
@@ -97,15 +97,15 @@ public class MetricRepositoryRule extends ExternalResource implements MetricRepo
}
@Override
- public Metric getById(long id) {
- Metric res = metricsById.get(id);
- checkState(res != null, format("No Metric can be found for id %s", id));
+ public Metric getByUuid(String uuid) {
+ Metric res = metricsByUuid.get(uuid);
+ checkState(res != null, format("No Metric can be found for uuid %s", uuid));
return res;
}
@Override
- public Optional<Metric> getOptionalById(long id) {
- return Optional.of(metricsById.get(id));
+ public Optional<Metric> getOptionalByUuid(String uuid) {
+ return Optional.of(metricsByUuid.get(uuid));
}
@Override
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/LiveMeasureComparator.java b/server/sonar-db-dao/src/main/java/org/sonar/db/measure/LiveMeasureComparator.java
index 6e27c71e54f..71b33d8bf62 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/LiveMeasureComparator.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/measure/LiveMeasureComparator.java
@@ -30,6 +30,6 @@ public enum LiveMeasureComparator implements Comparator<LiveMeasureDto> {
if (componentUuidComp != 0) {
return componentUuidComp;
}
- return Integer.compare(o1.getMetricId(), o2.getMetricId());
+ return o1.getMetricUuid().compareTo(o2.getMetricUuid());
}
}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/LiveMeasureDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/measure/LiveMeasureDao.java
index a28d7f829ec..f84dce60a4f 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/LiveMeasureDao.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/measure/LiveMeasureDao.java
@@ -44,23 +44,23 @@ public class LiveMeasureDao implements Dao {
this.system2 = system2;
}
- public List<LiveMeasureDto> selectByComponentUuidsAndMetricIds(DbSession dbSession, Collection<String> largeComponentUuids, Collection<Integer> metricIds) {
- if (largeComponentUuids.isEmpty() || metricIds.isEmpty()) {
+ public List<LiveMeasureDto> selectByComponentUuidsAndMetricUuids(DbSession dbSession, Collection<String> largeComponentUuids, Collection<String> metricUuis) {
+ if (largeComponentUuids.isEmpty() || metricUuis.isEmpty()) {
return Collections.emptyList();
}
return executeLargeInputs(
largeComponentUuids,
- componentUuids -> mapper(dbSession).selectByComponentUuidsAndMetricIds(componentUuids, metricIds));
+ componentUuids -> mapper(dbSession).selectByComponentUuidsAndMetricUuids(componentUuids, metricUuis));
}
- public void scrollSelectByComponentUuidAndMetricKeys(DbSession dbSession, String componentUuid, Collection<String> metricIds,
+ public void scrollSelectByComponentUuidAndMetricKeys(DbSession dbSession, String componentUuid, Collection<String> metricKeys,
ResultHandler<LiveMeasureDto> handler) {
- if (metricIds.isEmpty()) {
+ if (metricKeys.isEmpty()) {
return;
}
- mapper(dbSession).scrollSelectByComponentUuidAndMetricKeys(componentUuid, metricIds, handler);
+ mapper(dbSession).scrollSelectByComponentUuidAndMetricKeys(componentUuid, metricKeys, handler);
}
public List<LiveMeasureDto> selectByComponentUuidsAndMetricKeys(DbSession dbSession, Collection<String> largeComponentUuids, Collection<String> metricKeys) {
@@ -134,8 +134,8 @@ public class LiveMeasureDao implements Dao {
return mapper(dbSession).upsert(dto, system2.now());
}
- public void deleteByComponentUuidExcludingMetricIds(DbSession dbSession, String componentUuid, List<Integer> excludedMetricIds) {
- mapper(dbSession).deleteByComponentUuidExcludingMetricIds(componentUuid, excludedMetricIds);
+ public void deleteByComponentUuidExcludingMetricUuids(DbSession dbSession, String componentUuid, List<String> excludedMetricUuids) {
+ mapper(dbSession).deleteByComponentUuidExcludingMetricUuids(componentUuid, excludedMetricUuids);
}
private static LiveMeasureMapper mapper(DbSession dbSession) {
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/LiveMeasureDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/measure/LiveMeasureDto.java
index e0b61db1025..87dc889c4a5 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/LiveMeasureDto.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/measure/LiveMeasureDto.java
@@ -37,7 +37,7 @@ public class LiveMeasureDto {
private String componentUuid;
private String projectUuid;
- private int metricId;
+ private String metricUuid;
@Nullable
private Double value;
@Nullable
@@ -69,12 +69,12 @@ public class LiveMeasureDto {
return this;
}
- public int getMetricId() {
- return metricId;
+ public String getMetricUuid() {
+ return metricUuid;
}
- public LiveMeasureDto setMetricId(int i) {
- this.metricId = i;
+ public LiveMeasureDto setMetricUuid(String uuid) {
+ this.metricUuid = uuid;
return this;
}
@@ -141,7 +141,7 @@ public class LiveMeasureDto {
StringBuilder sb = new StringBuilder("LiveMeasureDto{");
sb.append("componentUuid='").append(componentUuid).append('\'');
sb.append(", projectUuid='").append(projectUuid).append('\'');
- sb.append(", metricId=").append(metricId);
+ sb.append(", metricUuid=").append(metricUuid);
sb.append(", value=").append(value);
sb.append(", variation=").append(variation);
sb.append(", textValue='").append(textValue).append('\'');
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/LiveMeasureMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/measure/LiveMeasureMapper.java
index 3b26e2fdbcc..c0d88340ddd 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/LiveMeasureMapper.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/measure/LiveMeasureMapper.java
@@ -29,9 +29,9 @@ import org.sonar.db.component.KeyType;
public interface LiveMeasureMapper {
- List<LiveMeasureDto> selectByComponentUuidsAndMetricIds(
+ List<LiveMeasureDto> selectByComponentUuidsAndMetricUuids(
@Param("componentUuids") Collection<String> componentUuids,
- @Param("metricIds") Collection<Integer> metricIds);
+ @Param("metricUuids") Collection<String> metricUuids);
List<LiveMeasureDto> selectByComponentUuidsAndMetricKeys(
@Param("componentUuids") Collection<String> componentUuids,
@@ -77,9 +77,9 @@ public interface LiveMeasureMapper {
@Param("dto") LiveMeasureDto dto,
@Param("now") long now);
- void deleteByComponentUuidExcludingMetricIds(
+ void deleteByComponentUuidExcludingMetricUuids(
@Param("componentUuid") String componentUuid,
- @Param("excludedMetricIds") List<Integer> excludedMetricIds);
+ @Param("excludedMetricUuids") List<String> excludedMetricUuids);
void deleteByComponent(@Param("componentUuid") String componentUuid);
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/MeasureDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/measure/MeasureDto.java
index cd3f006f86f..9c460bbc0b3 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/MeasureDto.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/measure/MeasureDto.java
@@ -36,7 +36,7 @@ public class MeasureDto {
private String alertText;
private String componentUuid;
private String analysisUuid;
- private int metricId;
+ private String metricUuid;
public String getUuid() {
return uuid;
@@ -118,12 +118,12 @@ public class MeasureDto {
return this;
}
- public int getMetricId() {
- return metricId;
+ public String getMetricUuid() {
+ return metricUuid;
}
- public MeasureDto setMetricId(int metricId) {
- this.metricId = metricId;
+ public MeasureDto setMetricUuid(String metricUuid) {
+ this.metricUuid = metricUuid;
return this;
}
@@ -147,7 +147,7 @@ public class MeasureDto {
.add("alertText", alertText)
.add("componentUuid", componentUuid)
.add("analysisUuid", analysisUuid)
- .add("metricId", metricId)
+ .add("metricUuid", metricUuid)
.toString();
}
}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/MeasureTreeQuery.java b/server/sonar-db-dao/src/main/java/org/sonar/db/measure/MeasureTreeQuery.java
index e9bd9a254cb..1a6fda6cdce 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/MeasureTreeQuery.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/measure/MeasureTreeQuery.java
@@ -45,13 +45,13 @@ public class MeasureTreeQuery {
private final Strategy strategy;
@CheckForNull
- private final Collection<Integer> metricIds;
+ private final Collection<String> metricUuids;
private MeasureTreeQuery(Builder builder) {
this.nameOrKeyQuery = builder.nameOrKeyQuery;
this.qualifiers = builder.qualifiers == null ? null : newArrayList(builder.qualifiers);
this.strategy = requireNonNull(builder.strategy);
- this.metricIds = builder.metricIds;
+ this.metricUuids = builder.metricUuids;
}
@CheckForNull
@@ -77,8 +77,8 @@ public class MeasureTreeQuery {
}
@CheckForNull
- public Collection<Integer> getMetricIds() {
- return metricIds;
+ public Collection<String> getMetricUuids() {
+ return metricUuids;
}
public String getUuidPath(ComponentDto component) {
@@ -93,7 +93,7 @@ public class MeasureTreeQuery {
}
public boolean returnsEmpty() {
- return (metricIds != null && metricIds.isEmpty()) || (qualifiers != null && qualifiers.isEmpty());
+ return (metricUuids != null && metricUuids.isEmpty()) || (qualifiers != null && qualifiers.isEmpty());
}
public static Builder builder() {
@@ -109,7 +109,7 @@ public class MeasureTreeQuery {
private Strategy strategy;
@CheckForNull
- private Collection<Integer> metricIds;
+ private Collection<String> metricUuids;
private Builder() {
}
@@ -132,8 +132,8 @@ public class MeasureTreeQuery {
/**
* All the measures are returned if parameter is {@code null}.
*/
- public Builder setMetricIds(@Nullable Collection<Integer> metricIds) {
- this.metricIds = metricIds;
+ public Builder setMetricUuids(@Nullable Collection<String> metricUuids) {
+ this.metricUuids = metricUuids;
return this;
}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/PastMeasureDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/measure/PastMeasureDto.java
index 9ef4c4bb964..570ff3fca91 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/PastMeasureDto.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/measure/PastMeasureDto.java
@@ -26,7 +26,7 @@ import static java.util.Objects.requireNonNull;
public class PastMeasureDto {
- private int metricId;
+ private String metricUuid;
@CheckForNull
private Double value;
@@ -45,12 +45,12 @@ public class PastMeasureDto {
return value != null;
}
- public int getMetricId() {
- return metricId;
+ public String getMetricUuid() {
+ return metricUuid;
}
- PastMeasureDto setMetricId(int i) {
- this.metricId = i;
+ PastMeasureDto setMetricUuid(String i) {
+ this.metricUuid = i;
return this;
}
}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/PastMeasureQuery.java b/server/sonar-db-dao/src/main/java/org/sonar/db/measure/PastMeasureQuery.java
index 3089e1feb03..e30faebf81d 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/PastMeasureQuery.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/measure/PastMeasureQuery.java
@@ -28,14 +28,14 @@ import static java.util.Objects.requireNonNull;
public class PastMeasureQuery {
private final String componentUuid;
- private final List<Integer> metricIds;
+ private final List<String> metricUuids;
private final Long from;
private final Long to;
private final String status;
- public PastMeasureQuery(String componentUuid, List<Integer> metricIds, @Nullable Long from, @Nullable Long to) {
+ public PastMeasureQuery(String componentUuid, List<String> metricUuids, @Nullable Long from, @Nullable Long to) {
this.componentUuid = requireNonNull(componentUuid);
- this.metricIds = requireNonNull(metricIds);
+ this.metricUuids = requireNonNull(metricUuids);
this.from = from;
this.to = to;
this.status = SnapshotDto.STATUS_PROCESSED;
@@ -45,8 +45,8 @@ public class PastMeasureQuery {
return componentUuid;
}
- public List<Integer> getMetricIds() {
- return metricIds;
+ public List<String> getMetricUuids() {
+ return metricUuids;
}
@CheckForNull
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/ProjectMeasuresIndexerIterator.java b/server/sonar-db-dao/src/main/java/org/sonar/db/measure/ProjectMeasuresIndexerIterator.java
index 18daceed44b..a0a3d30d390 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/ProjectMeasuresIndexerIterator.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/measure/ProjectMeasuresIndexerIterator.java
@@ -80,7 +80,7 @@ public class ProjectMeasuresIndexerIterator extends CloseableIterator<ProjectMea
private static final String PROJECT_FILTER = " AND p.uuid=?";
private static final String SQL_MEASURES = "SELECT m.name, pm.value, pm.variation, pm.text_value FROM live_measures pm " +
- "INNER JOIN metrics m ON m.id = pm.metric_id " +
+ "INNER JOIN metrics m ON m.uuid = pm.metric_uuid " +
"WHERE pm.component_uuid = ? " +
"AND m.name IN ({metricNames}) " +
"AND (pm.value IS NOT NULL OR pm.variation IS NOT NULL OR pm.text_value IS NOT NULL) " +
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/custom/CustomMeasureDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/measure/custom/CustomMeasureDao.java
index b34ff180819..de33aa34361 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/custom/CustomMeasureDao.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/measure/custom/CustomMeasureDao.java
@@ -49,20 +49,20 @@ public class CustomMeasureDao implements Dao {
mapper(session).delete(uuid);
}
- public void deleteByMetricIds(DbSession session, List<Integer> metricIds) {
- DatabaseUtils.executeLargeInputsWithoutOutput(metricIds, input -> mapper(session).deleteByMetricIds(metricIds));
+ public void deleteByMetricUuids(DbSession session, List<String> metricUuids) {
+ DatabaseUtils.executeLargeInputsWithoutOutput(metricUuids, input -> mapper(session).deleteByMetricUuids(metricUuids));
}
public Optional<CustomMeasureDto> selectByUuid(DbSession session, String uuid) {
return ofNullable(mapper(session).selectByUuid(uuid));
}
- public List<CustomMeasureDto> selectByMetricId(DbSession session, int metricId) {
- return mapper(session).selectByMetricId(metricId);
+ public List<CustomMeasureDto> selectByMetricUuid(DbSession session, String metricUuid) {
+ return mapper(session).selectByMetricUuid(metricUuid);
}
- public int countByComponentIdAndMetricId(DbSession session, String componentUuid, int metricId) {
- return mapper(session).countByComponentIdAndMetricId(componentUuid, metricId);
+ public int countByComponentIdAndMetricUuid(DbSession session, String componentUuid, String metricUuid) {
+ return mapper(session).countByComponentIdAndMetricUuid(componentUuid, metricUuid);
}
public List<CustomMeasureDto> selectByComponentUuid(DbSession session, String componentUuid, int offset, int limit) {
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/custom/CustomMeasureDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/measure/custom/CustomMeasureDto.java
index b989a60ace4..da5c5643ac2 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/custom/CustomMeasureDto.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/measure/custom/CustomMeasureDto.java
@@ -24,7 +24,7 @@ import javax.annotation.Nullable;
public class CustomMeasureDto {
private String uuid = null;
- private int metricId = 0;
+ private String metricUuid = null;
private String componentUuid = null;
private double value = 0.0D;
private String textValue = null;
@@ -37,8 +37,9 @@ public class CustomMeasureDto {
return uuid;
}
- public void setUuid(String uuid) {
+ public CustomMeasureDto setUuid(String uuid) {
this.uuid = uuid;
+ return this;
}
@CheckForNull
@@ -79,12 +80,12 @@ public class CustomMeasureDto {
return this;
}
- public int getMetricId() {
- return metricId;
+ public String getMetricUuid() {
+ return metricUuid;
}
- public CustomMeasureDto setMetricId(int metricId) {
- this.metricId = metricId;
+ public CustomMeasureDto setMetricUuid(String metricUuid) {
+ this.metricUuid = metricUuid;
return this;
}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/custom/CustomMeasureMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/measure/custom/CustomMeasureMapper.java
index f78faa88439..8081a413fae 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/custom/CustomMeasureMapper.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/measure/custom/CustomMeasureMapper.java
@@ -30,11 +30,11 @@ public interface CustomMeasureMapper {
void delete(String uuid);
- void deleteByMetricIds(@Param("metricIds") List<Integer> metricIds);
+ void deleteByMetricUuids(@Param("metricUuids") List<String> metricUuids);
CustomMeasureDto selectByUuid(String uuid);
- List<CustomMeasureDto> selectByMetricId(int id);
+ List<CustomMeasureDto> selectByMetricUuid(String uuid);
List<CustomMeasureDto> selectByComponentUuid(String s);
@@ -44,5 +44,5 @@ public interface CustomMeasureMapper {
int countByComponentUuid(String componentUuid);
- int countByComponentIdAndMetricId(@Param("componentUuid") String componentUuid, @Param("metricId") int metricId);
+ int countByComponentIdAndMetricUuid(@Param("componentUuid") String componentUuid, @Param("metricUuid") String metricUuid);
}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/metric/MetricDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/metric/MetricDao.java
index 9d021c02098..da78e49ff14 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/metric/MetricDao.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/metric/MetricDao.java
@@ -106,8 +106,8 @@ public class MetricDao implements Dao {
return mapper(session).selectAvailableCustomMetricsByComponentUuid(projectUuid);
}
- public List<MetricDto> selectByIds(DbSession session, Set<Integer> idsSet) {
- return executeLargeInputs(new ArrayList<>(idsSet), mapper(session)::selectByIds);
+ public List<MetricDto> selectByUuids(DbSession session, Set<String> uuidsSet) {
+ return executeLargeInputs(new ArrayList<>(uuidsSet), mapper(session)::selectByUuids);
}
private static class NotEmptyPredicate implements Predicate<String> {
@@ -122,8 +122,8 @@ public class MetricDao implements Dao {
return session.getMapper(MetricMapper.class);
}
- public void disableCustomByIds(final DbSession session, List<Integer> ids) {
- executeLargeInputsWithoutOutput(ids, input -> mapper(session).disableByIds(input));
+ public void disableCustomByUuids(final DbSession session, List<String> uuids) {
+ executeLargeInputsWithoutOutput(uuids, input -> mapper(session).disableByUuids(input));
}
/**
@@ -139,8 +139,8 @@ public class MetricDao implements Dao {
}
@CheckForNull
- public MetricDto selectById(DbSession session, long id) {
- return mapper(session).selectById(id);
+ public MetricDto selectByUuid(DbSession session, String uuid) {
+ return mapper(session).selectByUuid(uuid);
}
}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/metric/MetricDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/metric/MetricDto.java
index a211bd5098d..27cfe59c42a 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/metric/MetricDto.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/metric/MetricDto.java
@@ -29,7 +29,7 @@ import static org.sonar.db.metric.MetricValidator.checkMetricName;
public class MetricDto {
- private Integer id;
+ private String uuid;
private String kee;
@@ -61,12 +61,12 @@ public class MetricDto {
private Integer decimalScale;
- public Integer getId() {
- return id;
+ public String getUuid() {
+ return uuid;
}
- public MetricDto setId(Integer id) {
- this.id = id;
+ public MetricDto setUuid(String uuid) {
+ this.uuid = uuid;
return this;
}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/metric/MetricMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/metric/MetricMapper.java
index 6ef14a6cd65..c9656af8c16 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/metric/MetricMapper.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/metric/MetricMapper.java
@@ -27,9 +27,9 @@ import org.apache.ibatis.session.RowBounds;
public interface MetricMapper {
- MetricDto selectById(long id);
+ MetricDto selectByUuid(String uuid);
- List<MetricDto> selectByIds(@Param("ids") List<Integer> ids);
+ List<MetricDto> selectByUuids(@Param("uuids") List<String> uuids);
MetricDto selectByKey(@Param("key") String key);
@@ -45,7 +45,7 @@ public interface MetricMapper {
List<String> selectDomains();
- void disableByIds(@Param("ids") List<Integer> ids);
+ void disableByUuids(@Param("uuids") List<String> uuids);
int disableByKey(@Param("key") String key);
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateConditionDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateConditionDto.java
index b21fcc53532..ed191d46639 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateConditionDto.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateConditionDto.java
@@ -35,7 +35,7 @@ public class QualityGateConditionDto {
private long qualityGateId;
- private long metricId;
+ private String metricUuid;
private String metricKey;
@@ -65,12 +65,12 @@ public class QualityGateConditionDto {
return this;
}
- public long getMetricId() {
- return metricId;
+ public String getMetricUuid() {
+ return metricUuid;
}
- public QualityGateConditionDto setMetricId(long metricId) {
- this.metricId = metricId;
+ public QualityGateConditionDto setMetricUuid(String metricUuid) {
+ this.metricUuid = metricUuid;
return this;
}
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml
index ebaec604d12..5e69f21aec5 100644
--- a/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml
+++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml
@@ -732,7 +732,7 @@
<select id="selectPrivateProjectsWithNcloc" resultType="org.sonar.db.component.ProjectNclocDistributionDto">
select p.kee as kee, p.name as name, max(lm.value) as ncloc
from live_measures lm
- inner join metrics m on m.id = lm.metric_id
+ inner join metrics m on m.uuid = lm.metric_uuid
inner join project_branches b on b.uuid = lm.component_uuid
inner join components p on b.project_uuid = p.uuid
where
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/measure/LiveMeasureMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/measure/LiveMeasureMapper.xml
index cbc469e82db..33da39db11c 100644
--- a/server/sonar-db-dao/src/main/resources/org/sonar/db/measure/LiveMeasureMapper.xml
+++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/measure/LiveMeasureMapper.xml
@@ -6,17 +6,17 @@
<sql id="columns">
lm.component_uuid as componentUuid,
lm.project_uuid as projectUuid,
- lm.metric_id as metricId,
+ lm.metric_uuid as metricUuid,
lm.value as value,
lm.text_value as textValue,
lm.measure_data as data,
lm.variation as variation
</sql>
- <select id="selectByComponentUuidsAndMetricIds" parameterType="map" resultType="org.sonar.db.measure.LiveMeasureDto">
+ <select id="selectByComponentUuidsAndMetricUuids" parameterType="map" resultType="org.sonar.db.measure.LiveMeasureDto">
select <include refid="columns"/> from live_measures lm
where
- lm.metric_id in <foreach item="metricId" collection="metricIds" open="(" separator="," close=")">#{metricId, jdbcType=INTEGER}</foreach>
+ lm.metric_uuid in <foreach item="metricUuid" collection="metricUuids" open="(" separator="," close=")">#{metricUuid, jdbcType=VARCHAR}</foreach>
and lm.component_uuid in
<foreach item="componentUuid" collection="componentUuids" open="(" separator="," close=")">
#{componentUuid, jdbcType=VARCHAR}
@@ -25,7 +25,7 @@
<select id="selectByComponentUuidsAndMetricKeys" parameterType="map" resultType="org.sonar.db.measure.LiveMeasureDto">
select <include refid="columns"/> from live_measures lm
- inner join metrics m on m.id = lm.metric_id
+ inner join metrics m on m.uuid = lm.metric_uuid
where
m.name in <foreach item="metricKey" collection="metricKeys" open="(" separator="," close=")">#{metricKey, jdbcType=VARCHAR}</foreach>
and lm.component_uuid in
@@ -36,7 +36,7 @@
<select id="selectByComponentUuidAndMetricKeys" parameterType="map" resultType="org.sonar.db.measure.LiveMeasureDto">
select <include refid="columns"/> from live_measures lm
- inner join metrics m on m.id = lm.metric_id
+ inner join metrics m on m.uuid = lm.metric_uuid
where
m.name in <foreach item="metricKey" collection="metricKeys" open="(" separator="," close=")">#{metricKey, jdbcType=VARCHAR}</foreach>
and lm.component_uuid = #{componentUuid, jdbcType=VARCHAR}
@@ -44,7 +44,7 @@
<select id="selectByComponentUuidAndMetricKey" parameterType="map" resultType="org.sonar.db.measure.LiveMeasureDto">
select <include refid="columns"/> from live_measures lm
- inner join metrics m on m.id = lm.metric_id
+ inner join metrics m on m.uuid = lm.metric_uuid
where
m.name = #{metricKey, jdbcType=VARCHAR}
and lm.component_uuid = #{componentUuid, jdbcType=VARCHAR}
@@ -54,7 +54,7 @@
select sum(sumncloc.maxncloc) from (
select b.project_uuid as projectUuid, max(lm.value) as maxncloc
from live_measures lm
- inner join metrics m on m.id = lm.metric_id
+ inner join metrics m on m.uuid = lm.metric_uuid
inner join components p on p.uuid = lm.component_uuid
inner join project_branches b on b.uuid = p.uuid
<where>
@@ -82,7 +82,7 @@
uuid,
component_uuid,
project_uuid,
- metric_id,
+ metric_uuid,
value,
text_value,
variation,
@@ -93,7 +93,7 @@
#{uuid, jdbcType=VARCHAR},
#{dto.componentUuid, jdbcType=VARCHAR},
#{dto.projectUuid, jdbcType=VARCHAR},
- #{dto.metricId, jdbcType=INTEGER},
+ #{dto.metricUuid, jdbcType=VARCHAR},
#{dto.value, jdbcType=DOUBLE},
#{dto.textValue, jdbcType=VARCHAR},
#{dto.variation, jdbcType=DOUBLE},
@@ -112,7 +112,7 @@
updated_at = #{now, jdbcType=BIGINT}
where
component_uuid = #{dto.componentUuid, jdbcType=VARCHAR}
- and metric_id = #{dto.metricId, jdbcType=INTEGER}
+ and metric_uuid = #{dto.metricUuid, jdbcType=VARCHAR}
</update>
<delete id="deleteByComponent" parameterType="map">
@@ -126,7 +126,7 @@
uuid,
component_uuid,
project_uuid,
- metric_id,
+ metric_uuid,
value,
text_value,
variation,
@@ -137,7 +137,7 @@
#{dto.uuidForUpsert, jdbcType=VARCHAR},
#{dto.componentUuid, jdbcType=VARCHAR},
#{dto.projectUuid, jdbcType=VARCHAR},
- #{dto.metricId, jdbcType=INTEGER},
+ #{dto.metricUuid, jdbcType=VARCHAR},
#{dto.value, jdbcType=DOUBLE},
#{dto.textValue, jdbcType=VARCHAR},
#{dto.variation, jdbcType=DOUBLE},
@@ -145,7 +145,7 @@
#{now, jdbcType=BIGINT},
#{now, jdbcType=BIGINT}
)
- on conflict(component_uuid, metric_id) do update set
+ on conflict(component_uuid, metric_uuid) do update set
value = excluded.value,
variation = excluded.variation,
text_value = excluded.text_value,
@@ -158,23 +158,23 @@
live_measures.measure_data is distinct from excluded.measure_data
</update>
- <delete id="deleteByComponentUuidExcludingMetricIds" parameterType="map">
- <include refid="sql_deleteByComponentUuidExcludingMetricIds"/>
+ <delete id="deleteByComponentUuidExcludingMetricUuids" parameterType="map">
+ <include refid="sql_deleteByComponentUuidExcludingMetricUuids"/>
</delete>
- <sql id="sql_deleteByComponentUuidExcludingMetricIds">
+ <sql id="sql_deleteByComponentUuidExcludingMetricUuids">
delete from live_measures
where
component_uuid = #{componentUuid, jdbcType=VARCHAR}
- <if test="!excludedMetricIds.isEmpty()">
- and metric_id not in <foreach collection="excludedMetricIds" item="metricId" open="(" close=")" separator=",">#{metricId,jdbcType=INTEGER}</foreach>
+ <if test="!excludedMetricUuids.isEmpty()">
+ and metric_uuid not in <foreach collection="excludedMetricUuids" item="metricUuid" open="(" close=")" separator=",">#{metricUuid,jdbcType=VARCHAR}</foreach>
</if>
</sql>
<select id="scrollSelectByComponentUuidAndMetricKeys" resultType="org.sonar.db.measure.LiveMeasureDto" fetchSize="${_scrollFetchSize}"
resultSetType="FORWARD_ONLY">
select <include refid="columns"/> from live_measures lm
- inner join metrics m on m.id = lm.metric_id
+ inner join metrics m on m.uuid = lm.metric_uuid
where
m.name in <foreach item="metricKey" collection="metricKeys" open="(" separator="," close=")">#{metricKey, jdbcType=VARCHAR}</foreach>
and lm.component_uuid = #{componentUuid, jdbcType=VARCHAR}
@@ -186,9 +186,9 @@
<!-- TODO do we really need another join on components ? Using lm.project_uuid should be enough -->
<include refid="org.sonar.db.component.ComponentMapper.selectDescendantsJoins"/>
<where>
- <if test="query.getMetricIds() != null">
- lm.metric_id in
- <foreach item="metricId" collection="query.getMetricIds()" open="(" separator="," close=")">#{metricId,jdbcType=INTEGER}</foreach>
+ <if test="query.getMetricUuids() != null">
+ lm.metric_uuid in
+ <foreach item="metricUuid" collection="query.getMetricUuids()" open="(" separator="," close=")">#{metricUuid,jdbcType=VARCHAR}</foreach>
</if>
and p.enabled = ${_true}
<if test="query.qualifiers != null">
@@ -211,9 +211,9 @@
select <include refid="columns"/> from live_measures lm
inner join components p on p.uuid = lm.component_uuid and lm.component_uuid = #{baseUuid, jdbcType=VARCHAR}
<where>
- <if test="query.getMetricIds() != null">
- lm.metric_id in
- <foreach item="metricId" collection="query.getMetricIds()" open="(" separator="," close=")">#{metricId,jdbcType=INTEGER}</foreach>
+ <if test="query.getMetricUuids() != null">
+ lm.metric_uuid in
+ <foreach item="metricUuid" collection="query.getMetricUuids()" open="(" separator="," close=")">#{metricUuid,jdbcType=VARCHAR}</foreach>
</if>
and p.enabled = ${_true}
<if test="query.qualifiers != null">
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/measure/MeasureMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/measure/MeasureMapper.xml
index 6eb7c3a238d..4aec1f108ad 100644
--- a/server/sonar-db-dao/src/main/resources/org/sonar/db/measure/MeasureMapper.xml
+++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/measure/MeasureMapper.xml
@@ -5,7 +5,7 @@
<sql id="measureColumns">
pm.uuid as uuid,
- pm.metric_id as metricId,
+ pm.metric_uuid as metricUuid,
pm.component_uuid as componentUuid,
pm.analysis_uuid as analysisUuid,
pm.value as value,
@@ -19,7 +19,7 @@
<select id="selectLastMeasure" parameterType="map" resultType="Measure">
select <include refid="measureColumns"/>
from project_measures pm
- inner join metrics m on m.id = pm.metric_id
+ inner join metrics m on m.uuid = pm.metric_uuid
inner join snapshots s on s.uuid = pm.analysis_uuid
where
pm.component_uuid = #{componentUuid,jdbcType=VARCHAR} and
@@ -30,7 +30,7 @@
<select id="selectMeasure" parameterType="map" resultType="Measure">
select <include refid="measureColumns"/>
from project_measures pm
- inner join metrics m on m.id = pm.metric_id
+ inner join metrics m on m.uuid = pm.metric_uuid
inner join snapshots s on s.uuid = pm.analysis_uuid
where
pm.component_uuid = #{componentUuid,jdbcType=VARCHAR} and
@@ -41,7 +41,7 @@
<sql id="selectByQueryCommonJoins">
inner join snapshots analysis on analysis.uuid = pm.analysis_uuid
<if test="query.getMetricKeys() != null">
- inner join metrics m on m.id = pm.metric_id
+ inner join metrics m on m.uuid = pm.metric_uuid
</if>
</sql>
@@ -57,7 +57,7 @@
<if test="query.to!=null">
and analysis.created_at&lt;#{query.to, jdbcType=BIGINT}
</if>
- and pm.metric_id in <foreach item="metricId" collection="query.metricIds" open="(" separator="," close=")">#{metricId, jdbcType=VARCHAR}</foreach>
+ and pm.metric_uuid in <foreach item="metricUuid" collection="query.metricUuids" open="(" separator="," close=")">#{metricUuid, jdbcType=VARCHAR}</foreach>
and analysis.status=#{query.status, jdbcType=VARCHAR}
</select>
@@ -65,7 +65,7 @@
insert into project_measures (
uuid,
value,
- metric_id,
+ metric_uuid,
component_uuid,
analysis_uuid,
text_value,
@@ -76,7 +76,7 @@
VALUES (
#{uuid, jdbcType=VARCHAR},
#{value, jdbcType=DOUBLE},
- #{metricId, jdbcType=INTEGER},
+ #{metricUuid, jdbcType=VARCHAR},
#{componentUuid, jdbcType=VARCHAR},
#{analysisUuid, jdbcType=VARCHAR},
#{textValue, jdbcType=VARCHAR},
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/measure/custom/CustomMeasureMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/measure/custom/CustomMeasureMapper.xml
index 1f57484d562..c2dc6a9be5b 100644
--- a/server/sonar-db-dao/src/main/resources/org/sonar/db/measure/custom/CustomMeasureMapper.xml
+++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/measure/custom/CustomMeasureMapper.xml
@@ -4,7 +4,7 @@
<mapper namespace="org.sonar.db.measure.custom.CustomMeasureMapper">
<sql id="selectColumns">
m.uuid,
- m.metric_id as metricId,
+ m.metric_uuid as metricUuid,
m.component_uuid as componentUuid,
m.value,
m.text_value as textValue,
@@ -21,11 +21,11 @@
where m.uuid=#{uuid}
</select>
- <select id="selectByMetricId" resultType="CustomMeasure">
+ <select id="selectByMetricUuid" resultType="CustomMeasure">
select
<include refid="selectColumns"/>
from manual_measures m
- where m.metric_id=#{metricId}
+ where m.metric_uuid=#{metricUuid}
</select>
<select id="selectByComponentUuid" resultType="CustomMeasure">
@@ -39,7 +39,7 @@
SELECT
<include refid="selectColumns"/>
FROM manual_measures m
- INNER JOIN metrics metric ON metric.id=m.metric_id AND metric.name=#{metricKey}
+ INNER JOIN metrics metric ON metric.uuid=m.metric_uuid AND metric.name=#{metricKey}
<where>
m.text_value=#{textValue}
</where>
@@ -47,11 +47,11 @@
<insert id="insert" parameterType="CustomMeasure" useGeneratedKeys="false">
INSERT INTO manual_measures (
- uuid, metric_id, component_uuid, value, text_value, user_uuid, description, created_at, updated_at
+ uuid, metric_uuid, component_uuid, value, text_value, user_uuid, description, created_at, updated_at
)
VALUES (
#{uuid, jdbcType=VARCHAR},
- #{metricId, jdbcType=INTEGER},
+ #{metricUuid, jdbcType=VARCHAR},
#{componentUuid, jdbcType=VARCHAR},
#{value, jdbcType=DOUBLE},
#{textValue, jdbcType=VARCHAR},
@@ -72,11 +72,11 @@
where uuid = #{uuid}
</update>
- <delete id="deleteByMetricIds">
+ <delete id="deleteByMetricUuids">
delete from manual_measures
- where metric_id in
- <foreach collection="metricIds" item="metricId" open="(" close=")" separator=",">
- #{metricId}
+ where metric_uuid in
+ <foreach collection="metricUuids" item="metricUuid" open="(" close=")" separator=",">
+ #{metricUuid}
</foreach>
</delete>
@@ -91,9 +91,9 @@
where m.component_uuid=#{componentUuid}
</select>
- <select id="countByComponentIdAndMetricId" resultType="Integer">
+ <select id="countByComponentIdAndMetricUuid" resultType="Integer">
select count(1)
from manual_measures m
- where m.metric_id=#{metricId} and m.component_uuid=#{componentUuid}
+ where m.metric_uuid=#{metricUuid} and m.component_uuid=#{componentUuid}
</select>
</mapper>
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/metric/MetricMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/metric/MetricMapper.xml
index 52b95a7179e..acd5b2ea81d 100644
--- a/server/sonar-db-dao/src/main/resources/org/sonar/db/metric/MetricMapper.xml
+++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/metric/MetricMapper.xml
@@ -4,7 +4,7 @@
<mapper namespace="org.sonar.db.metric.MetricMapper">
<sql id="metricColumns">
- m.id,
+ m.uuid,
m.name as kee,
m.description,
m.direction,
@@ -60,7 +60,7 @@
select
<include refid="metricColumns"/>
from metrics m
- left join manual_measures mm on mm.metric_id = m.id and mm.component_uuid=#{componentUuid}
+ left join manual_measures mm on mm.metric_uuid = m.uuid and mm.component_uuid=#{componentUuid}
where m.enabled=${_true}
and m.user_managed=${_true}
and mm.uuid is null
@@ -83,13 +83,12 @@
</where>
</select>
- <insert id="insert" parameterType="org.sonar.db.metric.MetricDto" useGeneratedKeys="true" keyColumn="id"
- keyProperty="id">
+ <insert id="insert" parameterType="org.sonar.db.metric.MetricDto" useGeneratedKeys="false">
INSERT INTO metrics (
- name, description, direction, domain, short_name, qualitative, val_type, user_managed, enabled, worst_value,
+ uuid, name, description, direction, domain, short_name, qualitative, val_type, user_managed, enabled, worst_value,
best_value, optimized_best_value, hidden, delete_historical_data, decimal_scale)
VALUES (
- #{kee, jdbcType=VARCHAR}, #{description, jdbcType=VARCHAR}, #{direction, jdbcType=INTEGER},
+ #{uuid, jdbcType=VARCHAR}, #{kee, jdbcType=VARCHAR}, #{description, jdbcType=VARCHAR}, #{direction, jdbcType=INTEGER},
#{domain, jdbcType=VARCHAR}, #{shortName, jdbcType=VARCHAR}, #{qualitative, jdbcType=BOOLEAN},
#{valueType, jdbcType=VARCHAR}, #{userManaged, jdbcType=BOOLEAN}, #{enabled, jdbcType=BOOLEAN},
#{worstValue, jdbcType=DOUBLE}, #{bestValue, jdbcType=DOUBLE},
@@ -111,7 +110,7 @@
hidden=#{hidden, jdbcType=BOOLEAN},
qualitative=#{qualitative, jdbcType=BOOLEAN},
decimal_scale=#{decimalScale, jdbcType=INTEGER}
- where id=#{id}
+ where uuid=#{uuid}
</update>
<select id="selectDomains" resultType="String">
@@ -120,14 +119,14 @@
where m.domain is not null and m.enabled=${_true}
</select>
- <update id="disableByIds">
+ <update id="disableByUuids">
update metrics
set enabled=${_false}
<where>
AND user_managed=${_true}
- AND id in
- <foreach item="id" collection="ids" open="(" separator="," close=")">
- #{id}
+ AND uuid in
+ <foreach item="uuid" collection="uuids" open="(" separator="," close=")">
+ #{uuid}
</foreach>
</where>
</update>
@@ -151,24 +150,24 @@
</where>
</select>
- <select id="selectByIds" resultType="org.sonar.db.metric.MetricDto">
+ <select id="selectByUuids" resultType="org.sonar.db.metric.MetricDto">
SELECT
<include refid="metricColumns"/>
FROM metrics m
<where>
- AND m.id in
- <foreach item="id" collection="ids" open="(" separator="," close=")">
- #{id}
+ AND m.uuid in
+ <foreach item="uuid" collection="uuids" open="(" separator="," close=")">
+ #{uuid}
</foreach>
</where>
</select>
- <select id="selectById" resultType="org.sonar.db.metric.MetricDto">
+ <select id="selectByUuid" resultType="org.sonar.db.metric.MetricDto">
SELECT
<include refid="metricColumns"/>
FROM metrics m
<where>
- AND m.id=#{id}
+ AND m.uuid=#{uuid}
</where>
</select>
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/organization/OrganizationMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/organization/OrganizationMapper.xml
index 47a12351ea4..e8bda0081ec 100644
--- a/server/sonar-db-dao/src/main/resources/org/sonar/db/organization/OrganizationMapper.xml
+++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/organization/OrganizationMapper.xml
@@ -191,7 +191,7 @@
select orgUuid, sum(sumncloc.maxncloc) as ncloc from (
select b.project_uuid, p.organization_uuid as orgUuid, max(lm.value) as maxncloc
from live_measures lm
- inner join metrics m on m.id = lm.metric_id
+ inner join metrics m on m.uuid = lm.metric_uuid
inner join components p on p.uuid = lm.component_uuid
inner join project_branches b on b.uuid = p.uuid
where
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/qualitygate/QualityGateConditionMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/qualitygate/QualityGateConditionMapper.xml
index c7b3c7099e3..9f3da11eb10 100644
--- a/server/sonar-db-dao/src/main/resources/org/sonar/db/qualitygate/QualityGateConditionMapper.xml
+++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/qualitygate/QualityGateConditionMapper.xml
@@ -4,12 +4,12 @@
<mapper namespace="org.sonar.db.qualitygate.QualityGateConditionMapper">
<insert id="insert" parameterType="QualityGateCondition">
- insert into quality_gate_conditions (uuid, qgate_id, metric_id, operator, value_error, created_at, updated_at)
- values (#{uuid}, #{qualityGateId}, #{metricId}, #{operator}, #{errorThreshold}, #{createdAt}, #{updatedAt})
+ insert into quality_gate_conditions (uuid, qgate_id, metric_uuid, operator, value_error, created_at, updated_at)
+ values (#{uuid}, #{qualityGateId}, #{metricUuid}, #{operator}, #{errorThreshold}, #{createdAt}, #{updatedAt})
</insert>
<sql id="conditionColumns">
- uuid, qgate_id as qualityGateId, metric_id as metricId, operator, value_error as errorThreshold,
+ uuid, qgate_id as qualityGateId, metric_uuid as metricUuid, operator, value_error as errorThreshold,
created_at as createdAt, updated_at as updatedAt
</sql>
@@ -32,7 +32,7 @@
<update id="update" parameterType="QualityGateCondition">
update quality_gate_conditions set
- metric_id=#{metricId},
+ metric_uuid=#{metricUuid},
operator=#{operator},
value_error=#{errorThreshold},
updated_at=#{updatedAt}
@@ -41,7 +41,7 @@
<delete id="deleteConditionsWithInvalidMetrics">
delete from quality_gate_conditions
- where not exists (select 1 from metrics m where m.enabled=${_true} and m.id = metric_id)
+ where not exists (select 1 from metrics m where m.enabled=${_true} and m.uuid = metric_uuid)
</delete>
</mapper>
diff --git a/server/sonar-db-dao/src/schema/schema-sq.ddl b/server/sonar-db-dao/src/schema/schema-sq.ddl
index bd57c4aec5d..22a331ae4ab 100644
--- a/server/sonar-db-dao/src/schema/schema-sq.ddl
+++ b/server/sonar-db-dao/src/schema/schema-sq.ddl
@@ -418,21 +418,20 @@ CREATE TABLE "LIVE_MEASURES"(
"UUID" VARCHAR(40) NOT NULL,
"PROJECT_UUID" VARCHAR(50) NOT NULL,
"COMPONENT_UUID" VARCHAR(50) NOT NULL,
- "METRIC_ID" INTEGER NOT NULL,
"VALUE" DOUBLE,
"TEXT_VALUE" VARCHAR(4000),
"VARIATION" DOUBLE,
"MEASURE_DATA" BLOB,
"UPDATE_MARKER" VARCHAR(40),
"CREATED_AT" BIGINT NOT NULL,
- "UPDATED_AT" BIGINT NOT NULL
+ "UPDATED_AT" BIGINT NOT NULL,
+ "METRIC_UUID" VARCHAR(40) NOT NULL
);
ALTER TABLE "LIVE_MEASURES" ADD CONSTRAINT "PK_LIVE_MEASURES" PRIMARY KEY("UUID");
CREATE INDEX "LIVE_MEASURES_PROJECT" ON "LIVE_MEASURES"("PROJECT_UUID");
-CREATE UNIQUE INDEX "LIVE_MEASURES_COMPONENT" ON "LIVE_MEASURES"("COMPONENT_UUID", "METRIC_ID");
+CREATE UNIQUE INDEX "LIVE_MEASURES_COMPONENT" ON "LIVE_MEASURES"("COMPONENT_UUID", "METRIC_UUID");
CREATE TABLE "MANUAL_MEASURES"(
- "METRIC_ID" INTEGER NOT NULL,
"VALUE" DOUBLE,
"TEXT_VALUE" VARCHAR(4000),
"USER_UUID" VARCHAR(255),
@@ -440,13 +439,13 @@ CREATE TABLE "MANUAL_MEASURES"(
"CREATED_AT" BIGINT,
"UPDATED_AT" BIGINT,
"COMPONENT_UUID" VARCHAR(50) NOT NULL,
- "UUID" VARCHAR(40) NOT NULL
+ "UUID" VARCHAR(40) NOT NULL,
+ "METRIC_UUID" VARCHAR(40) NOT NULL
);
ALTER TABLE "MANUAL_MEASURES" ADD CONSTRAINT "PK_MANUAL_MEASURES" PRIMARY KEY("UUID");
CREATE INDEX "MANUAL_MEASURES_COMPONENT_UUID" ON "MANUAL_MEASURES"("COMPONENT_UUID");
CREATE TABLE "METRICS"(
- "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
"NAME" VARCHAR(64) NOT NULL,
"DESCRIPTION" VARCHAR(255),
"DIRECTION" INTEGER DEFAULT 0 NOT NULL,
@@ -461,9 +460,10 @@ CREATE TABLE "METRICS"(
"OPTIMIZED_BEST_VALUE" BOOLEAN,
"HIDDEN" BOOLEAN,
"DELETE_HISTORICAL_DATA" BOOLEAN,
- "DECIMAL_SCALE" INTEGER
+ "DECIMAL_SCALE" INTEGER,
+ "UUID" VARCHAR(40) NOT NULL
);
-ALTER TABLE "METRICS" ADD CONSTRAINT "PK_METRICS" PRIMARY KEY("ID");
+ALTER TABLE "METRICS" ADD CONSTRAINT "PK_METRICS" PRIMARY KEY("UUID");
CREATE UNIQUE INDEX "METRICS_UNIQUE_NAME" ON "METRICS"("NAME");
CREATE TABLE "NEW_CODE_PERIODS"(
@@ -674,7 +674,6 @@ CREATE INDEX "PROJECT_UUID" ON "PROJECT_MAPPINGS"("PROJECT_UUID");
CREATE TABLE "PROJECT_MEASURES"(
"VALUE" DOUBLE,
- "METRIC_ID" INTEGER NOT NULL,
"ANALYSIS_UUID" VARCHAR(50) NOT NULL,
"COMPONENT_UUID" VARCHAR(50) NOT NULL,
"TEXT_VALUE" VARCHAR(4000),
@@ -688,11 +687,12 @@ CREATE TABLE "PROJECT_MEASURES"(
"VARIATION_VALUE_4" DOUBLE,
"VARIATION_VALUE_5" DOUBLE,
"MEASURE_DATA" BLOB,
- "UUID" VARCHAR(40) NOT NULL
+ "UUID" VARCHAR(40) NOT NULL,
+ "METRIC_UUID" VARCHAR(40) NOT NULL
);
ALTER TABLE "PROJECT_MEASURES" ADD CONSTRAINT "PK_PROJECT_MEASURES" PRIMARY KEY("UUID");
-CREATE INDEX "MEASURES_ANALYSIS_METRIC" ON "PROJECT_MEASURES"("ANALYSIS_UUID", "METRIC_ID");
CREATE INDEX "MEASURES_COMPONENT_UUID" ON "PROJECT_MEASURES"("COMPONENT_UUID");
+CREATE INDEX "MEASURES_ANALYSIS_METRIC" ON "PROJECT_MEASURES"("ANALYSIS_UUID", "METRIC_UUID");
CREATE TABLE "PROJECT_QGATES"(
"PROJECT_UUID" VARCHAR(40) NOT NULL,
@@ -771,14 +771,14 @@ CREATE UNIQUE INDEX "QPROFILE_EDIT_USERS_UNIQUE" ON "QPROFILE_EDIT_USERS"("USER_
CREATE TABLE "QUALITY_GATE_CONDITIONS"(
"QGATE_ID" INTEGER,
- "METRIC_ID" INTEGER,
"PERIOD" INTEGER,
"OPERATOR" VARCHAR(3),
"VALUE_ERROR" VARCHAR(64),
"VALUE_WARNING" VARCHAR(64),
"CREATED_AT" TIMESTAMP,
"UPDATED_AT" TIMESTAMP,
- "UUID" VARCHAR(40) NOT NULL
+ "UUID" VARCHAR(40) NOT NULL,
+ "METRIC_UUID" VARCHAR(40) NOT NULL
);
ALTER TABLE "QUALITY_GATE_CONDITIONS" ADD CONSTRAINT "PK_QUALITY_GATE_CONDITIONS" PRIMARY KEY("UUID");
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/measure/LiveMeasureDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/measure/LiveMeasureDaoTest.java
index 5b0acf9ca51..83299dde0eb 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/measure/LiveMeasureDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/measure/LiveMeasureDaoTest.java
@@ -64,30 +64,30 @@ public class LiveMeasureDaoTest {
@Test
public void selectByComponentUuidsAndMetricIds() {
- LiveMeasureDto measure1 = newLiveMeasure().setMetricId(metric.getId());
- LiveMeasureDto measure2 = newLiveMeasure().setMetricId(metric.getId());
+ LiveMeasureDto measure1 = newLiveMeasure().setMetricUuid(metric.getUuid());
+ LiveMeasureDto measure2 = newLiveMeasure().setMetricUuid(metric.getUuid());
underTest.insert(db.getSession(), measure1);
underTest.insert(db.getSession(), measure2);
- List<LiveMeasureDto> selected = underTest.selectByComponentUuidsAndMetricIds(db.getSession(),
- asList(measure1.getComponentUuid(), measure2.getComponentUuid()), singletonList(metric.getId()));
+ List<LiveMeasureDto> selected = underTest.selectByComponentUuidsAndMetricUuids(db.getSession(),
+ asList(measure1.getComponentUuid(), measure2.getComponentUuid()), singletonList(metric.getUuid()));
assertThat(selected)
- .extracting(LiveMeasureDto::getComponentUuid, LiveMeasureDto::getProjectUuid, LiveMeasureDto::getMetricId, LiveMeasureDto::getValue, LiveMeasureDto::getDataAsString)
+ .extracting(LiveMeasureDto::getComponentUuid, LiveMeasureDto::getProjectUuid, LiveMeasureDto::getMetricUuid, LiveMeasureDto::getValue, LiveMeasureDto::getDataAsString)
.containsExactlyInAnyOrder(
- tuple(measure1.getComponentUuid(), measure1.getProjectUuid(), measure1.getMetricId(), measure1.getValue(), measure1.getDataAsString()),
- tuple(measure2.getComponentUuid(), measure2.getProjectUuid(), measure2.getMetricId(), measure2.getValue(), measure2.getDataAsString()));
+ tuple(measure1.getComponentUuid(), measure1.getProjectUuid(), measure1.getMetricUuid(), measure1.getValue(), measure1.getDataAsString()),
+ tuple(measure2.getComponentUuid(), measure2.getProjectUuid(), measure2.getMetricUuid(), measure2.getValue(), measure2.getDataAsString()));
- assertThat(underTest.selectByComponentUuidsAndMetricIds(db.getSession(), emptyList(), singletonList(metric.getId()))).isEmpty();
- assertThat(underTest.selectByComponentUuidsAndMetricIds(db.getSession(), singletonList(measure1.getComponentUuid()), emptyList())).isEmpty();
+ assertThat(underTest.selectByComponentUuidsAndMetricUuids(db.getSession(), emptyList(), singletonList(metric.getUuid()))).isEmpty();
+ assertThat(underTest.selectByComponentUuidsAndMetricUuids(db.getSession(), singletonList(measure1.getComponentUuid()), emptyList())).isEmpty();
}
@Test
public void selectByComponentUuidsAndMetricIds_returns_empty_list_if_metric_does_not_match() {
- LiveMeasureDto measure = newLiveMeasure().setMetricId(metric.getId());
+ LiveMeasureDto measure = newLiveMeasure().setMetricUuid(metric.getUuid());
underTest.insert(db.getSession(), measure);
- int otherMetricId = metric.getId() + 100;
- List<LiveMeasureDto> selected = underTest.selectByComponentUuidsAndMetricIds(db.getSession(), singletonList(measure.getComponentUuid()), singletonList(otherMetricId));
+ String otherMetricUuid = metric.getUuid() + "other";
+ List<LiveMeasureDto> selected = underTest.selectByComponentUuidsAndMetricUuids(db.getSession(), singletonList(measure.getComponentUuid()), singletonList(otherMetricUuid));
assertThat(selected).isEmpty();
}
@@ -97,25 +97,25 @@ public class LiveMeasureDaoTest {
LiveMeasureDto measure = newLiveMeasure();
underTest.insert(db.getSession(), measure);
- List<LiveMeasureDto> selected = underTest.selectByComponentUuidsAndMetricIds(db.getSession(), singletonList("_missing_"), singletonList(measure.getMetricId()));
+ List<LiveMeasureDto> selected = underTest.selectByComponentUuidsAndMetricUuids(db.getSession(), singletonList("_missing_"), singletonList(measure.getMetricUuid()));
assertThat(selected).isEmpty();
}
@Test
public void selectByComponentUuidsAndMetricKeys() {
- LiveMeasureDto measure1 = newLiveMeasure().setMetricId(metric.getId());
- LiveMeasureDto measure2 = newLiveMeasure().setMetricId(metric.getId());
+ LiveMeasureDto measure1 = newLiveMeasure().setMetricUuid(metric.getUuid());
+ LiveMeasureDto measure2 = newLiveMeasure().setMetricUuid(metric.getUuid());
underTest.insert(db.getSession(), measure1);
underTest.insert(db.getSession(), measure2);
List<LiveMeasureDto> selected = underTest.selectByComponentUuidsAndMetricKeys(db.getSession(), asList(measure1.getComponentUuid(), measure2.getComponentUuid()),
singletonList(metric.getKey()));
assertThat(selected)
- .extracting(LiveMeasureDto::getComponentUuid, LiveMeasureDto::getProjectUuid, LiveMeasureDto::getMetricId, LiveMeasureDto::getValue, LiveMeasureDto::getDataAsString)
+ .extracting(LiveMeasureDto::getComponentUuid, LiveMeasureDto::getProjectUuid, LiveMeasureDto::getMetricUuid, LiveMeasureDto::getValue, LiveMeasureDto::getDataAsString)
.containsExactlyInAnyOrder(
- tuple(measure1.getComponentUuid(), measure1.getProjectUuid(), measure1.getMetricId(), measure1.getValue(), measure1.getDataAsString()),
- tuple(measure2.getComponentUuid(), measure2.getProjectUuid(), measure2.getMetricId(), measure2.getValue(), measure2.getDataAsString()));
+ tuple(measure1.getComponentUuid(), measure1.getProjectUuid(), measure1.getMetricUuid(), measure1.getValue(), measure1.getDataAsString()),
+ tuple(measure2.getComponentUuid(), measure2.getProjectUuid(), measure2.getMetricUuid(), measure2.getValue(), measure2.getDataAsString()));
assertThat(underTest.selectByComponentUuidsAndMetricKeys(db.getSession(), emptyList(), singletonList(metric.getKey()))).isEmpty();
assertThat(underTest.selectByComponentUuidsAndMetricKeys(db.getSession(), singletonList(measure1.getComponentUuid()), emptyList())).isEmpty();
@@ -123,7 +123,7 @@ public class LiveMeasureDaoTest {
@Test
public void selectByComponentUuidsAndMetricKeys_returns_empty_list_if_metric_does_not_match() {
- LiveMeasureDto measure = newLiveMeasure().setMetricId(metric.getId());
+ LiveMeasureDto measure = newLiveMeasure().setMetricUuid(metric.getUuid());
underTest.insert(db.getSession(), measure);
List<LiveMeasureDto> selected = underTest.selectByComponentUuidsAndMetricKeys(db.getSession(), singletonList(measure.getComponentUuid()), singletonList("_other_"));
@@ -133,7 +133,7 @@ public class LiveMeasureDaoTest {
@Test
public void selectByComponentUuidsAndMetricKeys_returns_empty_list_if_component_does_not_match() {
- LiveMeasureDto measure = newLiveMeasure().setMetricId(metric.getId());
+ LiveMeasureDto measure = newLiveMeasure().setMetricUuid(metric.getUuid());
underTest.insert(db.getSession(), measure);
List<LiveMeasureDto> selected = underTest.selectByComponentUuidsAndMetricKeys(db.getSession(), singletonList("_missing_"), singletonList(metric.getKey()));
@@ -143,7 +143,7 @@ public class LiveMeasureDaoTest {
@Test
public void selectByComponentUuidAndMetricKey() {
- LiveMeasureDto measure = newLiveMeasure().setMetricId(metric.getId());
+ LiveMeasureDto measure = newLiveMeasure().setMetricUuid(metric.getUuid());
underTest.insert(db.getSession(), measure);
Optional<LiveMeasureDto> selected = underTest.selectMeasure(db.getSession(), measure.getComponentUuid(), metric.getKey());
@@ -154,7 +154,7 @@ public class LiveMeasureDaoTest {
@Test
public void selectByComponentUuidAndMetricKey_return_empty_if_component_does_not_match() {
- LiveMeasureDto measure = newLiveMeasure().setMetricId(metric.getId());
+ LiveMeasureDto measure = newLiveMeasure().setMetricUuid(metric.getUuid());
underTest.insert(db.getSession(), measure);
assertThat(underTest.selectMeasure(db.getSession(), "_missing_", metric.getKey())).isEmpty();
@@ -162,7 +162,7 @@ public class LiveMeasureDaoTest {
@Test
public void selectByComponentUuidAndMetricKey_return_empty_if_metric_does_not_match() {
- LiveMeasureDto measure = newLiveMeasure().setMetricId(metric.getId());
+ LiveMeasureDto measure = newLiveMeasure().setMetricUuid(metric.getUuid());
underTest.insert(db.getSession(), measure);
assertThat(underTest.selectMeasure(db.getSession(), measure.getComponentUuid(), "_missing_")).isEmpty();
@@ -172,8 +172,8 @@ public class LiveMeasureDaoTest {
public void selectByComponentUuidAndMetricKeys() {
MetricDto metric2 = db.measures().insertMetric();
- LiveMeasureDto measure1 = newLiveMeasure().setMetricId(metric.getId()).setValue(1.0).setComponentUuid("uuid");
- LiveMeasureDto measure2 = newLiveMeasure().setMetricId(metric2.getId()).setValue(2.0).setComponentUuid("uuid");
+ LiveMeasureDto measure1 = newLiveMeasure().setMetricUuid(metric.getUuid()).setValue(1.0).setComponentUuid("uuid");
+ LiveMeasureDto measure2 = newLiveMeasure().setMetricUuid(metric2.getUuid()).setValue(2.0).setComponentUuid("uuid");
underTest.insert(db.getSession(), measure1);
underTest.insert(db.getSession(), measure2);
@@ -181,13 +181,13 @@ public class LiveMeasureDaoTest {
List<LiveMeasureDto> selected = underTest.selectByComponentUuidAndMetricKeys(db.getSession(), "uuid", asList(metric.getKey(), metric2.getKey()));
assertThat(selected).hasSize(2);
- assertThat(selected).extracting(LiveMeasureDto::getMetricId, LiveMeasureDto::getValue)
- .containsExactlyInAnyOrder(tuple(metric.getId(), measure1.getValue()), tuple(metric2.getId(), measure2.getValue()));
+ assertThat(selected).extracting(LiveMeasureDto::getMetricUuid, LiveMeasureDto::getValue)
+ .containsExactlyInAnyOrder(tuple(metric.getUuid(), measure1.getValue()), tuple(metric2.getUuid(), measure2.getValue()));
}
@Test
public void selectByComponentUuidAndMetricKeys_return_empty_if_component_does_not_match() {
- LiveMeasureDto measure = newLiveMeasure().setMetricId(metric.getId());
+ LiveMeasureDto measure = newLiveMeasure().setMetricUuid(metric.getUuid());
underTest.insert(db.getSession(), measure);
assertThat(underTest.selectByComponentUuidAndMetricKeys(db.getSession(), "_missing_", singletonList(metric.getKey()))).isEmpty();
@@ -195,7 +195,7 @@ public class LiveMeasureDaoTest {
@Test
public void selectByComponentUuidAndMetricKeys_return_empty_if_no_metric_matches() {
- LiveMeasureDto measure = newLiveMeasure().setMetricId(metric.getId());
+ LiveMeasureDto measure = newLiveMeasure().setMetricUuid(metric.getUuid());
underTest.insert(db.getSession(), measure);
assertThat(underTest.selectByComponentUuidAndMetricKeys(db.getSession(), measure.getComponentUuid(), singletonList("_missing_"))).isEmpty();
@@ -204,7 +204,7 @@ public class LiveMeasureDaoTest {
@Test
public void selectMeasure() {
MetricDto metric = db.measures().insertMetric();
- LiveMeasureDto stored = newLiveMeasure().setMetricId(metric.getId());
+ LiveMeasureDto stored = newLiveMeasure().setMetricUuid(metric.getUuid());
underTest.insert(db.getSession(), stored);
// metric exists but not component
@@ -231,14 +231,14 @@ public class LiveMeasureDaoTest {
underTest.selectTreeByQuery(db.getSession(), project,
MeasureTreeQuery.builder()
- .setMetricIds(singleton(metric.getId()))
+ .setMetricUuids(singleton(metric.getUuid()))
.setStrategy(MeasureTreeQuery.Strategy.LEAVES).build(),
context -> results.add(context.getResultObject()));
assertThat(results).hasSize(1);
LiveMeasureDto result = results.get(0);
assertThat(result.getComponentUuid()).isEqualTo(file.uuid());
- assertThat(result.getMetricId()).isEqualTo(metric.getId());
+ assertThat(result.getMetricUuid()).isEqualTo(metric.getUuid());
assertThat(result.getValue()).isEqualTo(3.14);
}
@@ -256,13 +256,13 @@ public class LiveMeasureDaoTest {
context -> results.add(context.getResultObject()));
assertThat(results).hasSize(2);
- LiveMeasureDto result = results.stream().filter(lm -> lm.getMetricId() == metric.getId()).findFirst().get();
+ LiveMeasureDto result = results.stream().filter(lm -> lm.getMetricUuid().equals(metric.getUuid())).findFirst().get();
assertThat(result.getComponentUuid()).isEqualTo(project.uuid());
- assertThat(result.getMetricId()).isEqualTo(metric.getId());
+ assertThat(result.getMetricUuid()).isEqualTo(metric.getUuid());
assertThat(result.getValue()).isEqualTo(3.14);
- LiveMeasureDto result2 = results.stream().filter(lm -> lm.getMetricId() == metric2.getId()).findFirst().get();
+ LiveMeasureDto result2 = results.stream().filter(lm -> lm.getMetricUuid().equals(metric2.getUuid())).findFirst().get();
assertThat(result2.getComponentUuid()).isEqualTo(project.uuid());
- assertThat(result2.getMetricId()).isEqualTo(metric2.getId());
+ assertThat(result2.getMetricUuid()).isEqualTo(metric2.getUuid());
assertThat(result2.getValue()).isEqualTo(4.54);
}
@@ -296,9 +296,9 @@ public class LiveMeasureDaoTest {
LiveMeasureDto result = underTest.selectMeasure(db.getSession(), file.uuid(), metric.getKey()).orElseThrow(() -> new IllegalArgumentException("Measure not found"));
assertThat(result).as("Fail to map fields of %s", result.toString()).extracting(
- LiveMeasureDto::getProjectUuid, LiveMeasureDto::getComponentUuid, LiveMeasureDto::getMetricId, LiveMeasureDto::getValue, LiveMeasureDto::getVariation,
+ LiveMeasureDto::getProjectUuid, LiveMeasureDto::getComponentUuid, LiveMeasureDto::getMetricUuid, LiveMeasureDto::getValue, LiveMeasureDto::getVariation,
LiveMeasureDto::getDataAsString, LiveMeasureDto::getTextValue)
- .contains(project.uuid(), file.uuid(), metric.getId(), 3.14, 0.1, "text_value", "text_value");
+ .contains(project.uuid(), file.uuid(), metric.getUuid(), 3.14, 0.1, "text_value", "text_value");
}
@Test
@@ -403,16 +403,16 @@ public class LiveMeasureDaoTest {
@Test
public void deleteByComponentUuidExcludingMetricIds() {
- LiveMeasureDto measure1 = newLiveMeasure().setComponentUuid("C1").setMetricId(1);
- LiveMeasureDto measure2 = newLiveMeasure().setComponentUuid("C1").setMetricId(2);
- LiveMeasureDto measure3 = newLiveMeasure().setComponentUuid("C1").setMetricId(3);
- LiveMeasureDto measureOtherComponent = newLiveMeasure().setComponentUuid("C2").setMetricId(3);
+ LiveMeasureDto measure1 = newLiveMeasure().setComponentUuid("C1").setMetricUuid("1");
+ LiveMeasureDto measure2 = newLiveMeasure().setComponentUuid("C1").setMetricUuid("2");
+ LiveMeasureDto measure3 = newLiveMeasure().setComponentUuid("C1").setMetricUuid("3");
+ LiveMeasureDto measureOtherComponent = newLiveMeasure().setComponentUuid("C2").setMetricUuid("3");
underTest.insertOrUpdate(db.getSession(), measure1);
underTest.insertOrUpdate(db.getSession(), measure2);
underTest.insertOrUpdate(db.getSession(), measure3);
underTest.insertOrUpdate(db.getSession(), measureOtherComponent);
- underTest.deleteByComponentUuidExcludingMetricIds(db.getSession(), "C1", Arrays.asList(1, 2));
+ underTest.deleteByComponentUuidExcludingMetricUuids(db.getSession(), "C1", Arrays.asList("1", "2"));
verifyTableSize(3);
verifyPersisted(measure1);
@@ -422,10 +422,10 @@ public class LiveMeasureDaoTest {
@Test
public void deleteByComponentUuid() {
- LiveMeasureDto measure1 = newLiveMeasure().setComponentUuid("C1").setMetricId(1);
- LiveMeasureDto measure2 = newLiveMeasure().setComponentUuid("C1").setMetricId(2);
- LiveMeasureDto measure3 = newLiveMeasure().setComponentUuid("C1").setMetricId(3);
- LiveMeasureDto measureOtherComponent = newLiveMeasure().setComponentUuid("C2").setMetricId(3);
+ LiveMeasureDto measure1 = newLiveMeasure().setComponentUuid("C1").setMetricUuid("1");
+ LiveMeasureDto measure2 = newLiveMeasure().setComponentUuid("C1").setMetricUuid("2");
+ LiveMeasureDto measure3 = newLiveMeasure().setComponentUuid("C1").setMetricUuid("3");
+ LiveMeasureDto measureOtherComponent = newLiveMeasure().setComponentUuid("C2").setMetricUuid("3");
underTest.insertOrUpdate(db.getSession(), measure1);
underTest.insertOrUpdate(db.getSession(), measure2);
underTest.insertOrUpdate(db.getSession(), measure3);
@@ -439,14 +439,14 @@ public class LiveMeasureDaoTest {
@Test
public void deleteByComponentUuidExcludingMetricIds_with_empty_metrics() {
- LiveMeasureDto measure1 = newLiveMeasure().setComponentUuid("C1").setMetricId(1);
- LiveMeasureDto measure2 = newLiveMeasure().setComponentUuid("C1").setMetricId(2);
- LiveMeasureDto measureOnOtherComponent = newLiveMeasure().setComponentUuid("C2").setMetricId(2);
+ LiveMeasureDto measure1 = newLiveMeasure().setComponentUuid("C1").setMetricUuid("1");
+ LiveMeasureDto measure2 = newLiveMeasure().setComponentUuid("C1").setMetricUuid("2");
+ LiveMeasureDto measureOnOtherComponent = newLiveMeasure().setComponentUuid("C2").setMetricUuid("2");
underTest.insertOrUpdate(db.getSession(), measure1);
underTest.insertOrUpdate(db.getSession(), measure2);
underTest.insertOrUpdate(db.getSession(), measureOnOtherComponent);
- underTest.deleteByComponentUuidExcludingMetricIds(db.getSession(), "C1", Collections.emptyList());
+ underTest.deleteByComponentUuidExcludingMetricUuids(db.getSession(), "C1", Collections.emptyList());
verifyTableSize(1);
verifyPersisted(measureOnOtherComponent);
@@ -670,10 +670,10 @@ public class LiveMeasureDaoTest {
}
private void verifyPersisted(LiveMeasureDto dto) {
- List<LiveMeasureDto> selected = underTest.selectByComponentUuidsAndMetricIds(db.getSession(), singletonList(dto.getComponentUuid()), singletonList(dto.getMetricId()));
+ List<LiveMeasureDto> selected = underTest.selectByComponentUuidsAndMetricUuids(db.getSession(), singletonList(dto.getComponentUuid()), singletonList(dto.getMetricUuid()));
assertThat(selected).hasSize(1);
assertThat(selected.get(0)).isEqualToComparingOnlyGivenFields(dto,
// do not compare the field "uuid", which is used only for insert, not select
- "componentUuid", "projectUuid", "metricId", "value", "textValue", "data", "variation");
+ "componentUuid", "projectUuid", "metricUuid", "value", "textValue", "data", "variation");
}
}
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/measure/MeasureDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/measure/MeasureDaoTest.java
index a2f66a36cb9..8d7f8c17857 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/measure/MeasureDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/measure/MeasureDaoTest.java
@@ -123,18 +123,18 @@ public class MeasureDaoTest {
SnapshotDto project2LastAnalysis = insertAnalysis(project2.uuid(), true);
// project 1
- insertMeasure("P1_M1", lastAnalysis.getUuid(), project1.uuid(), ncloc.getId());
- insertMeasure("P1_M2", lastAnalysis.getUuid(), project1.uuid(), coverage.getId());
- insertMeasure("P1_M3", pastAnalysis.getUuid(), project1.uuid(), ncloc.getId());
+ insertMeasure("P1_M1", lastAnalysis.getUuid(), project1.uuid(), ncloc.getUuid());
+ insertMeasure("P1_M2", lastAnalysis.getUuid(), project1.uuid(), coverage.getUuid());
+ insertMeasure("P1_M3", pastAnalysis.getUuid(), project1.uuid(), ncloc.getUuid());
// project 2
- insertMeasure("P2_M1", project2LastAnalysis.getUuid(), project2.uuid(), ncloc.getId());
- insertMeasure("P2_M2", project2LastAnalysis.getUuid(), project2.uuid(), coverage.getId());
+ insertMeasure("P2_M1", project2LastAnalysis.getUuid(), project2.uuid(), ncloc.getUuid());
+ insertMeasure("P2_M2", project2LastAnalysis.getUuid(), project2.uuid(), coverage.getUuid());
// component C1
- insertMeasure("M1", pastAnalysis.getUuid(), "C1", ncloc.getId());
- insertMeasure("M2", lastAnalysis.getUuid(), "C1", ncloc.getId());
- insertMeasure("M3", lastAnalysis.getUuid(), "C1", coverage.getId());
+ insertMeasure("M1", pastAnalysis.getUuid(), "C1", ncloc.getUuid());
+ insertMeasure("M2", lastAnalysis.getUuid(), "C1", ncloc.getUuid());
+ insertMeasure("M3", lastAnalysis.getUuid(), "C1", coverage.getUuid());
// component C2
- insertMeasure("M6", lastAnalysis.getUuid(), "C2", ncloc.getId());
+ insertMeasure("M6", lastAnalysis.getUuid(), "C2", ncloc.getUuid());
db.commit();
verifyNoMeasure("C1", ncloc.getKey(), "invalid_analysis");
@@ -176,14 +176,14 @@ public class MeasureDaoTest {
db.commit();
// project
- insertMeasure("PROJECT_M1", lastAnalysis.getUuid(), project.uuid(), ncloc.getId());
- insertMeasure("PROJECT_M2", pastAnalysis.getUuid(), project.uuid(), ncloc.getId());
- insertMeasure("PROJECT_M3", "OLD_ANALYSIS_UUID", project.uuid(), ncloc.getId());
+ insertMeasure("PROJECT_M1", lastAnalysis.getUuid(), project.uuid(), ncloc.getUuid());
+ insertMeasure("PROJECT_M2", pastAnalysis.getUuid(), project.uuid(), ncloc.getUuid());
+ insertMeasure("PROJECT_M3", "OLD_ANALYSIS_UUID", project.uuid(), ncloc.getUuid());
db.commit();
// Measures of project for last and previous analyses
List<MeasureDto> result = underTest.selectPastMeasures(db.getSession(),
- new PastMeasureQuery(project.uuid(), singletonList(ncloc.getId()), previousAnalysisDate, lastAnalysisDate + 1_000L));
+ new PastMeasureQuery(project.uuid(), singletonList(ncloc.getUuid()), previousAnalysisDate, lastAnalysisDate + 1_000L));
assertThat(result).hasSize(2).extracting(MeasureDto::getData).containsOnly("PROJECT_M1", "PROJECT_M2");
}
@@ -208,11 +208,11 @@ public class MeasureDaoTest {
assertThat(underTest.selectLastMeasure(db.getSession(), componentUuid, metricKey)).isEmpty();
}
- private void insertMeasure(String value, String analysisUuid, String componentUuid, int metricId) {
+ private void insertMeasure(String value, String analysisUuid, String componentUuid, String metricUuid) {
MeasureDto measure = MeasureTesting.newMeasure()
.setAnalysisUuid(analysisUuid)
.setComponentUuid(componentUuid)
- .setMetricId(metricId)
+ .setMetricUuid(metricUuid)
// as ids can't be forced when inserting measures, the field "data"
// is used to store a virtual value. It is used then in assertions.
.setData(value);
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/measure/MeasureTreeQueryTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/measure/MeasureTreeQueryTest.java
index 515dbc5d8b6..66349c17b66 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/measure/MeasureTreeQueryTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/measure/MeasureTreeQueryTest.java
@@ -42,13 +42,13 @@ public class MeasureTreeQueryTest {
.setStrategy(CHILDREN)
.setQualifiers(asList("FIL", "DIR"))
.setNameOrKeyQuery("teSt")
- .setMetricIds(asList(10, 11))
+ .setMetricUuids(asList("10", "11"))
.build();
assertThat(query.getStrategy()).isEqualTo(CHILDREN);
assertThat(query.getQualifiers()).containsOnly("FIL", "DIR");
assertThat(query.getNameOrKeyQuery()).isEqualTo("teSt");
- assertThat(query.getMetricIds()).containsOnly(10, 11);
+ assertThat(query.getMetricUuids()).containsOnly("10", "11");
}
@Test
@@ -60,7 +60,7 @@ public class MeasureTreeQueryTest {
assertThat(query.getStrategy()).isEqualTo(CHILDREN);
assertThat(query.getQualifiers()).isNull();
assertThat(query.getNameOrKeyQuery()).isNull();
- assertThat(query.getMetricIds()).isNull();
+ assertThat(query.getMetricUuids()).isNull();
}
@Test
@@ -88,12 +88,12 @@ public class MeasureTreeQueryTest {
public void return_empty_when_metrics_is_empty() {
assertThat(MeasureTreeQuery.builder()
.setStrategy(CHILDREN)
- .setMetricIds(Collections.emptyList())
+ .setMetricUuids(Collections.emptyList())
.build().returnsEmpty()).isTrue();
assertThat(MeasureTreeQuery.builder()
.setStrategy(CHILDREN)
- .setMetricIds(null)
+ .setMetricUuids(null)
.build().returnsEmpty()).isFalse();
}
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/measure/PastMeasureDtoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/measure/PastMeasureDtoTest.java
index 98e04654871..94fb6644954 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/measure/PastMeasureDtoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/measure/PastMeasureDtoTest.java
@@ -29,22 +29,22 @@ public class PastMeasureDtoTest {
public void test_getter_and_setter() {
PastMeasureDto dto = new PastMeasureDto()
.setValue(1d)
- .setMetricId(2);
+ .setMetricUuid("2");
assertThat(dto.hasValue()).isTrue();
assertThat(dto.getValue()).isEqualTo(1d);
- assertThat(dto.getMetricId()).isEqualTo(2);
+ assertThat(dto.getMetricUuid()).isEqualTo("2");
}
@Test
public void test_has_value() {
PastMeasureDto measureWithValue = new PastMeasureDto()
.setValue(1d)
- .setMetricId(2);
+ .setMetricUuid("2");
assertThat(measureWithValue.hasValue()).isTrue();
PastMeasureDto measureWithoutValue = new PastMeasureDto()
- .setMetricId(2);
+ .setMetricUuid("2");
assertThat(measureWithoutValue.hasValue()).isFalse();
}
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/measure/custom/CustomMeasureDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/measure/custom/CustomMeasureDaoTest.java
index 366b64d412b..44499e01c68 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/measure/custom/CustomMeasureDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/measure/custom/CustomMeasureDaoTest.java
@@ -54,7 +54,7 @@ public class CustomMeasureDaoTest {
MetricDto metric = db.measures().insertMetric(m -> m.setUserManaged(true));
CustomMeasureDto measure = newCustomMeasureDto()
.setComponentUuid(project.uuid())
- .setMetricId(metric.getId())
+ .setMetricUuid(metric.getUuid())
.setUserUuid(user.getUuid());
underTest.insert(session, measure);
@@ -63,7 +63,7 @@ public class CustomMeasureDaoTest {
assertThat(optionalResult).isNotEmpty();
CustomMeasureDto result = optionalResult.get();
assertThat(result.getUuid()).isEqualTo(measure.getUuid());
- assertThat(result.getMetricId()).isEqualTo(metric.getId());
+ assertThat(result.getMetricUuid()).isEqualTo(metric.getUuid());
assertThat(result.getComponentUuid()).isEqualTo(project.uuid());
assertThat(result.getUserUuid()).isEqualTo(user.getUuid());
assertThat(result.getDescription()).isEqualTo(measure.getDescription());
@@ -80,7 +80,7 @@ public class CustomMeasureDaoTest {
MetricDto metric = db.measures().insertMetric(m -> m.setUserManaged(true));
CustomMeasureDto measure = db.measures().insertCustomMeasure(user, project, metric);
- underTest.deleteByMetricIds(session, singletonList(measure.getMetricId()));
+ underTest.deleteByMetricUuids(session, singletonList(measure.getMetricUuid()));
assertThat(underTest.selectByUuid(session, measure.getUuid())).isEmpty();
}
@@ -151,20 +151,20 @@ public class CustomMeasureDaoTest {
@Test
public void select_by_metric_id() {
- underTest.insert(session, newCustomMeasureDto().setMetricId(123));
- underTest.insert(session, newCustomMeasureDto().setMetricId(123));
+ underTest.insert(session, newCustomMeasureDto().setMetricUuid("metric"));
+ underTest.insert(session, newCustomMeasureDto().setMetricUuid("metric"));
- List<CustomMeasureDto> result = underTest.selectByMetricId(session, 123);
+ List<CustomMeasureDto> result = underTest.selectByMetricUuid(session, "metric");
assertThat(result).hasSize(2);
}
@Test
public void count_by_component_uuid_and_metric_id() {
- underTest.insert(session, newCustomMeasureDto().setMetricId(123).setComponentUuid("123"));
- underTest.insert(session, newCustomMeasureDto().setMetricId(123).setComponentUuid("123"));
+ underTest.insert(session, newCustomMeasureDto().setMetricUuid("metric").setComponentUuid("123"));
+ underTest.insert(session, newCustomMeasureDto().setMetricUuid("metric").setComponentUuid("123"));
- int count = underTest.countByComponentIdAndMetricId(session, "123", 123);
+ int count = underTest.countByComponentIdAndMetricUuid(session, "123", "metric");
assertThat(count).isEqualTo(2);
}
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/metric/MetricDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/metric/MetricDaoTest.java
index 13299a342d8..3654ce60937 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/metric/MetricDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/metric/MetricDaoTest.java
@@ -30,6 +30,7 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.sonar.api.utils.System2;
+import org.sonar.core.util.Uuids;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.RowNotFoundException;
@@ -93,8 +94,8 @@ public class MetricDaoTest {
db.getSession().commit();
assertThat(underTest.selectEnabled(dbSession))
- .extracting(MetricDto::getId)
- .containsOnly(enabledMetrics.stream().map(MetricDto::getId).toArray(Integer[]::new));
+ .extracting(MetricDto::getUuid)
+ .containsOnly(enabledMetrics.stream().map(MetricDto::getUuid).toArray(String[]::new));
}
@Test
@@ -113,13 +114,14 @@ public class MetricDaoTest {
db.getSession().commit();
assertThat(underTest.selectEnabled(dbSession))
- .extracting(MetricDto::getId)
- .containsOnly(enabledMetrics.stream().map(MetricDto::getId).toArray(Integer[]::new));
+ .extracting(MetricDto::getUuid)
+ .containsOnly(enabledMetrics.stream().map(MetricDto::getUuid).toArray(String[]::new));
}
@Test
public void insert() {
underTest.insert(dbSession, new MetricDto()
+ .setUuid(Uuids.createFast())
.setKey("coverage")
.setShortName("Coverage")
.setDescription("Coverage by unit tests")
@@ -136,7 +138,7 @@ public class MetricDaoTest {
.setEnabled(true));
MetricDto result = underTest.selectByKey(dbSession, "coverage");
- assertThat(result.getId()).isNotNull();
+ assertThat(result.getUuid()).isNotNull();
assertThat(result.getKey()).isEqualTo("coverage");
assertThat(result.getShortName()).isEqualTo("Coverage");
assertThat(result.getDescription()).isEqualTo("Coverage by unit tests");
@@ -156,6 +158,7 @@ public class MetricDaoTest {
@Test
public void insert_metrics() {
underTest.insert(dbSession, new MetricDto()
+ .setUuid(Uuids.createFast())
.setKey("coverage")
.setShortName("Coverage")
.setDescription("Coverage by unit tests")
@@ -171,6 +174,7 @@ public class MetricDaoTest {
.setDeleteHistoricalData(true)
.setEnabled(true),
new MetricDto()
+ .setUuid(Uuids.createFast())
.setKey("ncloc")
.setShortName("ncloc")
.setDescription("ncloc")
@@ -191,20 +195,20 @@ public class MetricDaoTest {
}
@Test
- public void selectById() {
+ public void selectByUuid() {
MetricDto metric = underTest.insert(dbSession, newMetricDto());
- MetricDto result = underTest.selectById(dbSession, metric.getId());
+ MetricDto result = underTest.selectByUuid(dbSession, metric.getUuid());
assertThat(result).isNotNull();
}
@Test
- public void selectByIds() {
+ public void selectByUuids() {
MetricDto metric1 = underTest.insert(dbSession, newMetricDto());
MetricDto metric2 = underTest.insert(dbSession, newMetricDto());
- List<MetricDto> result = underTest.selectByIds(dbSession, newHashSet(metric1.getId(), metric2.getId()));
+ List<MetricDto> result = underTest.selectByUuids(dbSession, newHashSet(metric1.getUuid(), metric2.getUuid()));
assertThat(result).hasSize(2);
}
@@ -255,13 +259,13 @@ public class MetricDaoTest {
}
@Test
- public void disableByIds() {
+ public void disableByUuids() {
MetricDto metric1 = underTest.insert(dbSession, newMetricDto().setEnabled(true).setUserManaged(true));
MetricDto metric2 = underTest.insert(dbSession, newMetricDto().setEnabled(true).setUserManaged(true));
- underTest.disableCustomByIds(dbSession, Arrays.asList(metric1.getId(), metric2.getId()));
+ underTest.disableCustomByUuids(dbSession, Arrays.asList(metric1.getUuid(), metric2.getUuid()));
- List<MetricDto> result = underTest.selectByIds(dbSession, newHashSet(metric1.getId(), metric2.getId()));
+ List<MetricDto> result = underTest.selectByUuids(dbSession, newHashSet(metric1.getUuid(), metric2.getUuid()));
assertThat(result).hasSize(2);
assertThat(result).extracting("enabled").containsOnly(false);
}
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/metric/MetricDtoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/metric/MetricDtoTest.java
index a3974e3cd8d..1f3c0506289 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/metric/MetricDtoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/metric/MetricDtoTest.java
@@ -35,7 +35,7 @@ public class MetricDtoTest {
@Test
public void getters_and_setters() {
MetricDto metricDto = new MetricDto()
- .setId(1)
+ .setUuid("1")
.setKey("coverage")
.setShortName("Coverage")
.setDescription("Coverage by unit tests")
@@ -51,7 +51,7 @@ public class MetricDtoTest {
.setDeleteHistoricalData(true)
.setEnabled(true);
- assertThat(metricDto.getId()).isEqualTo(1);
+ assertThat(metricDto.getUuid()).isEqualTo("1");
assertThat(metricDto.getKey()).isEqualTo("coverage");
assertThat(metricDto.getShortName()).isEqualTo("Coverage");
assertThat(metricDto.getDescription()).isEqualTo("Coverage by unit tests");
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeCommandsTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeCommandsTest.java
index 2634468b5f4..717f259e0b3 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeCommandsTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeCommandsTest.java
@@ -622,7 +622,7 @@ public class PurgeCommandsTest {
}
private int countMeasures(SnapshotDto analysis, MetricDto metric) {
- return dbTester.countSql("select count(*) from project_measures where analysis_uuid='" + analysis.getUuid() + "' and metric_id=" + metric.getId());
+ return dbTester.countSql("select count(*) from project_measures where analysis_uuid='" + analysis.getUuid() + "' and metric_id=" + metric.getUuid());
}
private int countComponentOfRoot(ComponentDto projectOrView) {
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeDaoTest.java
index 6ef1af9804d..de9d82c07bd 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeDaoTest.java
@@ -285,14 +285,14 @@ public class PurgeDaoTest {
// deletes live measure of selected
assertThat(db.countRowsOfTable("live_measures")).isEqualTo(4);
List<LiveMeasureDto> liveMeasureDtos = db.getDbClient().liveMeasureDao()
- .selectByComponentUuidsAndMetricIds(dbSession, ImmutableSet.of(srcFile.uuid(), dir.uuid(), project.uuid(), enabledFile.uuid()),
- ImmutableSet.of(metric1.getId(), metric2.getId()));
+ .selectByComponentUuidsAndMetricUuids(dbSession, ImmutableSet.of(srcFile.uuid(), dir.uuid(), project.uuid(), enabledFile.uuid()),
+ ImmutableSet.of(metric1.getUuid(), metric2.getUuid()));
assertThat(liveMeasureDtos)
.extracting(LiveMeasureDto::getComponentUuid)
.containsOnly(enabledFile.uuid(), project.uuid());
assertThat(liveMeasureDtos)
- .extracting(LiveMeasureDto::getMetricId)
- .containsOnly(metric1.getId(), metric2.getId());
+ .extracting(LiveMeasureDto::getMetricUuid)
+ .containsOnly(metric1.getUuid(), metric2.getUuid());
}
@Test
@@ -1272,8 +1272,8 @@ public class PurgeDaoTest {
underTest.deleteProject(dbSession, project1.uuid());
- assertThat(dbClient.liveMeasureDao().selectByComponentUuidsAndMetricIds(dbSession, asList(project1.uuid(), module1.uuid()), asList(metric.getId()))).isEmpty();
- assertThat(dbClient.liveMeasureDao().selectByComponentUuidsAndMetricIds(dbSession, asList(project2.uuid(), module2.uuid()), asList(metric.getId()))).hasSize(2);
+ assertThat(dbClient.liveMeasureDao().selectByComponentUuidsAndMetricUuids(dbSession, asList(project1.uuid(), module1.uuid()), asList(metric.getUuid()))).isEmpty();
+ assertThat(dbClient.liveMeasureDao().selectByComponentUuidsAndMetricUuids(dbSession, asList(project2.uuid(), module2.uuid()), asList(metric.getUuid()))).hasSize(2);
}
private void verifyNoEffect(ComponentDto firstRoot, ComponentDto... otherRoots) {
@@ -1525,7 +1525,7 @@ public class PurgeDaoTest {
private void insertManualMeasureFor(ComponentDto... componentDtos) {
Arrays.stream(componentDtos).forEach(componentDto -> dbClient.customMeasureDao().insert(dbSession, new CustomMeasureDto()
.setComponentUuid(componentDto.uuid())
- .setMetricId(new Random().nextInt())));
+ .setMetricUuid(randomAlphabetic(3))));
dbSession.commit();
}
@@ -1553,7 +1553,7 @@ public class PurgeDaoTest {
private void insertMeasureFor(ComponentDto... components) {
Arrays.stream(components).forEach(componentDto -> db.getDbClient().measureDao().insert(dbSession, new MeasureDto()
- .setMetricId(new Random().nextInt())
+ .setMetricUuid(randomAlphabetic(3))
.setComponentUuid(componentDto.uuid())
.setAnalysisUuid(randomAlphabetic(3))));
dbSession.commit();
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/qualitygate/QualityGateConditionDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/qualitygate/QualityGateConditionDaoTest.java
index 658a7077aa6..3c94e1d57d3 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/qualitygate/QualityGateConditionDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/qualitygate/QualityGateConditionDaoTest.java
@@ -44,7 +44,7 @@ public class QualityGateConditionDaoTest {
@Test
public void testInsert() {
- QualityGateConditionDto newCondition = insertQGCondition(1L, 2L, "GT", "20");
+ QualityGateConditionDto newCondition = insertQGCondition(1L, "2", "GT", "20");
assertThat(newCondition.getUuid()).isNotNull();
QualityGateConditionDto actual = underTest.selectByUuid(newCondition.getUuid(), dbSession);
@@ -83,7 +83,7 @@ public class QualityGateConditionDaoTest {
@Test
public void testSelectByUuid() {
- QualityGateConditionDto condition = insertQGCondition(1L, 2L, "GT", "20");
+ QualityGateConditionDto condition = insertQGCondition(1L, "2", "GT", "20");
assertEquals(underTest.selectByUuid(condition.getUuid(), dbSession), condition);
assertThat(underTest.selectByUuid("uuid1", dbSession)).isNull();
@@ -109,7 +109,7 @@ public class QualityGateConditionDaoTest {
QualityGateConditionDto newCondition1 = new QualityGateConditionDto()
.setUuid(condition1.getUuid())
.setQualityGateId(condition1.getQualityGateId())
- .setMetricId(7L)
+ .setMetricUuid("7")
.setOperator(">")
.setErrorThreshold("80");
underTest.update(newCondition1, dbSession);
@@ -124,9 +124,9 @@ public class QualityGateConditionDaoTest {
public void shouldCleanConditions() {
MetricDto enabledMetric = dbTester.measures().insertMetric(t -> t.setEnabled(true));
MetricDto disabledMetric = dbTester.measures().insertMetric(t -> t.setEnabled(false));
- QualityGateConditionDto condition1 = insertQGCondition(1L, enabledMetric.getId());
- QualityGateConditionDto condition2 = insertQGCondition(1L, disabledMetric.getId());
- QualityGateConditionDto condition3 = insertQGCondition(1L, 299);
+ QualityGateConditionDto condition1 = insertQGCondition(1L, enabledMetric.getUuid());
+ QualityGateConditionDto condition2 = insertQGCondition(1L, disabledMetric.getUuid());
+ QualityGateConditionDto condition3 = insertQGCondition(1L, "299");
underTest.deleteConditionsWithInvalidMetrics(dbTester.getSession());
dbTester.commit();
@@ -138,18 +138,18 @@ public class QualityGateConditionDaoTest {
}
private QualityGateConditionDto insertQGCondition(long qualityGateId) {
- return insertQGCondition(qualityGateId, new Random().nextInt(100));
+ return insertQGCondition(qualityGateId, randomAlphabetic(2));
}
- private QualityGateConditionDto insertQGCondition(long qualityGateId, int metricId) {
- return insertQGCondition(qualityGateId, metricId, randomAlphabetic(2), randomAlphabetic(3));
+ private QualityGateConditionDto insertQGCondition(long qualityGateId, String metricUuid) {
+ return insertQGCondition(qualityGateId, metricUuid, randomAlphabetic(2), randomAlphabetic(3));
}
- private QualityGateConditionDto insertQGCondition(long qualityGateId, long metricId, String operator, String threshold) {
+ private QualityGateConditionDto insertQGCondition(long qualityGateId, String metricUuid, String operator, String threshold) {
QualityGateConditionDto res = new QualityGateConditionDto()
.setUuid(Uuids.create())
.setQualityGateId(qualityGateId)
- .setMetricId(metricId)
+ .setMetricUuid(metricUuid)
.setOperator(operator)
.setErrorThreshold(threshold);
underTest.insert(res, dbTester.getSession());
@@ -159,7 +159,7 @@ public class QualityGateConditionDaoTest {
private void assertEquals(QualityGateConditionDto actual, QualityGateConditionDto expected) {
assertThat(actual.getQualityGateId()).isEqualTo(expected.getQualityGateId());
- assertThat(actual.getMetricId()).isEqualTo(expected.getMetricId());
+ assertThat(actual.getMetricUuid()).isEqualTo(expected.getMetricUuid());
assertThat(actual.getOperator()).isEqualTo(expected.getOperator());
assertThat(actual.getErrorThreshold()).isEqualTo(expected.getErrorThreshold());
}
diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/measure/MeasureDbTester.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/measure/MeasureDbTester.java
index 770ac10bba0..553e7252db8 100644
--- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/measure/MeasureDbTester.java
+++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/measure/MeasureDbTester.java
@@ -69,7 +69,7 @@ public class MeasureDbTester {
Preconditions.checkArgument(metricDto.isUserManaged(),"Custom measure must be created from a custom metric");
CustomMeasureDto dto = newCustomMeasureDto()
.setComponentUuid(component.uuid())
- .setMetricId(metricDto.getId());
+ .setMetricUuid(metricDto.getUuid());
if (user != null) {
dto.setUserUuid(user.getUuid());
}
diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/measure/MeasureTesting.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/measure/MeasureTesting.java
index 8e371c93692..b4cd54ea09b 100644
--- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/measure/MeasureTesting.java
+++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/measure/MeasureTesting.java
@@ -35,19 +35,19 @@ public class MeasureTesting {
}
public static MeasureDto newMeasureDto(MetricDto metricDto, ComponentDto component, SnapshotDto analysis) {
- checkNotNull(metricDto.getId());
+ checkNotNull(metricDto.getUuid());
checkNotNull(metricDto.getKey());
checkNotNull(component.uuid());
checkNotNull(analysis.getUuid());
return new MeasureDto()
- .setMetricId(metricDto.getId())
+ .setMetricUuid(metricDto.getUuid())
.setComponentUuid(component.uuid())
.setAnalysisUuid(analysis.getUuid());
}
public static MeasureDto newMeasure() {
return new MeasureDto()
- .setMetricId(cursor++)
+ .setMetricUuid(String.valueOf(cursor++))
.setComponentUuid(String.valueOf(cursor++))
.setAnalysisUuid(String.valueOf(cursor++))
.setData(String.valueOf(cursor++))
@@ -58,7 +58,7 @@ public class MeasureTesting {
public static LiveMeasureDto newLiveMeasure() {
return new LiveMeasureDto()
- .setMetricId(cursor++)
+ .setMetricUuid(String.valueOf(cursor++))
.setComponentUuid(String.valueOf(cursor++))
.setProjectUuid(String.valueOf(cursor++))
.setData(String.valueOf(cursor++))
@@ -68,7 +68,7 @@ public class MeasureTesting {
public static LiveMeasureDto newLiveMeasure(ComponentDto component, MetricDto metric) {
return new LiveMeasureDto()
- .setMetricId(metric.getId())
+ .setMetricUuid(metric.getUuid())
.setComponentUuid(component.uuid())
.setProjectUuid(component.projectUuid())
.setData(String.valueOf(cursor++))
diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/measure/custom/CustomMeasureTesting.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/measure/custom/CustomMeasureTesting.java
index 3b53e9c0a3e..9ce908c5891 100644
--- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/measure/custom/CustomMeasureTesting.java
+++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/measure/custom/CustomMeasureTesting.java
@@ -22,6 +22,7 @@ package org.sonar.db.measure.custom;
import org.apache.commons.lang.RandomStringUtils;
import org.apache.commons.lang.math.RandomUtils;
import org.sonar.api.utils.System2;
+import org.sonar.core.util.Uuids;
public class CustomMeasureTesting {
private CustomMeasureTesting() {
@@ -30,11 +31,12 @@ public class CustomMeasureTesting {
public static CustomMeasureDto newCustomMeasureDto() {
return new CustomMeasureDto()
+ .setUuid(Uuids.createFast())
.setDescription(RandomStringUtils.randomAlphanumeric(255))
.setTextValue(RandomStringUtils.randomAlphanumeric(255))
.setUserUuid("userUuid" + RandomStringUtils.randomAlphanumeric(100))
.setValue(RandomUtils.nextDouble())
- .setMetricId(RandomUtils.nextInt())
+ .setMetricUuid(RandomStringUtils.randomAlphanumeric(40))
.setComponentUuid(RandomStringUtils.randomAlphanumeric(50))
.setCreatedAt(System2.INSTANCE.now())
.setUpdatedAt(System2.INSTANCE.now());
diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/metric/MetricTesting.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/metric/MetricTesting.java
index 7c35222e23d..a1a65259f77 100644
--- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/metric/MetricTesting.java
+++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/metric/MetricTesting.java
@@ -31,7 +31,7 @@ public class MetricTesting {
public static MetricDto newMetricDto() {
Metric.ValueType[] metricTypes = Metric.ValueType.values();
return new MetricDto()
- .setId(RandomUtils.nextInt())
+ .setUuid(RandomStringUtils.randomAlphanumeric(40))
.setKey(RandomStringUtils.randomAlphanumeric(64))
.setShortName(RandomStringUtils.randomAlphanumeric(64))
.setValueType(metricTypes[RandomUtils.nextInt(metricTypes.length - 1)].name())
diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/qualitygate/QualityGateDbTester.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/qualitygate/QualityGateDbTester.java
index 1f49d797efb..68150491124 100644
--- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/qualitygate/QualityGateDbTester.java
+++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/qualitygate/QualityGateDbTester.java
@@ -95,7 +95,7 @@ public class QualityGateDbTester {
public final QualityGateConditionDto addCondition(QualityGateDto qualityGate, MetricDto metric, Consumer<QualityGateConditionDto>... dtoPopulators) {
QualityGateConditionDto condition = new QualityGateConditionDto().setQualityGateId(qualityGate.getId())
.setUuid(Uuids.createFast())
- .setMetricId(metric.getId())
+ .setMetricUuid(metric.getUuid())
.setOperator("GT")
.setErrorThreshold(randomNumeric(10));
Arrays.stream(dtoPopulators).forEach(dtoPopulator -> dtoPopulator.accept(condition));
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 d2e45c4e5be..3a958cd94fc 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
@@ -85,6 +85,32 @@ import org.sonar.server.platform.db.migration.version.v83.manualmeasures.DropIdC
import org.sonar.server.platform.db.migration.version.v83.manualmeasures.DropPrimaryKeyOnIdColumnOfManualMeasuresTable;
import org.sonar.server.platform.db.migration.version.v83.manualmeasures.MakeManualMeasuresUuidColumnNotNullable;
import org.sonar.server.platform.db.migration.version.v83.manualmeasures.PopulateManualMeasureUuid;
+import org.sonar.server.platform.db.migration.version.v83.metrics.AddPrimaryKeyOnUuidColumnOfMetricsTable;
+import org.sonar.server.platform.db.migration.version.v83.metrics.AddUuidColumnToMetricsTable;
+import org.sonar.server.platform.db.migration.version.v83.metrics.DropIdColumnOfMetricsTable;
+import org.sonar.server.platform.db.migration.version.v83.metrics.DropPrimaryKeyOnIdColumnOfMetricsTable;
+import org.sonar.server.platform.db.migration.version.v83.metrics.MakeMetricsUuidColumnNotNullable;
+import org.sonar.server.platform.db.migration.version.v83.metrics.PopulateMetricsUuid;
+import org.sonar.server.platform.db.migration.version.v83.metrics.livemeasures.AddIndexOnMetricUuidOfLiveMeasuresTable;
+import org.sonar.server.platform.db.migration.version.v83.metrics.livemeasures.AddMetricUuidColumnToLiveMeasures;
+import org.sonar.server.platform.db.migration.version.v83.metrics.livemeasures.DropIndexOnMetricIdOfLiveMeasuresTable;
+import org.sonar.server.platform.db.migration.version.v83.metrics.livemeasures.DropMetricIdColumnOfLiveMeasuresTable;
+import org.sonar.server.platform.db.migration.version.v83.metrics.livemeasures.MakeLiveMeasuresMetricUuidNotNullable;
+import org.sonar.server.platform.db.migration.version.v83.metrics.livemeasures.PopulateLiveMeasuresMetricUuid;
+import org.sonar.server.platform.db.migration.version.v83.metrics.manualmeasures.AddMetricUuidColumnToManualMeasures;
+import org.sonar.server.platform.db.migration.version.v83.metrics.manualmeasures.DropMetricIdColumnOfManualMeasuresTable;
+import org.sonar.server.platform.db.migration.version.v83.metrics.manualmeasures.MakeManualMeasuresMetricUuidNotNullable;
+import org.sonar.server.platform.db.migration.version.v83.metrics.manualmeasures.PopulateManualMeasuresMetricUuid;
+import org.sonar.server.platform.db.migration.version.v83.metrics.projectmeasures.AddIndexOnMetricUuidOfProjectMeasuresTable;
+import org.sonar.server.platform.db.migration.version.v83.metrics.projectmeasures.AddMetricUuidColumnToProjectMeasures;
+import org.sonar.server.platform.db.migration.version.v83.metrics.projectmeasures.DropIndexOnMetricIdOfProjectMeasuresTable;
+import org.sonar.server.platform.db.migration.version.v83.metrics.projectmeasures.DropMetricIdColumnOfProjectMeasuresTable;
+import org.sonar.server.platform.db.migration.version.v83.metrics.projectmeasures.MakeProjectMeasuresMetricUuidNotNullable;
+import org.sonar.server.platform.db.migration.version.v83.metrics.projectmeasures.PopulateProjectMeasuresMetricUuid;
+import org.sonar.server.platform.db.migration.version.v83.metrics.qualitygateconditions.AddMetricUuidColumnToQualityGateConditions;
+import org.sonar.server.platform.db.migration.version.v83.metrics.qualitygateconditions.DropMetricIdColumnOfQualityGateConditionsTable;
+import org.sonar.server.platform.db.migration.version.v83.metrics.qualitygateconditions.MakeQualityGateConditionsMetricUuidNotNullable;
+import org.sonar.server.platform.db.migration.version.v83.metrics.qualitygateconditions.PopulateQualityGateConditionsMetricUuid;
import org.sonar.server.platform.db.migration.version.v83.notifications.AddPrimaryKeyOnUuidColumnOfNotificationTable;
import org.sonar.server.platform.db.migration.version.v83.notifications.AddUuidAndCreatedAtColumnsToNotification;
import org.sonar.server.platform.db.migration.version.v83.notifications.DropIdColumnOfNotificationTable;
@@ -356,6 +382,44 @@ public class DbVersion83 implements DbVersion {
.add(3526, "Add primary key on 'UUID' column of 'RULES_PARAMETERS' table", AddPrimaryKeyOnUuidColumnOfRulesParametersTable.class)
.add(3527, "Drop column 'ID' of 'RULES_PARAMETERS' table", DropIdColumnOfRulesParametersTable.class)
+ // Migration of METRICS table
+ .add(3528, "Add 'UUID' column on 'METRICS' table", AddUuidColumnToMetricsTable.class)
+ .add(3529, "Populate 'uuid' for 'METRICS'", PopulateMetricsUuid.class)
+ .add(3530, "Make 'uuid' column not nullable for 'METRICS'", MakeMetricsUuidColumnNotNullable.class)
+
+ // Migration of FK in PROJECT_MEASURES to METRICS
+ .add(3531, "Add 'metric_uuid' column on 'PROJECT_MEASURES' table", AddMetricUuidColumnToProjectMeasures.class)
+ .add(3532, "Populate 'metric_uuid' for 'PROJECT_MEASURES'", PopulateProjectMeasuresMetricUuid.class)
+ .add(3533, "Make 'metric_uuid' column not nullable for 'PROJECT_MEASURES'", MakeProjectMeasuresMetricUuidNotNullable.class)
+ .add(3534, "Drop index on 'metric_id' and 'analysis_uuid' columns of 'PROJECT_MEASURES' table", DropIndexOnMetricIdOfProjectMeasuresTable.class)
+ .add(3535, "Add index on 'metric_uuid' and 'analysis_uuid' columns of 'PROJECT_MEASURES' table", AddIndexOnMetricUuidOfProjectMeasuresTable.class)
+
+ // Migration of FK in QUALITY_GATE_CONDITIONS to METRICS
+ .add(3536, "Add 'metric_uuid' column on 'QUALITY_GATE_CONDITIONS' table", AddMetricUuidColumnToQualityGateConditions.class)
+ .add(3537, "Populate 'metric_uuid' for 'QUALITY_GATE_CONDITIONS'", PopulateQualityGateConditionsMetricUuid.class)
+ .add(3538, "Make 'metric_uuid' column not nullable for 'QUALITY_GATE_CONDITIONS'", MakeQualityGateConditionsMetricUuidNotNullable.class)
+
+ // Migration of FK in LIVE_MEASURES to METRICS
+ .add(3539, "Add 'metric_uuid' column on 'LIVE_MEASURES' table", AddMetricUuidColumnToLiveMeasures.class)
+ .add(3540, "Populate 'metric_uuid' for 'LIVE_MEASURES'", PopulateLiveMeasuresMetricUuid.class)
+ .add(3541, "Make 'metric_uuid' column not nullable for 'LIVE_MEASURES'", MakeLiveMeasuresMetricUuidNotNullable.class)
+ .add(3542, "Drop index on 'metric_id' column of 'LIVE_MEASURES' table", DropIndexOnMetricIdOfLiveMeasuresTable.class)
+ .add(3543, "Add index on 'metric_uuid' column of 'LIVE_MEASURES' table", AddIndexOnMetricUuidOfLiveMeasuresTable.class)
+
+ // Migration of FK in MANUAL_MEASURES to METRICS
+ .add(3544, "Add 'metric_uuid' column on 'MANUAL_MEASURES' table", AddMetricUuidColumnToManualMeasures.class)
+ .add(3545, "Populate 'metric_uuid' for 'MANUAL_MEASURES'", PopulateManualMeasuresMetricUuid.class)
+ .add(3546, "Make 'metric_uuid' column not nullable for 'MANUAL_MEASURES'", MakeManualMeasuresMetricUuidNotNullable.class)
+
+ // Finish migration of METRICS
+ .add(3547, "Drop primary key on 'ID' column of 'METRICS' table", DropPrimaryKeyOnIdColumnOfMetricsTable.class)
+ .add(3548, "Add primary key on 'UUID' column of 'METRICS' table", AddPrimaryKeyOnUuidColumnOfMetricsTable.class)
+ .add(3549, "Drop column 'METRIC_ID' of 'PROJECT_MEASURES' table", DropMetricIdColumnOfProjectMeasuresTable.class)
+ .add(3550, "Drop column 'METRIC_ID' of 'QUALITY_GATE_CONDITIONS' table", DropMetricIdColumnOfQualityGateConditionsTable.class)
+ .add(3551, "Drop column 'METRIC_ID' of 'LIVE_MEASURES' table", DropMetricIdColumnOfLiveMeasuresTable.class)
+ .add(3552, "Drop column 'METRIC_ID' of 'MANUAL_MEASURES' table", DropMetricIdColumnOfManualMeasuresTable.class)
+ .add(3553, "Drop column 'ID' of 'METRICS' table", DropIdColumnOfMetricsTable.class)
+
;
}
}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/AddPrimaryKeyOnUuidColumnOfMetricsTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/AddPrimaryKeyOnUuidColumnOfMetricsTable.java
new file mode 100644
index 00000000000..652dc701a80
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/AddPrimaryKeyOnUuidColumnOfMetricsTable.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.metrics;
+
+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 AddPrimaryKeyOnUuidColumnOfMetricsTable extends DdlChange {
+
+ public AddPrimaryKeyOnUuidColumnOfMetricsTable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new AddPrimaryKeyBuilder("metrics", "uuid").build());
+ }
+
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/AddUuidColumnToMetricsTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/AddUuidColumnToMetricsTable.java
new file mode 100644
index 00000000000..9e13d3e5bed
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/AddUuidColumnToMetricsTable.java
@@ -0,0 +1,31 @@
+/*
+ * 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.metrics;
+
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.version.v83.common.AddUuidColumnToTable;
+
+public class AddUuidColumnToMetricsTable extends AddUuidColumnToTable {
+ private static final String TABLE = "metrics";
+
+ public AddUuidColumnToMetricsTable(Database db) {
+ super(db, TABLE);
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/DropIdColumnOfMetricsTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/DropIdColumnOfMetricsTable.java
new file mode 100644
index 00000000000..7bce5f8109d
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/DropIdColumnOfMetricsTable.java
@@ -0,0 +1,31 @@
+/*
+ * 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.metrics;
+
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.version.v83.common.DropIdColumn;
+
+public class DropIdColumnOfMetricsTable extends DropIdColumn {
+ private static final String TABLE = "metrics";
+
+ public DropIdColumnOfMetricsTable(Database db) {
+ super(db, TABLE);
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/DropPrimaryKeyOnIdColumnOfMetricsTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/DropPrimaryKeyOnIdColumnOfMetricsTable.java
new file mode 100644
index 00000000000..9f09c27d7db
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/DropPrimaryKeyOnIdColumnOfMetricsTable.java
@@ -0,0 +1,32 @@
+/*
+ * 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.metrics;
+
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.version.v83.common.DropPrimaryKeyOnIdColumn;
+import org.sonar.server.platform.db.migration.version.v83.util.DropPrimaryKeySqlGenerator;
+
+public class DropPrimaryKeyOnIdColumnOfMetricsTable extends DropPrimaryKeyOnIdColumn {
+ private static final String TABLE_NAME = "metrics";
+
+ public DropPrimaryKeyOnIdColumnOfMetricsTable(Database db, DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator) {
+ super(db, dropPrimaryKeySqlGenerator, TABLE_NAME);
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/MakeMetricsUuidColumnNotNullable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/MakeMetricsUuidColumnNotNullable.java
new file mode 100644
index 00000000000..af417536dc3
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/MakeMetricsUuidColumnNotNullable.java
@@ -0,0 +1,31 @@
+/*
+ * 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.metrics;
+
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.version.v83.common.MakeUuidColumnNotNullable;
+
+public class MakeMetricsUuidColumnNotNullable extends MakeUuidColumnNotNullable {
+ private static final String TABLE = "metrics";
+
+ public MakeMetricsUuidColumnNotNullable(Database db) {
+ super(db, TABLE);
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/PopulateMetricsUuid.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/PopulateMetricsUuid.java
new file mode 100644
index 00000000000..0edcee2caf6
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/PopulateMetricsUuid.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.metrics;
+
+import java.sql.SQLException;
+import org.sonar.core.util.UuidFactory;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.step.DataChange;
+import org.sonar.server.platform.db.migration.step.MassUpdate;
+
+public class PopulateMetricsUuid extends DataChange {
+
+ private final UuidFactory uuidFactory;
+
+ public PopulateMetricsUuid(Database db, UuidFactory uuidFactory) {
+ super(db);
+ this.uuidFactory = uuidFactory;
+ }
+
+ @Override
+ protected void execute(Context context) throws SQLException {
+ MassUpdate massUpdate = context.prepareMassUpdate();
+
+ massUpdate.select("select id from metrics where uuid is null order by id asc");
+ massUpdate.update("update metrics set uuid = ? where id = ?");
+
+ massUpdate.execute((row, update) -> {
+ update.setString(1, uuidFactory.create());
+ update.setLong(2, row.getLong(1));
+ return true;
+ });
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/livemeasures/AddIndexOnMetricUuidOfLiveMeasuresTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/livemeasures/AddIndexOnMetricUuidOfLiveMeasuresTable.java
new file mode 100644
index 00000000000..90f04d52594
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/livemeasures/AddIndexOnMetricUuidOfLiveMeasuresTable.java
@@ -0,0 +1,66 @@
+/*
+ * 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.metrics.livemeasures;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.db.DatabaseUtils;
+import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
+import org.sonar.server.platform.db.migration.sql.CreateIndexBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
+
+public class AddIndexOnMetricUuidOfLiveMeasuresTable extends DdlChange {
+ private static final String TABLE_NAME = "live_measures";
+ private static final String INDEX_NAME = "live_measures_component";
+
+ public AddIndexOnMetricUuidOfLiveMeasuresTable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ if (!indexExists()) {
+ context.execute(new CreateIndexBuilder()
+ .setUnique(true)
+ .setTable(TABLE_NAME)
+ .setName(INDEX_NAME)
+ .addColumn(newVarcharColumnDefBuilder()
+ .setColumnName("component_uuid")
+ .setIsNullable(false)
+ .setLimit(VarcharColumnDef.UUID_SIZE)
+ .build())
+ .addColumn(newVarcharColumnDefBuilder()
+ .setColumnName("metric_uuid")
+ .setIsNullable(false)
+ .setLimit(VarcharColumnDef.UUID_SIZE)
+ .build())
+ .build());
+ }
+ }
+
+ private boolean indexExists() throws SQLException {
+ try (Connection connection = getDatabase().getDataSource().getConnection()) {
+ return DatabaseUtils.indexExists(TABLE_NAME, INDEX_NAME, connection);
+ }
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/livemeasures/AddMetricUuidColumnToLiveMeasures.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/livemeasures/AddMetricUuidColumnToLiveMeasures.java
new file mode 100644
index 00000000000..b0c3d41ac31
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/livemeasures/AddMetricUuidColumnToLiveMeasures.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.metrics.livemeasures;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
+import org.sonar.server.platform.db.migration.sql.AddColumnsBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
+
+public class AddMetricUuidColumnToLiveMeasures extends DdlChange {
+ private static final String TABLE = "live_measures";
+
+ private static final VarcharColumnDef uuidColumnDefinition = newVarcharColumnDefBuilder()
+ .setColumnName("metric_uuid")
+ .setIsNullable(true)
+ .setDefaultValue(null)
+ .setLimit(VarcharColumnDef.UUID_SIZE)
+ .build();
+
+ public AddMetricUuidColumnToLiveMeasures(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new AddColumnsBuilder(getDialect(), TABLE)
+ .addColumn(uuidColumnDefinition)
+ .build());
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/livemeasures/DropIndexOnMetricIdOfLiveMeasuresTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/livemeasures/DropIndexOnMetricIdOfLiveMeasuresTable.java
new file mode 100644
index 00000000000..3c1b5aa964d
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/livemeasures/DropIndexOnMetricIdOfLiveMeasuresTable.java
@@ -0,0 +1,52 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v83.metrics.livemeasures;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.db.DatabaseUtils;
+import org.sonar.server.platform.db.migration.sql.DropIndexBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+public class DropIndexOnMetricIdOfLiveMeasuresTable extends DdlChange {
+ private static final String TABLE_NAME = "live_measures";
+ private static final String INDEX_NAME = "live_measures_component";
+
+ public DropIndexOnMetricIdOfLiveMeasuresTable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ if (indexExists()) {
+ context.execute(new DropIndexBuilder(getDialect())
+ .setTable(TABLE_NAME)
+ .setName(INDEX_NAME)
+ .build());
+ }
+ }
+
+ private boolean indexExists() throws SQLException {
+ try (Connection connection = getDatabase().getDataSource().getConnection()) {
+ return DatabaseUtils.indexExists(TABLE_NAME, INDEX_NAME, connection);
+ }
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/livemeasures/DropMetricIdColumnOfLiveMeasuresTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/livemeasures/DropMetricIdColumnOfLiveMeasuresTable.java
new file mode 100644
index 00000000000..619cb040b9d
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/livemeasures/DropMetricIdColumnOfLiveMeasuresTable.java
@@ -0,0 +1,36 @@
+/*
+ * 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.metrics.livemeasures;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.DropColumnsBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+public class DropMetricIdColumnOfLiveMeasuresTable extends DdlChange {
+ public DropMetricIdColumnOfLiveMeasuresTable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new DropColumnsBuilder(getDialect(), "live_measures", "metric_id").build());
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/livemeasures/MakeLiveMeasuresMetricUuidNotNullable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/livemeasures/MakeLiveMeasuresMetricUuidNotNullable.java
new file mode 100644
index 00000000000..3d34e113e83
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/livemeasures/MakeLiveMeasuresMetricUuidNotNullable.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.metrics.livemeasures;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
+import org.sonar.server.platform.db.migration.sql.AlterColumnsBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
+
+public class MakeLiveMeasuresMetricUuidNotNullable extends DdlChange {
+ private static final String TABLE = "live_measures";
+
+ private static final VarcharColumnDef uuidColumnDefinition = newVarcharColumnDefBuilder()
+ .setColumnName("metric_uuid")
+ .setIsNullable(false)
+ .setDefaultValue(null)
+ .setLimit(VarcharColumnDef.UUID_SIZE)
+ .build();
+
+ public MakeLiveMeasuresMetricUuidNotNullable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new AlterColumnsBuilder(getDialect(), TABLE)
+ .updateColumn(uuidColumnDefinition)
+ .build());
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/livemeasures/PopulateLiveMeasuresMetricUuid.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/livemeasures/PopulateLiveMeasuresMetricUuid.java
new file mode 100644
index 00000000000..c977afa369f
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/livemeasures/PopulateLiveMeasuresMetricUuid.java
@@ -0,0 +1,49 @@
+/*
+ * 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.metrics.livemeasures;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.step.DataChange;
+import org.sonar.server.platform.db.migration.step.MassUpdate;
+
+public class PopulateLiveMeasuresMetricUuid extends DataChange {
+
+ public PopulateLiveMeasuresMetricUuid(Database db) {
+ super(db);
+ }
+
+ @Override
+ protected void execute(Context context) throws SQLException {
+ MassUpdate massUpdate = context.prepareMassUpdate();
+
+ massUpdate.select("select lm.uuid, m.uuid " +
+ "from live_measures lm " +
+ "join metrics m on lm.metric_id = m.id");
+
+ massUpdate.update("update live_measures set metric_uuid = ? where uuid = ?");
+
+ massUpdate.execute((row, update) -> {
+ update.setString(1, row.getString(2));
+ update.setString(2, row.getString(1));
+ return true;
+ });
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/manualmeasures/AddMetricUuidColumnToManualMeasures.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/manualmeasures/AddMetricUuidColumnToManualMeasures.java
new file mode 100644
index 00000000000..d4e87a84671
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/manualmeasures/AddMetricUuidColumnToManualMeasures.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.metrics.manualmeasures;
+
+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 AddMetricUuidColumnToManualMeasures extends DdlChange {
+ private static final String TABLE = "manual_measures";
+
+ private static final VarcharColumnDef uuidColumnDefinition = newVarcharColumnDefBuilder()
+ .setColumnName("metric_uuid")
+ .setIsNullable(true)
+ .setDefaultValue(null)
+ .setLimit(VarcharColumnDef.UUID_SIZE)
+ .build();
+
+ public AddMetricUuidColumnToManualMeasures(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/metrics/manualmeasures/DropMetricIdColumnOfManualMeasuresTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/manualmeasures/DropMetricIdColumnOfManualMeasuresTable.java
new file mode 100644
index 00000000000..1685a2af332
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/manualmeasures/DropMetricIdColumnOfManualMeasuresTable.java
@@ -0,0 +1,36 @@
+/*
+ * 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.metrics.manualmeasures;
+
+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 DropMetricIdColumnOfManualMeasuresTable extends DdlChange {
+ public DropMetricIdColumnOfManualMeasuresTable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new DropColumnsBuilder(getDialect(), "manual_measures", "metric_id").build());
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/manualmeasures/MakeManualMeasuresMetricUuidNotNullable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/manualmeasures/MakeManualMeasuresMetricUuidNotNullable.java
new file mode 100644
index 00000000000..49b011f9f40
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/manualmeasures/MakeManualMeasuresMetricUuidNotNullable.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.metrics.manualmeasures;
+
+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 MakeManualMeasuresMetricUuidNotNullable extends DdlChange {
+ private static final String TABLE = "manual_measures";
+
+ private static final VarcharColumnDef uuidColumnDefinition = newVarcharColumnDefBuilder()
+ .setColumnName("metric_uuid")
+ .setIsNullable(false)
+ .setDefaultValue(null)
+ .setLimit(VarcharColumnDef.UUID_SIZE)
+ .build();
+
+ public MakeManualMeasuresMetricUuidNotNullable(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/metrics/manualmeasures/PopulateManualMeasuresMetricUuid.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/manualmeasures/PopulateManualMeasuresMetricUuid.java
new file mode 100644
index 00000000000..b3277075f29
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/manualmeasures/PopulateManualMeasuresMetricUuid.java
@@ -0,0 +1,49 @@
+/*
+ * 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.metrics.manualmeasures;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.step.DataChange;
+import org.sonar.server.platform.db.migration.step.MassUpdate;
+
+public class PopulateManualMeasuresMetricUuid extends DataChange {
+
+ public PopulateManualMeasuresMetricUuid(Database db) {
+ super(db);
+ }
+
+ @Override
+ protected void execute(Context context) throws SQLException {
+ MassUpdate massUpdate = context.prepareMassUpdate();
+
+ massUpdate.select("select mm.uuid, m.uuid " +
+ "from manual_measures mm " +
+ "join metrics m on mm.metric_id = m.id");
+
+ massUpdate.update("update manual_measures set metric_uuid = ? where uuid = ?");
+
+ massUpdate.execute((row, update) -> {
+ update.setString(1, row.getString(2));
+ update.setString(2, row.getString(1));
+ return true;
+ });
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/projectmeasures/AddIndexOnMetricUuidOfProjectMeasuresTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/projectmeasures/AddIndexOnMetricUuidOfProjectMeasuresTable.java
new file mode 100644
index 00000000000..96d783e7aab
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/projectmeasures/AddIndexOnMetricUuidOfProjectMeasuresTable.java
@@ -0,0 +1,66 @@
+/*
+ * 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.metrics.projectmeasures;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.db.DatabaseUtils;
+import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
+import org.sonar.server.platform.db.migration.sql.CreateIndexBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
+
+public class AddIndexOnMetricUuidOfProjectMeasuresTable extends DdlChange {
+ private static final String TABLE_NAME = "project_measures";
+ private static final String INDEX_NAME = "measures_analysis_metric";
+
+ public AddIndexOnMetricUuidOfProjectMeasuresTable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ if (!indexExists()) {
+ context.execute(new CreateIndexBuilder()
+ .setUnique(false)
+ .setTable(TABLE_NAME)
+ .setName(INDEX_NAME)
+ .addColumn(newVarcharColumnDefBuilder()
+ .setColumnName("analysis_uuid")
+ .setIsNullable(false)
+ .setLimit(VarcharColumnDef.UUID_SIZE)
+ .build())
+ .addColumn(newVarcharColumnDefBuilder()
+ .setColumnName("metric_uuid")
+ .setIsNullable(false)
+ .setLimit(VarcharColumnDef.UUID_SIZE)
+ .build())
+ .build());
+ }
+ }
+
+ private boolean indexExists() throws SQLException {
+ try (Connection connection = getDatabase().getDataSource().getConnection()) {
+ return DatabaseUtils.indexExists(TABLE_NAME, INDEX_NAME, connection);
+ }
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/projectmeasures/AddMetricUuidColumnToProjectMeasures.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/projectmeasures/AddMetricUuidColumnToProjectMeasures.java
new file mode 100644
index 00000000000..168917b237f
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/projectmeasures/AddMetricUuidColumnToProjectMeasures.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.metrics.projectmeasures;
+
+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 AddMetricUuidColumnToProjectMeasures extends DdlChange {
+ private static final String TABLE = "project_measures";
+
+ private static final VarcharColumnDef uuidColumnDefinition = newVarcharColumnDefBuilder()
+ .setColumnName("metric_uuid")
+ .setIsNullable(true)
+ .setDefaultValue(null)
+ .setLimit(VarcharColumnDef.UUID_SIZE)
+ .build();
+
+ public AddMetricUuidColumnToProjectMeasures(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/metrics/projectmeasures/DropIndexOnMetricIdOfProjectMeasuresTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/projectmeasures/DropIndexOnMetricIdOfProjectMeasuresTable.java
new file mode 100644
index 00000000000..c96583078af
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/projectmeasures/DropIndexOnMetricIdOfProjectMeasuresTable.java
@@ -0,0 +1,52 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v83.metrics.projectmeasures;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.db.DatabaseUtils;
+import org.sonar.server.platform.db.migration.sql.DropIndexBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+public class DropIndexOnMetricIdOfProjectMeasuresTable extends DdlChange {
+ private static final String TABLE_NAME = "project_measures";
+ private static final String INDEX_NAME = "measures_analysis_metric";
+
+ public DropIndexOnMetricIdOfProjectMeasuresTable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ if (indexExists()) {
+ context.execute(new DropIndexBuilder(getDialect())
+ .setTable(TABLE_NAME)
+ .setName(INDEX_NAME)
+ .build());
+ }
+ }
+
+ private boolean indexExists() throws SQLException {
+ try (Connection connection = getDatabase().getDataSource().getConnection()) {
+ return DatabaseUtils.indexExists(TABLE_NAME, INDEX_NAME, connection);
+ }
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/projectmeasures/DropMetricIdColumnOfProjectMeasuresTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/projectmeasures/DropMetricIdColumnOfProjectMeasuresTable.java
new file mode 100644
index 00000000000..2d3787da147
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/projectmeasures/DropMetricIdColumnOfProjectMeasuresTable.java
@@ -0,0 +1,36 @@
+/*
+ * 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.metrics.projectmeasures;
+
+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 DropMetricIdColumnOfProjectMeasuresTable extends DdlChange {
+ public DropMetricIdColumnOfProjectMeasuresTable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new DropColumnsBuilder(getDialect(), "project_measures", "metric_id").build());
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/projectmeasures/MakeProjectMeasuresMetricUuidNotNullable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/projectmeasures/MakeProjectMeasuresMetricUuidNotNullable.java
new file mode 100644
index 00000000000..4f2aeac199f
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/projectmeasures/MakeProjectMeasuresMetricUuidNotNullable.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.metrics.projectmeasures;
+
+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 MakeProjectMeasuresMetricUuidNotNullable extends DdlChange {
+ private static final String TABLE = "project_measures";
+
+ private static final VarcharColumnDef uuidColumnDefinition = newVarcharColumnDefBuilder()
+ .setColumnName("metric_uuid")
+ .setIsNullable(false)
+ .setDefaultValue(null)
+ .setLimit(VarcharColumnDef.UUID_SIZE)
+ .build();
+
+ public MakeProjectMeasuresMetricUuidNotNullable(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/metrics/projectmeasures/PopulateProjectMeasuresMetricUuid.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/projectmeasures/PopulateProjectMeasuresMetricUuid.java
new file mode 100644
index 00000000000..389e4a28bd8
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/projectmeasures/PopulateProjectMeasuresMetricUuid.java
@@ -0,0 +1,49 @@
+/*
+ * 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.metrics.projectmeasures;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.step.DataChange;
+import org.sonar.server.platform.db.migration.step.MassUpdate;
+
+public class PopulateProjectMeasuresMetricUuid extends DataChange {
+
+ public PopulateProjectMeasuresMetricUuid(Database db) {
+ super(db);
+ }
+
+ @Override
+ protected void execute(Context context) throws SQLException {
+ MassUpdate massUpdate = context.prepareMassUpdate();
+
+ massUpdate.select("select pm.uuid, m.uuid " +
+ "from project_measures pm " +
+ "join metrics m on pm.metric_id = m.id");
+
+ massUpdate.update("update project_measures set metric_uuid = ? where uuid = ?");
+
+ massUpdate.execute((row, update) -> {
+ update.setString(1, row.getString(2));
+ update.setString(2, row.getString(1));
+ return true;
+ });
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/qualitygateconditions/AddMetricUuidColumnToQualityGateConditions.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/qualitygateconditions/AddMetricUuidColumnToQualityGateConditions.java
new file mode 100644
index 00000000000..89c47a84a0a
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/qualitygateconditions/AddMetricUuidColumnToQualityGateConditions.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.metrics.qualitygateconditions;
+
+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 AddMetricUuidColumnToQualityGateConditions extends DdlChange {
+ private static final String TABLE = "quality_gate_conditions";
+
+ private static final VarcharColumnDef uuidColumnDefinition = newVarcharColumnDefBuilder()
+ .setColumnName("metric_uuid")
+ .setIsNullable(true)
+ .setDefaultValue(null)
+ .setLimit(VarcharColumnDef.UUID_SIZE)
+ .build();
+
+ public AddMetricUuidColumnToQualityGateConditions(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/metrics/qualitygateconditions/DropMetricIdColumnOfQualityGateConditionsTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/qualitygateconditions/DropMetricIdColumnOfQualityGateConditionsTable.java
new file mode 100644
index 00000000000..2e1613300f8
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/qualitygateconditions/DropMetricIdColumnOfQualityGateConditionsTable.java
@@ -0,0 +1,36 @@
+/*
+ * 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.metrics.qualitygateconditions;
+
+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 DropMetricIdColumnOfQualityGateConditionsTable extends DdlChange {
+ public DropMetricIdColumnOfQualityGateConditionsTable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new DropColumnsBuilder(getDialect(), "quality_gate_conditions", "metric_id").build());
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/qualitygateconditions/MakeQualityGateConditionsMetricUuidNotNullable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/qualitygateconditions/MakeQualityGateConditionsMetricUuidNotNullable.java
new file mode 100644
index 00000000000..c853fe66c5c
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/qualitygateconditions/MakeQualityGateConditionsMetricUuidNotNullable.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.metrics.qualitygateconditions;
+
+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 MakeQualityGateConditionsMetricUuidNotNullable extends DdlChange {
+ private static final String TABLE = "quality_gate_conditions";
+
+ private static final VarcharColumnDef uuidColumnDefinition = newVarcharColumnDefBuilder()
+ .setColumnName("metric_uuid")
+ .setIsNullable(false)
+ .setDefaultValue(null)
+ .setLimit(VarcharColumnDef.UUID_SIZE)
+ .build();
+
+ public MakeQualityGateConditionsMetricUuidNotNullable(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/metrics/qualitygateconditions/PopulateQualityGateConditionsMetricUuid.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/qualitygateconditions/PopulateQualityGateConditionsMetricUuid.java
new file mode 100644
index 00000000000..7cf55ffd7af
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/metrics/qualitygateconditions/PopulateQualityGateConditionsMetricUuid.java
@@ -0,0 +1,52 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v83.metrics.qualitygateconditions;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.step.DataChange;
+import org.sonar.server.platform.db.migration.step.MassUpdate;
+
+public class PopulateQualityGateConditionsMetricUuid extends DataChange {
+
+ public PopulateQualityGateConditionsMetricUuid(Database db) {
+ super(db);
+ }
+
+ @Override
+ protected void execute(Context context) throws SQLException {
+ // delete quality gate conditions without a metric
+ context.prepareUpsert("delete from quality_gate_conditions where metric_id is null").execute();
+
+ MassUpdate massUpdate = context.prepareMassUpdate();
+
+ massUpdate.select("select qgc.uuid, m.uuid " +
+ "from quality_gate_conditions qgc " +
+ "join metrics m on qgc.metric_id = m.id");
+
+ massUpdate.update("update quality_gate_conditions set metric_uuid = ? where uuid = ?");
+
+ massUpdate.execute((row, update) -> {
+ update.setString(1, row.getString(2));
+ update.setString(2, row.getString(1));
+ return true;
+ });
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/AddPrimaryKeyOnUuidColumnOfMetricsTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/AddPrimaryKeyOnUuidColumnOfMetricsTableTest.java
new file mode 100644
index 00000000000..e8f60edb48f
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/AddPrimaryKeyOnUuidColumnOfMetricsTableTest.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.metrics;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+public class AddPrimaryKeyOnUuidColumnOfMetricsTableTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(AddPrimaryKeyOnUuidColumnOfMetricsTableTest.class, "schema.sql");
+
+ private DdlChange underTest = new AddPrimaryKeyOnUuidColumnOfMetricsTable(db.database());
+
+ @Test
+ public void execute() throws SQLException {
+ underTest.execute();
+
+ db.assertPrimaryKey("metrics", "pk_metrics", "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/metrics/AddUuidColumnToMetricsTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/AddUuidColumnToMetricsTableTest.java
new file mode 100644
index 00000000000..a2478609fd2
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/AddUuidColumnToMetricsTableTest.java
@@ -0,0 +1,60 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v83.metrics;
+
+import java.sql.SQLException;
+import java.sql.Types;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class AddUuidColumnToMetricsTableTest {
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(AddUuidColumnToMetricsTableTest.class, "schema.sql");
+ private DdlChange underTest = new AddUuidColumnToMetricsTable(db.database());
+
+ @Before
+ public void setup() {
+ insertMetric(1L);
+ insertMetric(2L);
+ insertMetric(3L);
+ }
+
+ @Test
+ public void add_uuid_column() throws SQLException {
+ underTest.execute();
+
+ db.assertColumnDefinition("metrics", "uuid", Types.VARCHAR, 40, true);
+
+ assertThat(db.countRowsOfTable("metrics"))
+ .isEqualTo(3);
+ }
+
+ private void insertMetric(Long id) {
+ db.executeInsert("metrics",
+ "id", id,
+ "name", "name" + id);
+ }
+
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/DropIdColumnOfMetricsTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/DropIdColumnOfMetricsTableTest.java
new file mode 100644
index 00000000000..36a53eb5c78
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/DropIdColumnOfMetricsTableTest.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.metrics;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+public class DropIdColumnOfMetricsTableTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(DropIdColumnOfMetricsTableTest.class, "schema.sql");
+
+ private DdlChange underTest = new DropIdColumnOfMetricsTable(db.database());
+
+ @Test
+ public void execute() throws SQLException {
+ underTest.execute();
+
+ db.assertColumnDoesNotExist("metrics", "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/metrics/DropPrimaryKeyOnIdColumnOfMetricsTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/DropPrimaryKeyOnIdColumnOfMetricsTableTest.java
new file mode 100644
index 00000000000..d3c1fc90e9c
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/DropPrimaryKeyOnIdColumnOfMetricsTableTest.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.metrics;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+import org.sonar.server.platform.db.migration.version.v83.util.DropPrimaryKeySqlGenerator;
+import org.sonar.server.platform.db.migration.version.v83.util.SqlHelper;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+public class DropPrimaryKeyOnIdColumnOfMetricsTableTest {
+
+ private static final String TABLE_NAME = "metrics";
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(DropPrimaryKeyOnIdColumnOfMetricsTableTest.class, "schema.sql");
+
+ private DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new SqlHelper(db.database()));
+
+ private DdlChange underTest = new DropPrimaryKeyOnIdColumnOfMetricsTable(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/metrics/MakeMetricsUuidColumnNotNullableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/MakeMetricsUuidColumnNotNullableTest.java
new file mode 100644
index 00000000000..72d7bc59961
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/MakeMetricsUuidColumnNotNullableTest.java
@@ -0,0 +1,42 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v83.metrics;
+
+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 MakeMetricsUuidColumnNotNullableTest {
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(MakeMetricsUuidColumnNotNullableTest.class, "schema.sql");
+
+ private MigrationStep underTest = new MakeMetricsUuidColumnNotNullable(db.database());
+
+ @Test
+ public void uuid_column_is_not_nullable() throws SQLException {
+ underTest.execute();
+
+ db.assertColumnDefinition("metrics", "uuid", VARCHAR, null, false);
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/PopulateMetricsUuidTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/PopulateMetricsUuidTest.java
new file mode 100644
index 00000000000..a34fc00c4dd
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/PopulateMetricsUuidTest.java
@@ -0,0 +1,79 @@
+/*
+ * 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.metrics;
+
+import java.sql.SQLException;
+import java.util.Objects;
+import java.util.stream.Collectors;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.core.util.UuidFactory;
+import org.sonar.core.util.UuidFactoryFast;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DataChange;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class PopulateMetricsUuidTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(PopulateMetricsUuidTest.class, "schema.sql");
+
+ private UuidFactory uuidFactory = UuidFactoryFast.getInstance();
+ private DataChange underTest = new PopulateMetricsUuid(db.database(), uuidFactory);
+
+ @Test
+ public void populate_uuids() throws SQLException {
+ insertMetric(1L);
+ insertMetric(2L);
+ insertMetric(3L);
+
+ underTest.execute();
+
+ verifyUuidsAreNotNull();
+ }
+
+ @Test
+ public void migration_is_reentrant() throws SQLException {
+ insertMetric(1L);
+ insertMetric(2L);
+ insertMetric(3L);
+
+ underTest.execute();
+ // re-entrant
+ underTest.execute();
+
+ verifyUuidsAreNotNull();
+ }
+
+ private void verifyUuidsAreNotNull() {
+ assertThat(db.select("select uuid from metrics")
+ .stream()
+ .map(row -> row.get("UUID"))
+ .filter(Objects::isNull)
+ .collect(Collectors.toList())).isEmpty();
+ }
+
+ private void insertMetric(Long id) {
+ db.executeInsert("metrics",
+ "id", id,
+ "name", "name" + id);
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/livemeasures/AddIndexOnMetricUuidOfLiveMeasuresTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/livemeasures/AddIndexOnMetricUuidOfLiveMeasuresTableTest.java
new file mode 100644
index 00000000000..9e4bf1d2566
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/livemeasures/AddIndexOnMetricUuidOfLiveMeasuresTableTest.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.metrics.livemeasures;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.MigrationStep;
+
+public class AddIndexOnMetricUuidOfLiveMeasuresTableTest {
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(AddIndexOnMetricUuidOfLiveMeasuresTableTest.class, "schema.sql");
+
+ private MigrationStep underTest = new AddIndexOnMetricUuidOfLiveMeasuresTable(db.database());
+
+ @Test
+ public void execute() throws SQLException {
+ underTest.execute();
+
+ db.assertUniqueIndex("live_measures", "live_measures_component", "component_uuid", "metric_uuid");
+ }
+
+ @Test
+ public void migration_is_re_entrant() throws SQLException {
+ underTest.execute();
+
+ // re-entrant
+ underTest.execute();
+
+ db.assertUniqueIndex("live_measures", "live_measures_component", "component_uuid", "metric_uuid");
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/livemeasures/AddMetricUuidColumnToLiveMeasuresTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/livemeasures/AddMetricUuidColumnToLiveMeasuresTest.java
new file mode 100644
index 00000000000..765421240c2
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/livemeasures/AddMetricUuidColumnToLiveMeasuresTest.java
@@ -0,0 +1,64 @@
+/*
+ * 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.metrics.livemeasures;
+
+import java.sql.SQLException;
+import java.sql.Types;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class AddMetricUuidColumnToLiveMeasuresTest {
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(AddMetricUuidColumnToLiveMeasuresTest.class, "schema.sql");
+ private DdlChange underTest = new AddMetricUuidColumnToLiveMeasures(db.database());
+
+ @Before
+ public void setup() {
+ insertLiveMeasure(1L);
+ insertLiveMeasure(2L);
+ insertLiveMeasure(3L);
+ }
+
+ @Test
+ public void add_active_rule_uuid_column() throws SQLException {
+ underTest.execute();
+
+ db.assertColumnDefinition("live_measures", "metric_uuid", Types.VARCHAR, 40, true);
+
+ assertThat(db.countRowsOfTable("live_measures"))
+ .isEqualTo(3);
+ }
+
+ private void insertLiveMeasure(Long id) {
+ db.executeInsert("live_measures",
+ "uuid", "uuid" + id,
+ "metric_id", id + 1,
+ "component_uuid", "component" + id,
+ "project_uuid", "project" + id + 2,
+ "created_at", id + 3,
+ "updated_at", id + 4
+ );
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/livemeasures/DropIndexOnMetricIdOfLiveMeasuresTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/livemeasures/DropIndexOnMetricIdOfLiveMeasuresTableTest.java
new file mode 100644
index 00000000000..f65a0732b83
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/livemeasures/DropIndexOnMetricIdOfLiveMeasuresTableTest.java
@@ -0,0 +1,54 @@
+/*
+ * 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.metrics.livemeasures;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.MigrationStep;
+
+public class DropIndexOnMetricIdOfLiveMeasuresTableTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(DropIndexOnMetricIdOfLiveMeasuresTableTest.class, "schema.sql");
+
+ private MigrationStep underTest = new DropIndexOnMetricIdOfLiveMeasuresTable(db.database());
+
+ @Test
+ public void execute() throws SQLException {
+ db.assertTableExists("live_measures");
+ db.assertUniqueIndex("live_measures", "live_measures_component", "component_uuid", "metric_id");
+
+ underTest.execute();
+
+ db.assertIndexDoesNotExist("live_measures", "live_measures_component");
+ }
+
+ @Test
+ public void migration_is_re_entrant() throws SQLException {
+ underTest.execute();
+
+ // re-entrant
+ underTest.execute();
+
+ db.assertIndexDoesNotExist("live_measures", "live_measures_component");
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/livemeasures/DropMetricIdColumnOfLiveMeasuresTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/livemeasures/DropMetricIdColumnOfLiveMeasuresTableTest.java
new file mode 100644
index 00000000000..f6d7b506d99
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/livemeasures/DropMetricIdColumnOfLiveMeasuresTableTest.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.metrics.livemeasures;
+
+import java.sql.SQLException;
+import java.sql.Types;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+public class DropMetricIdColumnOfLiveMeasuresTableTest {
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(DropMetricIdColumnOfLiveMeasuresTableTest.class, "schema.sql");
+
+ private DdlChange underTest = new DropMetricIdColumnOfLiveMeasuresTable(db.database());
+
+ @Test
+ public void execute() throws SQLException {
+ db.assertColumnDefinition("live_measures", "metric_id", Types.INTEGER, null, false);
+ underTest.execute();
+ db.assertColumnDoesNotExist("live_measures", "metric_id");
+ }
+
+ @Test
+ public void migration_is_not_re_entrant() throws SQLException {
+ underTest.execute();
+
+ assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class);
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/livemeasures/MakeLiveMeasuresMetricUuidNotNullableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/livemeasures/MakeLiveMeasuresMetricUuidNotNullableTest.java
new file mode 100644
index 00000000000..38c45d9f490
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/livemeasures/MakeLiveMeasuresMetricUuidNotNullableTest.java
@@ -0,0 +1,42 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v83.metrics.livemeasures;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.MigrationStep;
+
+import static java.sql.Types.VARCHAR;
+
+public class MakeLiveMeasuresMetricUuidNotNullableTest {
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(MakeLiveMeasuresMetricUuidNotNullableTest.class, "schema.sql");
+
+ private MigrationStep underTest = new MakeLiveMeasuresMetricUuidNotNullable(db.database());
+
+ @Test
+ public void uuid_column_is_not_null() throws SQLException {
+ underTest.execute();
+
+ db.assertColumnDefinition("live_measures", "metric_uuid", VARCHAR, null, false);
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/livemeasures/PopulateLiveMeasuresMetricUuidTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/livemeasures/PopulateLiveMeasuresMetricUuidTest.java
new file mode 100644
index 00000000000..48012348d8d
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/livemeasures/PopulateLiveMeasuresMetricUuidTest.java
@@ -0,0 +1,102 @@
+/*
+ * 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.metrics.livemeasures;
+
+import java.sql.SQLException;
+import java.util.List;
+import java.util.Map;
+import org.assertj.core.groups.Tuple;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DataChange;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.tuple;
+
+public class PopulateLiveMeasuresMetricUuidTest {
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(PopulateLiveMeasuresMetricUuidTest.class, "schema.sql");
+
+ private DataChange underTest = new PopulateLiveMeasuresMetricUuid(db.database());
+
+ @Test
+ public void populate_uuids() throws SQLException {
+ insertMetric(1L);
+ insertMetric(2L);
+ insertMetric(3L);
+
+ insertLiveMeasure(4L, 1L);
+ insertLiveMeasure(5L, 2L);
+ insertLiveMeasure(6L, 3L);
+
+ underTest.execute();
+
+ assertThatTableContains(
+ tuple("uuid4", 1L, "uuid1"),
+ tuple("uuid5", 2L, "uuid2"),
+ tuple("uuid6", 3L, "uuid3")
+ );
+ }
+
+ @Test
+ public void migration_is_reentrant() throws SQLException {
+ insertMetric(1L);
+ insertMetric(2L);
+ insertMetric(3L);
+
+ insertLiveMeasure(4L, 1L);
+ insertLiveMeasure(5L, 2L);
+ insertLiveMeasure(6L, 3L);
+
+ underTest.execute();
+ // re-entrant
+ underTest.execute();
+
+ assertThatTableContains(
+ tuple("uuid4", 1L, "uuid1"),
+ tuple("uuid5", 2L, "uuid2"),
+ tuple("uuid6", 3L, "uuid3")
+ );
+ }
+
+ private void assertThatTableContains(Tuple... tuples) {
+ List<Map<String, Object>> select = db.select("select uuid, metric_id, metric_uuid from live_measures");
+ assertThat(select).extracting(m -> m.get("UUID"), m -> m.get("METRIC_ID"), m -> m.get("METRIC_UUID"))
+ .containsExactlyInAnyOrder(tuples);
+ }
+
+ private void insertMetric(Long id) {
+ db.executeInsert("metrics",
+ "id", id,
+ "uuid", "uuid" + id,
+ "name", "name" + id);
+ }
+
+ private void insertLiveMeasure(Long id, Long metricId) {
+ db.executeInsert("live_measures",
+ "uuid", "uuid" + id,
+ "metric_id", metricId,
+ "component_uuid", "component" + id,
+ "project_uuid", "project" + id + 2,
+ "created_at", id + 3,
+ "updated_at", id + 4);
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/manualmeasures/AddMetricUuidColumnToManualMeasuresTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/manualmeasures/AddMetricUuidColumnToManualMeasuresTest.java
new file mode 100644
index 00000000000..2942032eb78
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/manualmeasures/AddMetricUuidColumnToManualMeasuresTest.java
@@ -0,0 +1,60 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v83.metrics.manualmeasures;
+
+import java.sql.SQLException;
+import java.sql.Types;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class AddMetricUuidColumnToManualMeasuresTest {
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(AddMetricUuidColumnToManualMeasuresTest.class, "schema.sql");
+ private DdlChange underTest = new AddMetricUuidColumnToManualMeasures(db.database());
+
+ @Before
+ public void setup() {
+ insertManualMeasure(1L);
+ insertManualMeasure(2L);
+ insertManualMeasure(3L);
+ }
+
+ @Test
+ public void add_active_rule_uuid_column() throws SQLException {
+ underTest.execute();
+
+ db.assertColumnDefinition("manual_measures", "metric_uuid", Types.VARCHAR, 40, true);
+
+ assertThat(db.countRowsOfTable("manual_measures"))
+ .isEqualTo(3);
+ }
+
+ private void insertManualMeasure(Long id) {
+ db.executeInsert("manual_measures",
+ "uuid", "uuid" + id,
+ "metric_id", id + 1,
+ "component_uuid", "component" + id);
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/manualmeasures/DropMetricIdColumnOfManualMeasuresTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/manualmeasures/DropMetricIdColumnOfManualMeasuresTableTest.java
new file mode 100644
index 00000000000..ffbf5d0072d
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/manualmeasures/DropMetricIdColumnOfManualMeasuresTableTest.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.metrics.manualmeasures;
+
+import java.sql.SQLException;
+import java.sql.Types;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+public class DropMetricIdColumnOfManualMeasuresTableTest {
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(DropMetricIdColumnOfManualMeasuresTableTest.class, "schema.sql");
+
+ private DdlChange underTest = new DropMetricIdColumnOfManualMeasuresTable(db.database());
+
+ @Test
+ public void execute() throws SQLException {
+ db.assertColumnDefinition("manual_measures", "metric_id", Types.INTEGER, null, false);
+ underTest.execute();
+ db.assertColumnDoesNotExist("manual_measures", "metric_id");
+ }
+
+ @Test
+ public void migration_is_not_re_entrant() throws SQLException {
+ underTest.execute();
+
+ assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class);
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/manualmeasures/MakeManualMeasuresMetricUuidNotNullableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/manualmeasures/MakeManualMeasuresMetricUuidNotNullableTest.java
new file mode 100644
index 00000000000..f0c5a8869e8
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/manualmeasures/MakeManualMeasuresMetricUuidNotNullableTest.java
@@ -0,0 +1,42 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v83.metrics.manualmeasures;
+
+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 MakeManualMeasuresMetricUuidNotNullableTest {
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(MakeManualMeasuresMetricUuidNotNullableTest.class, "schema.sql");
+
+ private MigrationStep underTest = new MakeManualMeasuresMetricUuidNotNullable(db.database());
+
+ @Test
+ public void uuid_column_is_not_null() throws SQLException {
+ underTest.execute();
+
+ db.assertColumnDefinition("manual_measures", "metric_uuid", VARCHAR, null, false);
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/manualmeasures/PopulateManualMeasuresMetricUuidTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/manualmeasures/PopulateManualMeasuresMetricUuidTest.java
new file mode 100644
index 00000000000..71106d58325
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/manualmeasures/PopulateManualMeasuresMetricUuidTest.java
@@ -0,0 +1,99 @@
+/*
+ * 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.metrics.manualmeasures;
+
+import java.sql.SQLException;
+import java.util.List;
+import java.util.Map;
+import org.assertj.core.groups.Tuple;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DataChange;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.tuple;
+
+public class PopulateManualMeasuresMetricUuidTest {
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(PopulateManualMeasuresMetricUuidTest.class, "schema.sql");
+
+ private DataChange underTest = new PopulateManualMeasuresMetricUuid(db.database());
+
+ @Test
+ public void populate_uuids() throws SQLException {
+ insertMetric(1L);
+ insertMetric(2L);
+ insertMetric(3L);
+
+ insertManualMeasure(4L, 1L);
+ insertManualMeasure(5L, 2L);
+ insertManualMeasure(6L, 3L);
+
+ underTest.execute();
+
+ assertThatTableContains(
+ tuple("uuid4", 1L, "uuid1"),
+ tuple("uuid5", 2L, "uuid2"),
+ tuple("uuid6", 3L, "uuid3")
+ );
+ }
+
+ @Test
+ public void migration_is_reentrant() throws SQLException {
+ insertMetric(1L);
+ insertMetric(2L);
+ insertMetric(3L);
+
+ insertManualMeasure(4L, 1L);
+ insertManualMeasure(5L, 2L);
+ insertManualMeasure(6L, 3L);
+
+ underTest.execute();
+ // re-entrant
+ underTest.execute();
+
+ assertThatTableContains(
+ tuple("uuid4", 1L, "uuid1"),
+ tuple("uuid5", 2L, "uuid2"),
+ tuple("uuid6", 3L, "uuid3")
+ );
+ }
+
+ private void assertThatTableContains(Tuple... tuples) {
+ List<Map<String, Object>> select = db.select("select uuid, metric_id, metric_uuid from manual_measures");
+ assertThat(select).extracting(m -> m.get("UUID"), m -> m.get("METRIC_ID"), m -> m.get("METRIC_UUID"))
+ .containsExactlyInAnyOrder(tuples);
+ }
+
+ private void insertMetric(Long id) {
+ db.executeInsert("metrics",
+ "id", id,
+ "uuid", "uuid" + id,
+ "name", "name" + id);
+ }
+
+ private void insertManualMeasure(Long id, Long metricId) {
+ db.executeInsert("manual_measures",
+ "uuid", "uuid" + id,
+ "metric_id", metricId,
+ "component_uuid", "component" + id);
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/projectmeasures/AddIndexOnMetricUuidOfProjectMeasuresTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/projectmeasures/AddIndexOnMetricUuidOfProjectMeasuresTableTest.java
new file mode 100644
index 00000000000..9d913261abe
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/projectmeasures/AddIndexOnMetricUuidOfProjectMeasuresTableTest.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.metrics.projectmeasures;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.MigrationStep;
+
+public class AddIndexOnMetricUuidOfProjectMeasuresTableTest {
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(AddIndexOnMetricUuidOfProjectMeasuresTableTest.class, "schema.sql");
+
+ private MigrationStep underTest = new AddIndexOnMetricUuidOfProjectMeasuresTable(db.database());
+
+ @Test
+ public void execute() throws SQLException {
+ underTest.execute();
+
+ db.assertIndex("project_measures", "measures_analysis_metric", "analysis_uuid", "metric_uuid");
+ }
+
+ @Test
+ public void migration_is_re_entrant() throws SQLException {
+ underTest.execute();
+
+ // re-entrant
+ underTest.execute();
+
+ db.assertIndex("project_measures", "measures_analysis_metric", "analysis_uuid", "metric_uuid");
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/projectmeasures/AddMetricUuidColumnToProjectMeasuresTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/projectmeasures/AddMetricUuidColumnToProjectMeasuresTest.java
new file mode 100644
index 00000000000..88662b71471
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/projectmeasures/AddMetricUuidColumnToProjectMeasuresTest.java
@@ -0,0 +1,61 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v83.metrics.projectmeasures;
+
+import java.sql.SQLException;
+import java.sql.Types;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class AddMetricUuidColumnToProjectMeasuresTest {
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(AddMetricUuidColumnToProjectMeasuresTest.class, "schema.sql");
+ private DdlChange underTest = new AddMetricUuidColumnToProjectMeasures(db.database());
+
+ @Before
+ public void setup() {
+ insertProjectMeasure(1L);
+ insertProjectMeasure(2L);
+ insertProjectMeasure(3L);
+ }
+
+ @Test
+ public void add_active_rule_uuid_column() throws SQLException {
+ underTest.execute();
+
+ db.assertColumnDefinition("project_measures", "metric_uuid", Types.VARCHAR, 40, true);
+
+ assertThat(db.countRowsOfTable("project_measures"))
+ .isEqualTo(3);
+ }
+
+ private void insertProjectMeasure(Long id) {
+ db.executeInsert("project_measures",
+ "uuid", "uuid" + id,
+ "metric_id", id + 1,
+ "component_uuid", "component" + id,
+ "analysis_uuid", "analysis" + id + 1);
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/projectmeasures/DropIndexOnMetricIdOfProjectMeasuresTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/projectmeasures/DropIndexOnMetricIdOfProjectMeasuresTableTest.java
new file mode 100644
index 00000000000..59606f405d7
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/projectmeasures/DropIndexOnMetricIdOfProjectMeasuresTableTest.java
@@ -0,0 +1,54 @@
+/*
+ * 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.metrics.projectmeasures;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.MigrationStep;
+
+public class DropIndexOnMetricIdOfProjectMeasuresTableTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(DropIndexOnMetricIdOfProjectMeasuresTableTest.class, "schema.sql");
+
+ private MigrationStep underTest = new DropIndexOnMetricIdOfProjectMeasuresTable(db.database());
+
+ @Test
+ public void execute() throws SQLException {
+ db.assertTableExists("project_measures");
+ db.assertIndex("project_measures", "measures_analysis_metric", "analysis_uuid", "metric_id");
+
+ underTest.execute();
+
+ db.assertIndexDoesNotExist("project_measures", "measures_analysis_metric");
+ }
+
+ @Test
+ public void migration_is_re_entrant() throws SQLException {
+ underTest.execute();
+
+ // re-entrant
+ underTest.execute();
+
+ db.assertIndexDoesNotExist("project_measures", "measures_analysis_metric");
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/projectmeasures/DropMetricIdColumnOfProjectMeasuresTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/projectmeasures/DropMetricIdColumnOfProjectMeasuresTableTest.java
new file mode 100644
index 00000000000..43fcb3d4e7b
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/projectmeasures/DropMetricIdColumnOfProjectMeasuresTableTest.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.metrics.projectmeasures;
+
+import java.sql.SQLException;
+import java.sql.Types;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+public class DropMetricIdColumnOfProjectMeasuresTableTest {
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(DropMetricIdColumnOfProjectMeasuresTableTest.class, "schema.sql");
+
+ private DdlChange underTest = new DropMetricIdColumnOfProjectMeasuresTable(db.database());
+
+ @Test
+ public void execute() throws SQLException {
+ db.assertColumnDefinition("project_measures", "metric_id", Types.INTEGER, null, false);
+ underTest.execute();
+ db.assertColumnDoesNotExist("project_measures", "metric_id");
+ }
+
+ @Test
+ public void migration_is_not_re_entrant() throws SQLException {
+ underTest.execute();
+
+ assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class);
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/projectmeasures/MakeProjectMeasuresMetricUuidNotNullableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/projectmeasures/MakeProjectMeasuresMetricUuidNotNullableTest.java
new file mode 100644
index 00000000000..47e79aaaa6b
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/projectmeasures/MakeProjectMeasuresMetricUuidNotNullableTest.java
@@ -0,0 +1,42 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v83.metrics.projectmeasures;
+
+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 MakeProjectMeasuresMetricUuidNotNullableTest {
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(MakeProjectMeasuresMetricUuidNotNullableTest.class, "schema.sql");
+
+ private MigrationStep underTest = new MakeProjectMeasuresMetricUuidNotNullable(db.database());
+
+ @Test
+ public void uuid_column_is_not_null() throws SQLException {
+ underTest.execute();
+
+ db.assertColumnDefinition("project_measures", "metric_uuid", VARCHAR, null, false);
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/projectmeasures/PopulateProjectMeasuresMetricUuidTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/projectmeasures/PopulateProjectMeasuresMetricUuidTest.java
new file mode 100644
index 00000000000..a3f0d1b4994
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/projectmeasures/PopulateProjectMeasuresMetricUuidTest.java
@@ -0,0 +1,100 @@
+/*
+ * 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.metrics.projectmeasures;
+
+import java.sql.SQLException;
+import java.util.List;
+import java.util.Map;
+import org.assertj.core.groups.Tuple;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DataChange;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.tuple;
+
+public class PopulateProjectMeasuresMetricUuidTest {
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(PopulateProjectMeasuresMetricUuidTest.class, "schema.sql");
+
+ private DataChange underTest = new PopulateProjectMeasuresMetricUuid(db.database());
+
+ @Test
+ public void populate_uuids() throws SQLException {
+ insertMetric(1L);
+ insertMetric(2L);
+ insertMetric(3L);
+
+ insertProjectMeasure(4L, 1L);
+ insertProjectMeasure(5L, 2L);
+ insertProjectMeasure(6L, 3L);
+
+ underTest.execute();
+
+ assertThatTableContains(
+ tuple("uuid4", 1L, "uuid1"),
+ tuple("uuid5", 2L, "uuid2"),
+ tuple("uuid6", 3L, "uuid3")
+ );
+ }
+
+ @Test
+ public void migration_is_reentrant() throws SQLException {
+ insertMetric(1L);
+ insertMetric(2L);
+ insertMetric(3L);
+
+ insertProjectMeasure(4L, 1L);
+ insertProjectMeasure(5L, 2L);
+ insertProjectMeasure(6L, 3L);
+
+ underTest.execute();
+ // re-entrant
+ underTest.execute();
+
+ assertThatTableContains(
+ tuple("uuid4", 1L, "uuid1"),
+ tuple("uuid5", 2L, "uuid2"),
+ tuple("uuid6", 3L, "uuid3")
+ );
+ }
+
+ private void assertThatTableContains(Tuple... tuples) {
+ List<Map<String, Object>> select = db.select("select uuid, metric_id, metric_uuid from project_measures");
+ assertThat(select).extracting(m -> m.get("UUID"), m -> m.get("METRIC_ID"), m -> m.get("METRIC_UUID"))
+ .containsExactlyInAnyOrder(tuples);
+ }
+
+ private void insertMetric(Long id) {
+ db.executeInsert("metrics",
+ "id", id,
+ "uuid", "uuid" + id,
+ "name", "name" + id);
+ }
+
+ private void insertProjectMeasure(Long id, Long metricId) {
+ db.executeInsert("project_measures",
+ "uuid", "uuid" + id,
+ "metric_id", metricId,
+ "component_uuid", "component" + id,
+ "analysis_uuid", "analysis" + id + 1);
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/qualitygateconditions/AddMetricUuidColumnToQualityGateConditionsTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/qualitygateconditions/AddMetricUuidColumnToQualityGateConditionsTest.java
new file mode 100644
index 00000000000..7f93012cdb5
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/qualitygateconditions/AddMetricUuidColumnToQualityGateConditionsTest.java
@@ -0,0 +1,59 @@
+/*
+ * 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.metrics.qualitygateconditions;
+
+import java.sql.SQLException;
+import java.sql.Types;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class AddMetricUuidColumnToQualityGateConditionsTest {
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(AddMetricUuidColumnToQualityGateConditionsTest.class, "schema.sql");
+ private DdlChange underTest = new AddMetricUuidColumnToQualityGateConditions(db.database());
+
+ @Before
+ public void setup() {
+ insertQualityGateConditions(1L);
+ insertQualityGateConditions(2L);
+ insertQualityGateConditions(3L);
+ }
+
+ @Test
+ public void add_active_rule_uuid_column() throws SQLException {
+ underTest.execute();
+
+ db.assertColumnDefinition("quality_gate_conditions", "metric_uuid", Types.VARCHAR, 40, true);
+
+ assertThat(db.countRowsOfTable("quality_gate_conditions"))
+ .isEqualTo(3);
+ }
+
+ private void insertQualityGateConditions(Long id) {
+ db.executeInsert("quality_gate_conditions",
+ "uuid", "uuid" + id,
+ "metric_id", id + 1);
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/qualitygateconditions/DropMetricIdColumnOfQualityGateConditionsTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/qualitygateconditions/DropMetricIdColumnOfQualityGateConditionsTableTest.java
new file mode 100644
index 00000000000..b312dbe5479
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/qualitygateconditions/DropMetricIdColumnOfQualityGateConditionsTableTest.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.metrics.qualitygateconditions;
+
+import java.sql.SQLException;
+import java.sql.Types;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+public class DropMetricIdColumnOfQualityGateConditionsTableTest {
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(DropMetricIdColumnOfQualityGateConditionsTableTest.class, "schema.sql");
+
+ private DdlChange underTest = new DropMetricIdColumnOfQualityGateConditionsTable(db.database());
+
+ @Test
+ public void execute() throws SQLException {
+ db.assertColumnDefinition("quality_gate_conditions", "metric_id", Types.INTEGER, null, true);
+ underTest.execute();
+ db.assertColumnDoesNotExist("quality_gate_conditions", "metric_id");
+ }
+
+ @Test
+ public void migration_is_not_re_entrant() throws SQLException {
+ underTest.execute();
+
+ assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class);
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/qualitygateconditions/MakeQualityGateConditionsMetricUuidNotNullableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/qualitygateconditions/MakeQualityGateConditionsMetricUuidNotNullableTest.java
new file mode 100644
index 00000000000..75f4734cc67
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/qualitygateconditions/MakeQualityGateConditionsMetricUuidNotNullableTest.java
@@ -0,0 +1,42 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v83.metrics.qualitygateconditions;
+
+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 MakeQualityGateConditionsMetricUuidNotNullableTest {
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(MakeQualityGateConditionsMetricUuidNotNullableTest.class, "schema.sql");
+
+ private MigrationStep underTest = new MakeQualityGateConditionsMetricUuidNotNullable(db.database());
+
+ @Test
+ public void uuid_column_is_not_null() throws SQLException {
+ underTest.execute();
+
+ db.assertColumnDefinition("quality_gate_conditions", "metric_uuid", VARCHAR, null, false);
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/qualitygateconditions/PopulateQualityGateConditionsMetricUuidTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/qualitygateconditions/PopulateQualityGateConditionsMetricUuidTest.java
new file mode 100644
index 00000000000..ad312df9192
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/metrics/qualitygateconditions/PopulateQualityGateConditionsMetricUuidTest.java
@@ -0,0 +1,118 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v83.metrics.qualitygateconditions;
+
+import java.sql.SQLException;
+import java.util.List;
+import java.util.Map;
+import org.assertj.core.groups.Tuple;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DataChange;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.tuple;
+
+public class PopulateQualityGateConditionsMetricUuidTest {
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(PopulateQualityGateConditionsMetricUuidTest.class, "schema.sql");
+
+ private DataChange underTest = new PopulateQualityGateConditionsMetricUuid(db.database());
+
+ @Test
+ public void populate_uuids() throws SQLException {
+ insertMetric(1L);
+ insertMetric(2L);
+ insertMetric(3L);
+
+ insertQualityGateConditions(4L, 1L);
+ insertQualityGateConditions(5L, 2L);
+ insertQualityGateConditions(6L, 3L);
+
+ underTest.execute();
+
+ assertThatTableContains(
+ tuple("uuid4", 1L, "uuid1"),
+ tuple("uuid5", 2L, "uuid2"),
+ tuple("uuid6", 3L, "uuid3")
+ );
+ }
+
+ @Test
+ public void delete_entries_with_null_id() throws SQLException {
+ insertMetric(1L);
+ insertMetric(2L);
+ insertMetric(3L);
+
+ insertQualityGateConditions(4L, null);
+ insertQualityGateConditions(5L, 2L);
+ insertQualityGateConditions(6L, 3L);
+
+ underTest.execute();
+ // re-entrant
+ underTest.execute();
+
+ assertThatTableContains(
+ tuple("uuid5", 2L, "uuid2"),
+ tuple("uuid6", 3L, "uuid3")
+ );
+ }
+
+ @Test
+ public void migration_is_reentrant() throws SQLException {
+ insertMetric(1L);
+ insertMetric(2L);
+ insertMetric(3L);
+
+ insertQualityGateConditions(4L, 1L);
+ insertQualityGateConditions(5L, 2L);
+ insertQualityGateConditions(6L, 3L);
+
+ underTest.execute();
+ // re-entrant
+ underTest.execute();
+
+ assertThatTableContains(
+ tuple("uuid4", 1L, "uuid1"),
+ tuple("uuid5", 2L, "uuid2"),
+ tuple("uuid6", 3L, "uuid3")
+ );
+ }
+
+ private void assertThatTableContains(Tuple... tuples) {
+ List<Map<String, Object>> select = db.select("select uuid, metric_id, metric_uuid from quality_gate_conditions");
+ assertThat(select).extracting(m -> m.get("UUID"), m -> m.get("METRIC_ID"), m -> m.get("METRIC_UUID"))
+ .containsExactlyInAnyOrder(tuples);
+ }
+
+ private void insertMetric(Long id) {
+ db.executeInsert("metrics",
+ "id", id,
+ "uuid", "uuid" + id,
+ "name", "name" + id);
+ }
+
+ private void insertQualityGateConditions(Long id, Long metricId) {
+ db.executeInsert("quality_gate_conditions",
+ "uuid", "uuid" + id,
+ "metric_id", metricId);
+ }
+}
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/AddPrimaryKeyOnUuidColumnOfMetricsTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/AddPrimaryKeyOnUuidColumnOfMetricsTableTest/schema.sql
new file mode 100644
index 00000000000..51a7ed18a25
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/AddPrimaryKeyOnUuidColumnOfMetricsTableTest/schema.sql
@@ -0,0 +1,20 @@
+CREATE TABLE "METRICS"(
+ "ID" INTEGER NOT NULL,
+ "UUID" VARCHAR(40) NOT NULL,
+ "NAME" VARCHAR(64) NOT NULL,
+ "DESCRIPTION" VARCHAR(255),
+ "DIRECTION" INTEGER DEFAULT 0 NOT NULL,
+ "DOMAIN" VARCHAR(64),
+ "SHORT_NAME" VARCHAR(64),
+ "QUALITATIVE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "VAL_TYPE" VARCHAR(8),
+ "USER_MANAGED" BOOLEAN DEFAULT FALSE,
+ "ENABLED" BOOLEAN DEFAULT TRUE,
+ "WORST_VALUE" DOUBLE,
+ "BEST_VALUE" DOUBLE,
+ "OPTIMIZED_BEST_VALUE" BOOLEAN,
+ "HIDDEN" BOOLEAN,
+ "DELETE_HISTORICAL_DATA" BOOLEAN,
+ "DECIMAL_SCALE" INTEGER
+);
+CREATE UNIQUE INDEX "METRICS_UNIQUE_NAME" ON "METRICS"("NAME");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/AddUuidColumnToMetricsTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/AddUuidColumnToMetricsTableTest/schema.sql
new file mode 100644
index 00000000000..8ca314830d2
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/AddUuidColumnToMetricsTableTest/schema.sql
@@ -0,0 +1,20 @@
+CREATE TABLE "METRICS"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "NAME" VARCHAR(64) NOT NULL,
+ "DESCRIPTION" VARCHAR(255),
+ "DIRECTION" INTEGER DEFAULT 0 NOT NULL,
+ "DOMAIN" VARCHAR(64),
+ "SHORT_NAME" VARCHAR(64),
+ "QUALITATIVE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "VAL_TYPE" VARCHAR(8),
+ "USER_MANAGED" BOOLEAN DEFAULT FALSE,
+ "ENABLED" BOOLEAN DEFAULT TRUE,
+ "WORST_VALUE" DOUBLE,
+ "BEST_VALUE" DOUBLE,
+ "OPTIMIZED_BEST_VALUE" BOOLEAN,
+ "HIDDEN" BOOLEAN,
+ "DELETE_HISTORICAL_DATA" BOOLEAN,
+ "DECIMAL_SCALE" INTEGER
+);
+ALTER TABLE "METRICS" ADD CONSTRAINT "PK_METRICS" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "METRICS_UNIQUE_NAME" ON "METRICS"("NAME");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/DropIdColumnOfMetricsTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/DropIdColumnOfMetricsTableTest/schema.sql
new file mode 100644
index 00000000000..cc5c53aec36
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/DropIdColumnOfMetricsTableTest/schema.sql
@@ -0,0 +1,21 @@
+CREATE TABLE "METRICS"(
+ "ID" INTEGER NOT NULL,
+ "UUID" VARCHAR(40) NOT NULL,
+ "NAME" VARCHAR(64) NOT NULL,
+ "DESCRIPTION" VARCHAR(255),
+ "DIRECTION" INTEGER DEFAULT 0 NOT NULL,
+ "DOMAIN" VARCHAR(64),
+ "SHORT_NAME" VARCHAR(64),
+ "QUALITATIVE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "VAL_TYPE" VARCHAR(8),
+ "USER_MANAGED" BOOLEAN DEFAULT FALSE,
+ "ENABLED" BOOLEAN DEFAULT TRUE,
+ "WORST_VALUE" DOUBLE,
+ "BEST_VALUE" DOUBLE,
+ "OPTIMIZED_BEST_VALUE" BOOLEAN,
+ "HIDDEN" BOOLEAN,
+ "DELETE_HISTORICAL_DATA" BOOLEAN,
+ "DECIMAL_SCALE" INTEGER
+);
+ALTER TABLE "METRICS" ADD CONSTRAINT "PK_METRICS" PRIMARY KEY("UUID");
+CREATE UNIQUE INDEX "METRICS_UNIQUE_NAME" ON "METRICS"("NAME");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/DropPrimaryKeyOnIdColumnOfMetricsTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/DropPrimaryKeyOnIdColumnOfMetricsTableTest/schema.sql
new file mode 100644
index 00000000000..a5940e9702e
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/DropPrimaryKeyOnIdColumnOfMetricsTableTest/schema.sql
@@ -0,0 +1,21 @@
+CREATE TABLE "METRICS"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "UUID" VARCHAR(40) NOT NULL,
+ "NAME" VARCHAR(64) NOT NULL,
+ "DESCRIPTION" VARCHAR(255),
+ "DIRECTION" INTEGER DEFAULT 0 NOT NULL,
+ "DOMAIN" VARCHAR(64),
+ "SHORT_NAME" VARCHAR(64),
+ "QUALITATIVE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "VAL_TYPE" VARCHAR(8),
+ "USER_MANAGED" BOOLEAN DEFAULT FALSE,
+ "ENABLED" BOOLEAN DEFAULT TRUE,
+ "WORST_VALUE" DOUBLE,
+ "BEST_VALUE" DOUBLE,
+ "OPTIMIZED_BEST_VALUE" BOOLEAN,
+ "HIDDEN" BOOLEAN,
+ "DELETE_HISTORICAL_DATA" BOOLEAN,
+ "DECIMAL_SCALE" INTEGER
+);
+ALTER TABLE "METRICS" ADD CONSTRAINT "PK_METRICS" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "METRICS_UNIQUE_NAME" ON "METRICS"("NAME");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/MakeMetricsUuidColumnNotNullableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/MakeMetricsUuidColumnNotNullableTest/schema.sql
new file mode 100644
index 00000000000..5e215f6a7a9
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/MakeMetricsUuidColumnNotNullableTest/schema.sql
@@ -0,0 +1,21 @@
+CREATE TABLE "METRICS"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "UUID" VARCHAR(40),
+ "NAME" VARCHAR(64) NOT NULL,
+ "DESCRIPTION" VARCHAR(255),
+ "DIRECTION" INTEGER DEFAULT 0 NOT NULL,
+ "DOMAIN" VARCHAR(64),
+ "SHORT_NAME" VARCHAR(64),
+ "QUALITATIVE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "VAL_TYPE" VARCHAR(8),
+ "USER_MANAGED" BOOLEAN DEFAULT FALSE,
+ "ENABLED" BOOLEAN DEFAULT TRUE,
+ "WORST_VALUE" DOUBLE,
+ "BEST_VALUE" DOUBLE,
+ "OPTIMIZED_BEST_VALUE" BOOLEAN,
+ "HIDDEN" BOOLEAN,
+ "DELETE_HISTORICAL_DATA" BOOLEAN,
+ "DECIMAL_SCALE" INTEGER
+);
+ALTER TABLE "METRICS" ADD CONSTRAINT "PK_METRICS" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "METRICS_UNIQUE_NAME" ON "METRICS"("NAME");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/PopulateMetricsUuidTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/PopulateMetricsUuidTest/schema.sql
new file mode 100644
index 00000000000..5e215f6a7a9
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/PopulateMetricsUuidTest/schema.sql
@@ -0,0 +1,21 @@
+CREATE TABLE "METRICS"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "UUID" VARCHAR(40),
+ "NAME" VARCHAR(64) NOT NULL,
+ "DESCRIPTION" VARCHAR(255),
+ "DIRECTION" INTEGER DEFAULT 0 NOT NULL,
+ "DOMAIN" VARCHAR(64),
+ "SHORT_NAME" VARCHAR(64),
+ "QUALITATIVE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "VAL_TYPE" VARCHAR(8),
+ "USER_MANAGED" BOOLEAN DEFAULT FALSE,
+ "ENABLED" BOOLEAN DEFAULT TRUE,
+ "WORST_VALUE" DOUBLE,
+ "BEST_VALUE" DOUBLE,
+ "OPTIMIZED_BEST_VALUE" BOOLEAN,
+ "HIDDEN" BOOLEAN,
+ "DELETE_HISTORICAL_DATA" BOOLEAN,
+ "DECIMAL_SCALE" INTEGER
+);
+ALTER TABLE "METRICS" ADD CONSTRAINT "PK_METRICS" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "METRICS_UNIQUE_NAME" ON "METRICS"("NAME");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/livemeasures/AddIndexOnMetricUuidOfLiveMeasuresTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/livemeasures/AddIndexOnMetricUuidOfLiveMeasuresTableTest/schema.sql
new file mode 100644
index 00000000000..b624715d6c6
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/livemeasures/AddIndexOnMetricUuidOfLiveMeasuresTableTest/schema.sql
@@ -0,0 +1,16 @@
+CREATE TABLE "LIVE_MEASURES"(
+ "UUID" VARCHAR(40) NOT NULL,
+ "PROJECT_UUID" VARCHAR(50) NOT NULL,
+ "COMPONENT_UUID" VARCHAR(50) NOT NULL,
+ "METRIC_ID" INTEGER NOT NULL,
+ "METRIC_UUID" VARCHAR NOT NULL,
+ "VALUE" DOUBLE,
+ "TEXT_VALUE" VARCHAR(4000),
+ "VARIATION" DOUBLE,
+ "MEASURE_DATA" BLOB,
+ "UPDATE_MARKER" VARCHAR(40),
+ "CREATED_AT" BIGINT NOT NULL,
+ "UPDATED_AT" BIGINT NOT NULL
+);
+ALTER TABLE "LIVE_MEASURES" ADD CONSTRAINT "PK_LIVE_MEASURES" PRIMARY KEY("UUID");
+CREATE INDEX "LIVE_MEASURES_PROJECT" ON "LIVE_MEASURES"("PROJECT_UUID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/livemeasures/AddMetricUuidColumnToLiveMeasuresTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/livemeasures/AddMetricUuidColumnToLiveMeasuresTest/schema.sql
new file mode 100644
index 00000000000..e969dd3add3
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/livemeasures/AddMetricUuidColumnToLiveMeasuresTest/schema.sql
@@ -0,0 +1,16 @@
+CREATE TABLE "LIVE_MEASURES"(
+ "UUID" VARCHAR(40) NOT NULL,
+ "PROJECT_UUID" VARCHAR(50) NOT NULL,
+ "COMPONENT_UUID" VARCHAR(50) NOT NULL,
+ "METRIC_ID" INTEGER NOT NULL,
+ "VALUE" DOUBLE,
+ "TEXT_VALUE" VARCHAR(4000),
+ "VARIATION" DOUBLE,
+ "MEASURE_DATA" BLOB,
+ "UPDATE_MARKER" VARCHAR(40),
+ "CREATED_AT" BIGINT NOT NULL,
+ "UPDATED_AT" BIGINT NOT NULL
+);
+ALTER TABLE "LIVE_MEASURES" ADD CONSTRAINT "PK_LIVE_MEASURES" PRIMARY KEY("UUID");
+CREATE INDEX "LIVE_MEASURES_PROJECT" ON "LIVE_MEASURES"("PROJECT_UUID");
+CREATE UNIQUE INDEX "LIVE_MEASURES_COMPONENT" ON "LIVE_MEASURES"("COMPONENT_UUID", "METRIC_ID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/livemeasures/DropIndexOnMetricIdOfLiveMeasuresTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/livemeasures/DropIndexOnMetricIdOfLiveMeasuresTableTest/schema.sql
new file mode 100644
index 00000000000..79dd9a63064
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/livemeasures/DropIndexOnMetricIdOfLiveMeasuresTableTest/schema.sql
@@ -0,0 +1,17 @@
+CREATE TABLE "LIVE_MEASURES"(
+ "UUID" VARCHAR(40) NOT NULL,
+ "PROJECT_UUID" VARCHAR(50) NOT NULL,
+ "COMPONENT_UUID" VARCHAR(50) NOT NULL,
+ "METRIC_ID" INTEGER NOT NULL,
+ "METRIC_UUID" VARCHAR NOT NULL,
+ "VALUE" DOUBLE,
+ "TEXT_VALUE" VARCHAR(4000),
+ "VARIATION" DOUBLE,
+ "MEASURE_DATA" BLOB,
+ "UPDATE_MARKER" VARCHAR(40),
+ "CREATED_AT" BIGINT NOT NULL,
+ "UPDATED_AT" BIGINT NOT NULL
+);
+ALTER TABLE "LIVE_MEASURES" ADD CONSTRAINT "PK_LIVE_MEASURES" PRIMARY KEY("UUID");
+CREATE INDEX "LIVE_MEASURES_PROJECT" ON "LIVE_MEASURES"("PROJECT_UUID");
+CREATE UNIQUE INDEX "LIVE_MEASURES_COMPONENT" ON "LIVE_MEASURES"("COMPONENT_UUID", "METRIC_ID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/livemeasures/DropMetricIdColumnOfLiveMeasuresTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/livemeasures/DropMetricIdColumnOfLiveMeasuresTableTest/schema.sql
new file mode 100644
index 00000000000..5b750f3ece5
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/livemeasures/DropMetricIdColumnOfLiveMeasuresTableTest/schema.sql
@@ -0,0 +1,17 @@
+CREATE TABLE "LIVE_MEASURES"(
+ "UUID" VARCHAR(40) NOT NULL,
+ "PROJECT_UUID" VARCHAR(50) NOT NULL,
+ "COMPONENT_UUID" VARCHAR(50) NOT NULL,
+ "METRIC_ID" INTEGER NOT NULL,
+ "METRIC_UUID" VARCHAR NOT NULL,
+ "VALUE" DOUBLE,
+ "TEXT_VALUE" VARCHAR(4000),
+ "VARIATION" DOUBLE,
+ "MEASURE_DATA" BLOB,
+ "UPDATE_MARKER" VARCHAR(40),
+ "CREATED_AT" BIGINT NOT NULL,
+ "UPDATED_AT" BIGINT NOT NULL
+);
+ALTER TABLE "LIVE_MEASURES" ADD CONSTRAINT "PK_LIVE_MEASURES" PRIMARY KEY("UUID");
+CREATE INDEX "LIVE_MEASURES_PROJECT" ON "LIVE_MEASURES"("PROJECT_UUID");
+CREATE UNIQUE INDEX "LIVE_MEASURES_COMPONENT" ON "LIVE_MEASURES"("COMPONENT_UUID", "METRIC_UUID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/livemeasures/MakeLiveMeasuresMetricUuidNotNullableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/livemeasures/MakeLiveMeasuresMetricUuidNotNullableTest/schema.sql
new file mode 100644
index 00000000000..dd1e89afe4c
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/livemeasures/MakeLiveMeasuresMetricUuidNotNullableTest/schema.sql
@@ -0,0 +1,17 @@
+CREATE TABLE "LIVE_MEASURES"(
+ "UUID" VARCHAR(40) NOT NULL,
+ "PROJECT_UUID" VARCHAR(50) NOT NULL,
+ "COMPONENT_UUID" VARCHAR(50) NOT NULL,
+ "METRIC_ID" INTEGER NOT NULL,
+ "METRIC_UUID" VARCHAR(40),
+ "VALUE" DOUBLE,
+ "TEXT_VALUE" VARCHAR(4000),
+ "VARIATION" DOUBLE,
+ "MEASURE_DATA" BLOB,
+ "UPDATE_MARKER" VARCHAR(40),
+ "CREATED_AT" BIGINT NOT NULL,
+ "UPDATED_AT" BIGINT NOT NULL
+);
+ALTER TABLE "LIVE_MEASURES" ADD CONSTRAINT "PK_LIVE_MEASURES" PRIMARY KEY("UUID");
+CREATE INDEX "LIVE_MEASURES_PROJECT" ON "LIVE_MEASURES"("PROJECT_UUID");
+CREATE UNIQUE INDEX "LIVE_MEASURES_COMPONENT" ON "LIVE_MEASURES"("COMPONENT_UUID", "METRIC_ID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/livemeasures/PopulateLiveMeasuresMetricUuidTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/livemeasures/PopulateLiveMeasuresMetricUuidTest/schema.sql
new file mode 100644
index 00000000000..85b848f4614
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/livemeasures/PopulateLiveMeasuresMetricUuidTest/schema.sql
@@ -0,0 +1,39 @@
+CREATE TABLE "LIVE_MEASURES"(
+ "UUID" VARCHAR(40) NOT NULL,
+ "PROJECT_UUID" VARCHAR(50) NOT NULL,
+ "COMPONENT_UUID" VARCHAR(50) NOT NULL,
+ "METRIC_ID" INTEGER NOT NULL,
+ "METRIC_UUID" VARCHAR(40),
+ "VALUE" DOUBLE,
+ "TEXT_VALUE" VARCHAR(4000),
+ "VARIATION" DOUBLE,
+ "MEASURE_DATA" BLOB,
+ "UPDATE_MARKER" VARCHAR(40),
+ "CREATED_AT" BIGINT NOT NULL,
+ "UPDATED_AT" BIGINT NOT NULL
+);
+ALTER TABLE "LIVE_MEASURES" ADD CONSTRAINT "PK_LIVE_MEASURES" PRIMARY KEY("UUID");
+CREATE INDEX "LIVE_MEASURES_PROJECT" ON "LIVE_MEASURES"("PROJECT_UUID");
+CREATE UNIQUE INDEX "LIVE_MEASURES_COMPONENT" ON "LIVE_MEASURES"("COMPONENT_UUID", "METRIC_ID");
+
+CREATE TABLE "METRICS"(
+ "ID" INTEGER NOT NULL,
+ "UUID" VARCHAR(40) NOT NULL,
+ "NAME" VARCHAR(64) NOT NULL,
+ "DESCRIPTION" VARCHAR(255),
+ "DIRECTION" INTEGER DEFAULT 0 NOT NULL,
+ "DOMAIN" VARCHAR(64),
+ "SHORT_NAME" VARCHAR(64),
+ "QUALITATIVE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "VAL_TYPE" VARCHAR(8),
+ "USER_MANAGED" BOOLEAN DEFAULT FALSE,
+ "ENABLED" BOOLEAN DEFAULT TRUE,
+ "WORST_VALUE" DOUBLE,
+ "BEST_VALUE" DOUBLE,
+ "OPTIMIZED_BEST_VALUE" BOOLEAN,
+ "HIDDEN" BOOLEAN,
+ "DELETE_HISTORICAL_DATA" BOOLEAN,
+ "DECIMAL_SCALE" INTEGER
+);
+ALTER TABLE "METRICS" ADD CONSTRAINT "PK_METRICS" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "METRICS_UNIQUE_NAME" ON "METRICS"("NAME");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/manualmeasures/AddMetricUuidColumnToManualMeasuresTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/manualmeasures/AddMetricUuidColumnToManualMeasuresTest/schema.sql
new file mode 100644
index 00000000000..37a120d6215
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/manualmeasures/AddMetricUuidColumnToManualMeasuresTest/schema.sql
@@ -0,0 +1,35 @@
+CREATE TABLE "MANUAL_MEASURES"(
+ "UUID" VARCHAR(40) NOT NULL,
+ "METRIC_ID" INTEGER NOT NULL,
+ "VALUE" DOUBLE,
+ "TEXT_VALUE" VARCHAR(4000),
+ "USER_UUID" VARCHAR(255),
+ "DESCRIPTION" VARCHAR(4000),
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "COMPONENT_UUID" VARCHAR(50) NOT NULL
+);
+ALTER TABLE "MANUAL_MEASURES" ADD CONSTRAINT "PK_MANUAL_MEASURES" PRIMARY KEY("UUID");
+CREATE INDEX "MANUAL_MEASURES_COMPONENT_UUID" ON "MANUAL_MEASURES"("COMPONENT_UUID");
+
+CREATE TABLE "METRICS"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "NAME" VARCHAR(64) NOT NULL,
+ "DESCRIPTION" VARCHAR(255),
+ "DIRECTION" INTEGER DEFAULT 0 NOT NULL,
+ "DOMAIN" VARCHAR(64),
+ "SHORT_NAME" VARCHAR(64),
+ "QUALITATIVE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "VAL_TYPE" VARCHAR(8),
+ "USER_MANAGED" BOOLEAN DEFAULT FALSE,
+ "ENABLED" BOOLEAN DEFAULT TRUE,
+ "WORST_VALUE" DOUBLE,
+ "BEST_VALUE" DOUBLE,
+ "OPTIMIZED_BEST_VALUE" BOOLEAN,
+ "HIDDEN" BOOLEAN,
+ "DELETE_HISTORICAL_DATA" BOOLEAN,
+ "DECIMAL_SCALE" INTEGER,
+ "UUID" VARCHAR(40) NOT NULL
+);
+ALTER TABLE "METRICS" ADD CONSTRAINT "PK_METRICS" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "METRICS_UNIQUE_NAME" ON "METRICS"("NAME");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/manualmeasures/DropMetricIdColumnOfManualMeasuresTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/manualmeasures/DropMetricIdColumnOfManualMeasuresTableTest/schema.sql
new file mode 100644
index 00000000000..3bb1010e374
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/manualmeasures/DropMetricIdColumnOfManualMeasuresTableTest/schema.sql
@@ -0,0 +1,36 @@
+CREATE TABLE "MANUAL_MEASURES"(
+ "UUID" VARCHAR(40) NOT NULL,
+ "METRIC_UUID" VARCHAR(40) NOT NULL,
+ "METRIC_ID" INTEGER NOT NULL,
+ "VALUE" DOUBLE,
+ "TEXT_VALUE" VARCHAR(4000),
+ "USER_UUID" VARCHAR(255),
+ "DESCRIPTION" VARCHAR(4000),
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "COMPONENT_UUID" VARCHAR(50) NOT NULL
+);
+ALTER TABLE "MANUAL_MEASURES" ADD CONSTRAINT "PK_MANUAL_MEASURES" PRIMARY KEY("UUID");
+CREATE INDEX "MANUAL_MEASURES_COMPONENT_UUID" ON "MANUAL_MEASURES"("COMPONENT_UUID");
+
+CREATE TABLE "METRICS"(
+ "ID" INTEGER NOT NULL,
+ "NAME" VARCHAR(64) NOT NULL,
+ "DESCRIPTION" VARCHAR(255),
+ "DIRECTION" INTEGER DEFAULT 0 NOT NULL,
+ "DOMAIN" VARCHAR(64),
+ "SHORT_NAME" VARCHAR(64),
+ "QUALITATIVE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "VAL_TYPE" VARCHAR(8),
+ "USER_MANAGED" BOOLEAN DEFAULT FALSE,
+ "ENABLED" BOOLEAN DEFAULT TRUE,
+ "WORST_VALUE" DOUBLE,
+ "BEST_VALUE" DOUBLE,
+ "OPTIMIZED_BEST_VALUE" BOOLEAN,
+ "HIDDEN" BOOLEAN,
+ "DELETE_HISTORICAL_DATA" BOOLEAN,
+ "DECIMAL_SCALE" INTEGER,
+ "UUID" VARCHAR(40) NOT NULL
+);
+ALTER TABLE "METRICS" ADD CONSTRAINT "PK_METRICS" PRIMARY KEY("UUID");
+CREATE UNIQUE INDEX "METRICS_UNIQUE_NAME" ON "METRICS"("NAME");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/manualmeasures/MakeManualMeasuresMetricUuidNotNullableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/manualmeasures/MakeManualMeasuresMetricUuidNotNullableTest/schema.sql
new file mode 100644
index 00000000000..fe619cf50f2
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/manualmeasures/MakeManualMeasuresMetricUuidNotNullableTest/schema.sql
@@ -0,0 +1,36 @@
+CREATE TABLE "MANUAL_MEASURES"(
+ "UUID" VARCHAR(40) NOT NULL,
+ "METRIC_UUID" VARCHAR(40),
+ "METRIC_ID" INTEGER NOT NULL,
+ "VALUE" DOUBLE,
+ "TEXT_VALUE" VARCHAR(4000),
+ "USER_UUID" VARCHAR(255),
+ "DESCRIPTION" VARCHAR(4000),
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "COMPONENT_UUID" VARCHAR(50) NOT NULL
+);
+ALTER TABLE "MANUAL_MEASURES" ADD CONSTRAINT "PK_MANUAL_MEASURES" PRIMARY KEY("UUID");
+CREATE INDEX "MANUAL_MEASURES_COMPONENT_UUID" ON "MANUAL_MEASURES"("COMPONENT_UUID");
+
+CREATE TABLE "METRICS"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "NAME" VARCHAR(64) NOT NULL,
+ "DESCRIPTION" VARCHAR(255),
+ "DIRECTION" INTEGER DEFAULT 0 NOT NULL,
+ "DOMAIN" VARCHAR(64),
+ "SHORT_NAME" VARCHAR(64),
+ "QUALITATIVE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "VAL_TYPE" VARCHAR(8),
+ "USER_MANAGED" BOOLEAN DEFAULT FALSE,
+ "ENABLED" BOOLEAN DEFAULT TRUE,
+ "WORST_VALUE" DOUBLE,
+ "BEST_VALUE" DOUBLE,
+ "OPTIMIZED_BEST_VALUE" BOOLEAN,
+ "HIDDEN" BOOLEAN,
+ "DELETE_HISTORICAL_DATA" BOOLEAN,
+ "DECIMAL_SCALE" INTEGER,
+ "UUID" VARCHAR(40) NOT NULL
+);
+ALTER TABLE "METRICS" ADD CONSTRAINT "PK_METRICS" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "METRICS_UNIQUE_NAME" ON "METRICS"("NAME");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/manualmeasures/PopulateManualMeasuresMetricUuidTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/manualmeasures/PopulateManualMeasuresMetricUuidTest/schema.sql
new file mode 100644
index 00000000000..fe619cf50f2
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/manualmeasures/PopulateManualMeasuresMetricUuidTest/schema.sql
@@ -0,0 +1,36 @@
+CREATE TABLE "MANUAL_MEASURES"(
+ "UUID" VARCHAR(40) NOT NULL,
+ "METRIC_UUID" VARCHAR(40),
+ "METRIC_ID" INTEGER NOT NULL,
+ "VALUE" DOUBLE,
+ "TEXT_VALUE" VARCHAR(4000),
+ "USER_UUID" VARCHAR(255),
+ "DESCRIPTION" VARCHAR(4000),
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT,
+ "COMPONENT_UUID" VARCHAR(50) NOT NULL
+);
+ALTER TABLE "MANUAL_MEASURES" ADD CONSTRAINT "PK_MANUAL_MEASURES" PRIMARY KEY("UUID");
+CREATE INDEX "MANUAL_MEASURES_COMPONENT_UUID" ON "MANUAL_MEASURES"("COMPONENT_UUID");
+
+CREATE TABLE "METRICS"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "NAME" VARCHAR(64) NOT NULL,
+ "DESCRIPTION" VARCHAR(255),
+ "DIRECTION" INTEGER DEFAULT 0 NOT NULL,
+ "DOMAIN" VARCHAR(64),
+ "SHORT_NAME" VARCHAR(64),
+ "QUALITATIVE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "VAL_TYPE" VARCHAR(8),
+ "USER_MANAGED" BOOLEAN DEFAULT FALSE,
+ "ENABLED" BOOLEAN DEFAULT TRUE,
+ "WORST_VALUE" DOUBLE,
+ "BEST_VALUE" DOUBLE,
+ "OPTIMIZED_BEST_VALUE" BOOLEAN,
+ "HIDDEN" BOOLEAN,
+ "DELETE_HISTORICAL_DATA" BOOLEAN,
+ "DECIMAL_SCALE" INTEGER,
+ "UUID" VARCHAR(40) NOT NULL
+);
+ALTER TABLE "METRICS" ADD CONSTRAINT "PK_METRICS" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "METRICS_UNIQUE_NAME" ON "METRICS"("NAME");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/projectmeasures/AddIndexOnMetricUuidOfProjectMeasuresTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/projectmeasures/AddIndexOnMetricUuidOfProjectMeasuresTableTest/schema.sql
new file mode 100644
index 00000000000..bcd93c5d249
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/projectmeasures/AddIndexOnMetricUuidOfProjectMeasuresTableTest/schema.sql
@@ -0,0 +1,21 @@
+CREATE TABLE "PROJECT_MEASURES"(
+ "VALUE" DOUBLE,
+ "METRIC_UUID" VARCHAR(40) NOT NULL,
+ "METRIC_ID" INTEGER NOT NULL,
+ "ANALYSIS_UUID" VARCHAR(50) NOT NULL,
+ "COMPONENT_UUID" VARCHAR(50) NOT NULL,
+ "TEXT_VALUE" VARCHAR(4000),
+ "ALERT_STATUS" VARCHAR(5),
+ "ALERT_TEXT" VARCHAR(4000),
+ "DESCRIPTION" VARCHAR(4000),
+ "PERSON_ID" INTEGER,
+ "VARIATION_VALUE_1" DOUBLE,
+ "VARIATION_VALUE_2" DOUBLE,
+ "VARIATION_VALUE_3" DOUBLE,
+ "VARIATION_VALUE_4" DOUBLE,
+ "VARIATION_VALUE_5" DOUBLE,
+ "MEASURE_DATA" BLOB,
+ "UUID" VARCHAR(40) NOT NULL
+);
+ALTER TABLE "PROJECT_MEASURES" ADD CONSTRAINT "PK_PROJECT_MEASURES" PRIMARY KEY("UUID");
+CREATE INDEX "MEASURES_COMPONENT_UUID" ON "PROJECT_MEASURES"("COMPONENT_UUID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/projectmeasures/AddMetricUuidColumnToProjectMeasuresTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/projectmeasures/AddMetricUuidColumnToProjectMeasuresTest/schema.sql
new file mode 100644
index 00000000000..847518066d5
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/projectmeasures/AddMetricUuidColumnToProjectMeasuresTest/schema.sql
@@ -0,0 +1,21 @@
+CREATE TABLE "PROJECT_MEASURES"(
+ "VALUE" DOUBLE,
+ "METRIC_ID" INTEGER NOT NULL,
+ "ANALYSIS_UUID" VARCHAR(50) NOT NULL,
+ "COMPONENT_UUID" VARCHAR(50) NOT NULL,
+ "TEXT_VALUE" VARCHAR(4000),
+ "ALERT_STATUS" VARCHAR(5),
+ "ALERT_TEXT" VARCHAR(4000),
+ "DESCRIPTION" VARCHAR(4000),
+ "PERSON_ID" INTEGER,
+ "VARIATION_VALUE_1" DOUBLE,
+ "VARIATION_VALUE_2" DOUBLE,
+ "VARIATION_VALUE_3" DOUBLE,
+ "VARIATION_VALUE_4" DOUBLE,
+ "VARIATION_VALUE_5" DOUBLE,
+ "MEASURE_DATA" BLOB,
+ "UUID" VARCHAR(40) NOT NULL
+);
+ALTER TABLE "PROJECT_MEASURES" ADD CONSTRAINT "PK_PROJECT_MEASURES" PRIMARY KEY("UUID");
+CREATE INDEX "MEASURES_ANALYSIS_METRIC" ON "PROJECT_MEASURES"("ANALYSIS_UUID", "METRIC_ID");
+CREATE INDEX "MEASURES_COMPONENT_UUID" ON "PROJECT_MEASURES"("COMPONENT_UUID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/projectmeasures/DropIndexOnMetricIdOfProjectMeasuresTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/projectmeasures/DropIndexOnMetricIdOfProjectMeasuresTableTest/schema.sql
new file mode 100644
index 00000000000..90d0eb46d3e
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/projectmeasures/DropIndexOnMetricIdOfProjectMeasuresTableTest/schema.sql
@@ -0,0 +1,22 @@
+CREATE TABLE "PROJECT_MEASURES"(
+ "VALUE" DOUBLE,
+ "METRIC_UUID" VARCHAR(40) NOT NULL,
+ "METRIC_ID" INTEGER NOT NULL,
+ "ANALYSIS_UUID" VARCHAR(50) NOT NULL,
+ "COMPONENT_UUID" VARCHAR(50) NOT NULL,
+ "TEXT_VALUE" VARCHAR(4000),
+ "ALERT_STATUS" VARCHAR(5),
+ "ALERT_TEXT" VARCHAR(4000),
+ "DESCRIPTION" VARCHAR(4000),
+ "PERSON_ID" INTEGER,
+ "VARIATION_VALUE_1" DOUBLE,
+ "VARIATION_VALUE_2" DOUBLE,
+ "VARIATION_VALUE_3" DOUBLE,
+ "VARIATION_VALUE_4" DOUBLE,
+ "VARIATION_VALUE_5" DOUBLE,
+ "MEASURE_DATA" BLOB,
+ "UUID" VARCHAR(40) NOT NULL
+);
+ALTER TABLE "PROJECT_MEASURES" ADD CONSTRAINT "PK_PROJECT_MEASURES" PRIMARY KEY("UUID");
+CREATE INDEX "MEASURES_ANALYSIS_METRIC" ON "PROJECT_MEASURES"("ANALYSIS_UUID", "METRIC_ID");
+CREATE INDEX "MEASURES_COMPONENT_UUID" ON "PROJECT_MEASURES"("COMPONENT_UUID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/projectmeasures/DropMetricIdColumnOfProjectMeasuresTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/projectmeasures/DropMetricIdColumnOfProjectMeasuresTableTest/schema.sql
new file mode 100644
index 00000000000..55356e78300
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/projectmeasures/DropMetricIdColumnOfProjectMeasuresTableTest/schema.sql
@@ -0,0 +1,22 @@
+CREATE TABLE "PROJECT_MEASURES"(
+ "VALUE" DOUBLE,
+ "METRIC_UUID" VARCHAR(40) NOT NULL,
+ "METRIC_ID" INTEGER NOT NULL,
+ "ANALYSIS_UUID" VARCHAR(50) NOT NULL,
+ "COMPONENT_UUID" VARCHAR(50) NOT NULL,
+ "TEXT_VALUE" VARCHAR(4000),
+ "ALERT_STATUS" VARCHAR(5),
+ "ALERT_TEXT" VARCHAR(4000),
+ "DESCRIPTION" VARCHAR(4000),
+ "PERSON_ID" INTEGER,
+ "VARIATION_VALUE_1" DOUBLE,
+ "VARIATION_VALUE_2" DOUBLE,
+ "VARIATION_VALUE_3" DOUBLE,
+ "VARIATION_VALUE_4" DOUBLE,
+ "VARIATION_VALUE_5" DOUBLE,
+ "MEASURE_DATA" BLOB,
+ "UUID" VARCHAR(40) NOT NULL
+);
+ALTER TABLE "PROJECT_MEASURES" ADD CONSTRAINT "PK_PROJECT_MEASURES" PRIMARY KEY("UUID");
+CREATE INDEX "MEASURES_ANALYSIS_METRIC" ON "PROJECT_MEASURES"("ANALYSIS_UUID", "METRIC_UUID");
+CREATE INDEX "MEASURES_COMPONENT_UUID" ON "PROJECT_MEASURES"("COMPONENT_UUID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/projectmeasures/MakeProjectMeasuresMetricUuidNotNullableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/projectmeasures/MakeProjectMeasuresMetricUuidNotNullableTest/schema.sql
new file mode 100644
index 00000000000..d78a04c7c95
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/projectmeasures/MakeProjectMeasuresMetricUuidNotNullableTest/schema.sql
@@ -0,0 +1,22 @@
+CREATE TABLE "PROJECT_MEASURES"(
+ "VALUE" DOUBLE,
+ "METRIC_UUID" VARCHAR(40),
+ "METRIC_ID" INTEGER NOT NULL,
+ "ANALYSIS_UUID" VARCHAR(50) NOT NULL,
+ "COMPONENT_UUID" VARCHAR(50) NOT NULL,
+ "TEXT_VALUE" VARCHAR(4000),
+ "ALERT_STATUS" VARCHAR(5),
+ "ALERT_TEXT" VARCHAR(4000),
+ "DESCRIPTION" VARCHAR(4000),
+ "PERSON_ID" INTEGER,
+ "VARIATION_VALUE_1" DOUBLE,
+ "VARIATION_VALUE_2" DOUBLE,
+ "VARIATION_VALUE_3" DOUBLE,
+ "VARIATION_VALUE_4" DOUBLE,
+ "VARIATION_VALUE_5" DOUBLE,
+ "MEASURE_DATA" BLOB,
+ "UUID" VARCHAR(40) NOT NULL
+);
+ALTER TABLE "PROJECT_MEASURES" ADD CONSTRAINT "PK_PROJECT_MEASURES" PRIMARY KEY("UUID");
+CREATE INDEX "MEASURES_ANALYSIS_METRIC" ON "PROJECT_MEASURES"("ANALYSIS_UUID", "METRIC_ID");
+CREATE INDEX "MEASURES_COMPONENT_UUID" ON "PROJECT_MEASURES"("COMPONENT_UUID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/projectmeasures/PopulateProjectMeasuresMetricUuidTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/projectmeasures/PopulateProjectMeasuresMetricUuidTest/schema.sql
new file mode 100644
index 00000000000..ae7f3c32c33
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/projectmeasures/PopulateProjectMeasuresMetricUuidTest/schema.sql
@@ -0,0 +1,44 @@
+CREATE TABLE "PROJECT_MEASURES"(
+ "VALUE" DOUBLE,
+ "METRIC_UUID" VARCHAR(40),
+ "METRIC_ID" INTEGER NOT NULL,
+ "ANALYSIS_UUID" VARCHAR(50) NOT NULL,
+ "COMPONENT_UUID" VARCHAR(50) NOT NULL,
+ "TEXT_VALUE" VARCHAR(4000),
+ "ALERT_STATUS" VARCHAR(5),
+ "ALERT_TEXT" VARCHAR(4000),
+ "DESCRIPTION" VARCHAR(4000),
+ "PERSON_ID" INTEGER,
+ "VARIATION_VALUE_1" DOUBLE,
+ "VARIATION_VALUE_2" DOUBLE,
+ "VARIATION_VALUE_3" DOUBLE,
+ "VARIATION_VALUE_4" DOUBLE,
+ "VARIATION_VALUE_5" DOUBLE,
+ "MEASURE_DATA" BLOB,
+ "UUID" VARCHAR(40) NOT NULL
+);
+ALTER TABLE "PROJECT_MEASURES" ADD CONSTRAINT "PK_PROJECT_MEASURES" PRIMARY KEY("UUID");
+CREATE INDEX "MEASURES_ANALYSIS_METRIC" ON "PROJECT_MEASURES"("ANALYSIS_UUID", "METRIC_ID");
+CREATE INDEX "MEASURES_COMPONENT_UUID" ON "PROJECT_MEASURES"("COMPONENT_UUID");
+
+CREATE TABLE "METRICS"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "UUID" VARCHAR(40),
+ "NAME" VARCHAR(64) NOT NULL,
+ "DESCRIPTION" VARCHAR(255),
+ "DIRECTION" INTEGER DEFAULT 0 NOT NULL,
+ "DOMAIN" VARCHAR(64),
+ "SHORT_NAME" VARCHAR(64),
+ "QUALITATIVE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "VAL_TYPE" VARCHAR(8),
+ "USER_MANAGED" BOOLEAN DEFAULT FALSE,
+ "ENABLED" BOOLEAN DEFAULT TRUE,
+ "WORST_VALUE" DOUBLE,
+ "BEST_VALUE" DOUBLE,
+ "OPTIMIZED_BEST_VALUE" BOOLEAN,
+ "HIDDEN" BOOLEAN,
+ "DELETE_HISTORICAL_DATA" BOOLEAN,
+ "DECIMAL_SCALE" INTEGER
+);
+ALTER TABLE "METRICS" ADD CONSTRAINT "PK_METRICS" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "METRICS_UNIQUE_NAME" ON "METRICS"("NAME");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/qualitygateconditions/AddMetricUuidColumnToQualityGateConditionsTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/qualitygateconditions/AddMetricUuidColumnToQualityGateConditionsTest/schema.sql
new file mode 100644
index 00000000000..dff1d72e573
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/qualitygateconditions/AddMetricUuidColumnToQualityGateConditionsTest/schema.sql
@@ -0,0 +1,34 @@
+CREATE TABLE "QUALITY_GATE_CONDITIONS"(
+ "UUID" VARCHAR(40) NOT NULL,
+ "QGATE_ID" INTEGER,
+ "METRIC_ID" INTEGER,
+ "PERIOD" INTEGER,
+ "OPERATOR" VARCHAR(3),
+ "VALUE_ERROR" VARCHAR(64),
+ "VALUE_WARNING" VARCHAR(64),
+ "CREATED_AT" TIMESTAMP,
+ "UPDATED_AT" TIMESTAMP
+);
+ALTER TABLE "QUALITY_GATE_CONDITIONS" ADD CONSTRAINT "PK_QUALITY_GATE_CONDITIONS" PRIMARY KEY("UUID");
+
+CREATE TABLE "METRICS"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "UUID" VARCHAR(40) NOT NULL,
+ "NAME" VARCHAR(64) NOT NULL,
+ "DESCRIPTION" VARCHAR(255),
+ "DIRECTION" INTEGER DEFAULT 0 NOT NULL,
+ "DOMAIN" VARCHAR(64),
+ "SHORT_NAME" VARCHAR(64),
+ "QUALITATIVE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "VAL_TYPE" VARCHAR(8),
+ "USER_MANAGED" BOOLEAN DEFAULT FALSE,
+ "ENABLED" BOOLEAN DEFAULT TRUE,
+ "WORST_VALUE" DOUBLE,
+ "BEST_VALUE" DOUBLE,
+ "OPTIMIZED_BEST_VALUE" BOOLEAN,
+ "HIDDEN" BOOLEAN,
+ "DELETE_HISTORICAL_DATA" BOOLEAN,
+ "DECIMAL_SCALE" INTEGER
+);
+ALTER TABLE "METRICS" ADD CONSTRAINT "PK_METRICS" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "METRICS_UNIQUE_NAME" ON "METRICS"("NAME");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/qualitygateconditions/DropMetricIdColumnOfQualityGateConditionsTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/qualitygateconditions/DropMetricIdColumnOfQualityGateConditionsTableTest/schema.sql
new file mode 100644
index 00000000000..aa2aaf71563
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/qualitygateconditions/DropMetricIdColumnOfQualityGateConditionsTableTest/schema.sql
@@ -0,0 +1,35 @@
+CREATE TABLE "QUALITY_GATE_CONDITIONS"(
+ "UUID" VARCHAR(40) NOT NULL,
+ "QGATE_ID" INTEGER,
+ "METRIC_UUID" VARCHAR(40) NOT NULL,
+ "METRIC_ID" INTEGER,
+ "PERIOD" INTEGER,
+ "OPERATOR" VARCHAR(3),
+ "VALUE_ERROR" VARCHAR(64),
+ "VALUE_WARNING" VARCHAR(64),
+ "CREATED_AT" TIMESTAMP,
+ "UPDATED_AT" TIMESTAMP
+);
+ALTER TABLE "QUALITY_GATE_CONDITIONS" ADD CONSTRAINT "PK_QUALITY_GATE_CONDITIONS" PRIMARY KEY("UUID");
+
+CREATE TABLE "METRICS"(
+ "ID" INTEGER NOT NULL,
+ "UUID" VARCHAR(40) NOT NULL,
+ "NAME" VARCHAR(64) NOT NULL,
+ "DESCRIPTION" VARCHAR(255),
+ "DIRECTION" INTEGER DEFAULT 0 NOT NULL,
+ "DOMAIN" VARCHAR(64),
+ "SHORT_NAME" VARCHAR(64),
+ "QUALITATIVE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "VAL_TYPE" VARCHAR(8),
+ "USER_MANAGED" BOOLEAN DEFAULT FALSE,
+ "ENABLED" BOOLEAN DEFAULT TRUE,
+ "WORST_VALUE" DOUBLE,
+ "BEST_VALUE" DOUBLE,
+ "OPTIMIZED_BEST_VALUE" BOOLEAN,
+ "HIDDEN" BOOLEAN,
+ "DELETE_HISTORICAL_DATA" BOOLEAN,
+ "DECIMAL_SCALE" INTEGER
+);
+ALTER TABLE "METRICS" ADD CONSTRAINT "PK_METRICS" PRIMARY KEY("UUID");
+CREATE UNIQUE INDEX "METRICS_UNIQUE_NAME" ON "METRICS"("NAME");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/qualitygateconditions/MakeQualityGateConditionsMetricUuidNotNullableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/qualitygateconditions/MakeQualityGateConditionsMetricUuidNotNullableTest/schema.sql
new file mode 100644
index 00000000000..2b5a222cb91
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/qualitygateconditions/MakeQualityGateConditionsMetricUuidNotNullableTest/schema.sql
@@ -0,0 +1,35 @@
+CREATE TABLE "QUALITY_GATE_CONDITIONS"(
+ "UUID" VARCHAR(40) NOT NULL,
+ "QGATE_ID" INTEGER,
+ "METRIC_UUID" VARCHAR(40),
+ "METRIC_ID" INTEGER,
+ "PERIOD" INTEGER,
+ "OPERATOR" VARCHAR(3),
+ "VALUE_ERROR" VARCHAR(64),
+ "VALUE_WARNING" VARCHAR(64),
+ "CREATED_AT" TIMESTAMP,
+ "UPDATED_AT" TIMESTAMP
+);
+ALTER TABLE "QUALITY_GATE_CONDITIONS" ADD CONSTRAINT "PK_QUALITY_GATE_CONDITIONS" PRIMARY KEY("UUID");
+
+CREATE TABLE "METRICS"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "UUID" VARCHAR(40) NOT NULL,
+ "NAME" VARCHAR(64) NOT NULL,
+ "DESCRIPTION" VARCHAR(255),
+ "DIRECTION" INTEGER DEFAULT 0 NOT NULL,
+ "DOMAIN" VARCHAR(64),
+ "SHORT_NAME" VARCHAR(64),
+ "QUALITATIVE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "VAL_TYPE" VARCHAR(8),
+ "USER_MANAGED" BOOLEAN DEFAULT FALSE,
+ "ENABLED" BOOLEAN DEFAULT TRUE,
+ "WORST_VALUE" DOUBLE,
+ "BEST_VALUE" DOUBLE,
+ "OPTIMIZED_BEST_VALUE" BOOLEAN,
+ "HIDDEN" BOOLEAN,
+ "DELETE_HISTORICAL_DATA" BOOLEAN,
+ "DECIMAL_SCALE" INTEGER
+);
+ALTER TABLE "METRICS" ADD CONSTRAINT "PK_METRICS" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "METRICS_UNIQUE_NAME" ON "METRICS"("NAME");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/qualitygateconditions/PopulateQualityGateConditionsMetricUuidTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/qualitygateconditions/PopulateQualityGateConditionsMetricUuidTest/schema.sql
new file mode 100644
index 00000000000..2b5a222cb91
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/metrics/qualitygateconditions/PopulateQualityGateConditionsMetricUuidTest/schema.sql
@@ -0,0 +1,35 @@
+CREATE TABLE "QUALITY_GATE_CONDITIONS"(
+ "UUID" VARCHAR(40) NOT NULL,
+ "QGATE_ID" INTEGER,
+ "METRIC_UUID" VARCHAR(40),
+ "METRIC_ID" INTEGER,
+ "PERIOD" INTEGER,
+ "OPERATOR" VARCHAR(3),
+ "VALUE_ERROR" VARCHAR(64),
+ "VALUE_WARNING" VARCHAR(64),
+ "CREATED_AT" TIMESTAMP,
+ "UPDATED_AT" TIMESTAMP
+);
+ALTER TABLE "QUALITY_GATE_CONDITIONS" ADD CONSTRAINT "PK_QUALITY_GATE_CONDITIONS" PRIMARY KEY("UUID");
+
+CREATE TABLE "METRICS"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "UUID" VARCHAR(40) NOT NULL,
+ "NAME" VARCHAR(64) NOT NULL,
+ "DESCRIPTION" VARCHAR(255),
+ "DIRECTION" INTEGER DEFAULT 0 NOT NULL,
+ "DOMAIN" VARCHAR(64),
+ "SHORT_NAME" VARCHAR(64),
+ "QUALITATIVE" BOOLEAN DEFAULT FALSE NOT NULL,
+ "VAL_TYPE" VARCHAR(8),
+ "USER_MANAGED" BOOLEAN DEFAULT FALSE,
+ "ENABLED" BOOLEAN DEFAULT TRUE,
+ "WORST_VALUE" DOUBLE,
+ "BEST_VALUE" DOUBLE,
+ "OPTIMIZED_BEST_VALUE" BOOLEAN,
+ "HIDDEN" BOOLEAN,
+ "DELETE_HISTORICAL_DATA" BOOLEAN,
+ "DECIMAL_SCALE" INTEGER
+);
+ALTER TABLE "METRICS" ADD CONSTRAINT "PK_METRICS" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "METRICS_UNIQUE_NAME" ON "METRICS"("NAME");
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/metric/DefaultMetricFinder.java b/server/sonar-server-common/src/main/java/org/sonar/server/metric/DefaultMetricFinder.java
index c60f68ec62a..50d5471feed 100644
--- a/server/sonar-server-common/src/main/java/org/sonar/server/metric/DefaultMetricFinder.java
+++ b/server/sonar-server-common/src/main/java/org/sonar/server/metric/DefaultMetricFinder.java
@@ -42,9 +42,9 @@ public class DefaultMetricFinder implements MetricFinder {
}
@Override
- public Metric findById(int id) {
+ public Metric findByUuid(String uuid) {
try (DbSession session = dbClient.openSession(false)) {
- MetricDto dto = dbClient.metricDao().selectById(session, id);
+ MetricDto dto = dbClient.metricDao().selectByUuid(session, uuid);
if (dto != null && dto.isEnabled()) {
return ToMetric.INSTANCE.apply(dto);
}
@@ -93,7 +93,7 @@ public class DefaultMetricFinder implements MetricFinder {
@Override
public Metric apply(@Nonnull MetricDto dto) {
Metric<Serializable> metric = new Metric<>();
- metric.setId(dto.getId());
+ metric.setUuid(dto.getUuid());
metric.setKey(dto.getKey());
metric.setDescription(dto.getDescription());
metric.setName(dto.getShortName());
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/metric/MetricToDto.java b/server/sonar-server-common/src/main/java/org/sonar/server/metric/MetricToDto.java
index 64696f2d6d9..204b29eb6ac 100644
--- a/server/sonar-server-common/src/main/java/org/sonar/server/metric/MetricToDto.java
+++ b/server/sonar-server-common/src/main/java/org/sonar/server/metric/MetricToDto.java
@@ -31,7 +31,7 @@ public enum MetricToDto implements Function<Metric, MetricDto> {
@Nonnull
public MetricDto apply(Metric metric) {
MetricDto dto = new MetricDto();
- dto.setId(metric.getId());
+ dto.setUuid(metric.getUuid());
dto.setKey(metric.getKey());
dto.setDescription(metric.getDescription());
dto.setShortName(metric.getName());
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/notification/DefaultNotificationManager.java b/server/sonar-server-common/src/main/java/org/sonar/server/notification/DefaultNotificationManager.java
index d164616accc..ca8dbb67abe 100644
--- a/server/sonar-server-common/src/main/java/org/sonar/server/notification/DefaultNotificationManager.java
+++ b/server/sonar-server-common/src/main/java/org/sonar/server/notification/DefaultNotificationManager.java
@@ -36,10 +36,8 @@ import javax.annotation.Nullable;
import org.sonar.api.notifications.Notification;
import org.sonar.api.notifications.NotificationChannel;
import org.sonar.api.utils.SonarException;
-import org.sonar.api.utils.System2;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
-import org.sonar.core.util.UuidFactory;
import org.sonar.core.util.stream.MoreCollectors;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/metric/DefaultMetricFinderTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/metric/DefaultMetricFinderTest.java
index da532fad346..6948eebafed 100644
--- a/server/sonar-server-common/src/test/java/org/sonar/server/metric/DefaultMetricFinderTest.java
+++ b/server/sonar-server-common/src/test/java/org/sonar/server/metric/DefaultMetricFinderTest.java
@@ -66,7 +66,7 @@ public class DefaultMetricFinderTest {
MetricDto secondMetric = db.getDbClient().metricDao().insert(db.getSession(), newMetricDto());
db.commit();
- assertThat(underTest.findById(firstMetric.getId())).extracting(Metric::getKey).isEqualTo(firstMetric.getKey());
+ assertThat(underTest.findByUuid(firstMetric.getUuid())).extracting(Metric::getKey).isEqualTo(firstMetric.getKey());
}
@Test
diff --git a/server/sonar-webserver-core/src/main/java/org/sonar/server/startup/RegisterMetrics.java b/server/sonar-webserver-core/src/main/java/org/sonar/server/startup/RegisterMetrics.java
index b95bd83dcc0..db1b1bcec6c 100644
--- a/server/sonar-webserver-core/src/main/java/org/sonar/server/startup/RegisterMetrics.java
+++ b/server/sonar-webserver-core/src/main/java/org/sonar/server/startup/RegisterMetrics.java
@@ -30,6 +30,7 @@ import org.sonar.api.measures.Metrics;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
import org.sonar.api.utils.log.Profiler;
+import org.sonar.core.util.UuidFactory;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.metric.MetricDto;
@@ -44,18 +45,20 @@ public class RegisterMetrics implements Startable {
private static final Logger LOG = Loggers.get(RegisterMetrics.class);
private final DbClient dbClient;
+ private final UuidFactory uuidFactory;
private final Metrics[] metricsRepositories;
- public RegisterMetrics(DbClient dbClient, Metrics[] metricsRepositories) {
+ public RegisterMetrics(DbClient dbClient, UuidFactory uuidFactory, Metrics[] metricsRepositories) {
this.dbClient = dbClient;
+ this.uuidFactory = uuidFactory;
this.metricsRepositories = metricsRepositories;
}
/**
* Used when no plugin is defining Metrics
*/
- public RegisterMetrics(DbClient dbClient) {
- this(dbClient, new Metrics[] {});
+ public RegisterMetrics(DbClient dbClient, UuidFactory uuidFactory) {
+ this(dbClient, uuidFactory, new Metrics[] {});
}
@Override
@@ -93,10 +96,11 @@ public class RegisterMetrics implements Startable {
MetricDto base = basesByKey.get(metric.getKey());
if (base == null) {
// new metric, never installed
+ dto.setUuid(uuidFactory.create());
dbClient.metricDao().insert(session, dto);
} else if (!base.isUserManaged()) {
// existing metric, update changes. Existing custom metrics are kept without applying changes.
- dto.setId(base.getId());
+ dto.setUuid(base.getUuid());
dbClient.metricDao().update(session, dto);
}
basesByKey.remove(metric.getKey());
diff --git a/server/sonar-webserver-core/src/test/java/org/sonar/server/startup/RegisterMetricsTest.java b/server/sonar-webserver-core/src/test/java/org/sonar/server/startup/RegisterMetricsTest.java
index bdb58181da0..ac66c05b19a 100644
--- a/server/sonar-webserver-core/src/test/java/org/sonar/server/startup/RegisterMetricsTest.java
+++ b/server/sonar-webserver-core/src/test/java/org/sonar/server/startup/RegisterMetricsTest.java
@@ -30,6 +30,8 @@ import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.measures.Metric;
import org.sonar.api.measures.Metrics;
import org.sonar.api.utils.System2;
+import org.sonar.core.util.SequenceUuidFactory;
+import org.sonar.core.util.UuidFactory;
import org.sonar.db.DbClient;
import org.sonar.db.DbTester;
import org.sonar.db.metric.MetricDto;
@@ -44,6 +46,7 @@ public class RegisterMetricsTest {
@Rule
public DbTester dbTester = DbTester.create(System2.INSTANCE);
+ private UuidFactory uuidFactory = new SequenceUuidFactory();
private DbClient dbClient = dbTester.getDbClient();
/**
@@ -63,7 +66,7 @@ public class RegisterMetricsTest {
.setUserManaged(true)
.create();
- RegisterMetrics register = new RegisterMetrics(dbClient);
+ RegisterMetrics register = new RegisterMetrics(dbClient, uuidFactory);
register.register(asList(m1, custom));
Map<String, MetricDto> metricsByKey = selectAllMetrics();
@@ -101,7 +104,7 @@ public class RegisterMetricsTest {
.setHidden(false)
.setDecimalScale(1));
- RegisterMetrics register = new RegisterMetrics(dbClient);
+ RegisterMetrics register = new RegisterMetrics(dbClient, uuidFactory);
Metric m1 = new Metric.Builder("m1", "New name", Metric.ValueType.FLOAT)
.setDescription("new description")
.setDirection(-1)
@@ -137,7 +140,7 @@ public class RegisterMetricsTest {
IntStream.range(0, count)
.forEach(t -> dbTester.measures().insertMetric(m -> m.setEnabled(random.nextBoolean()).setUserManaged(false)));
- RegisterMetrics register = new RegisterMetrics(dbClient);
+ RegisterMetrics register = new RegisterMetrics(dbClient, uuidFactory);
register.register(Collections.emptyList());
assertThat(selectAllMetrics().values().stream())
@@ -150,7 +153,7 @@ public class RegisterMetricsTest {
MetricDto enabledMetric = dbTester.measures().insertMetric(t -> t.setEnabled(true).setUserManaged(false));
MetricDto disabledMetric = dbTester.measures().insertMetric(t -> t.setEnabled(false).setUserManaged(false));
- RegisterMetrics register = new RegisterMetrics(dbClient);
+ RegisterMetrics register = new RegisterMetrics(dbClient, uuidFactory);
register.register(asList(builderOf(enabledMetric).create(), builderOf(disabledMetric).create()));
assertThat(selectAllMetrics().values())
@@ -163,7 +166,7 @@ public class RegisterMetricsTest {
MetricDto enabledMetric = dbTester.measures().insertMetric(t -> t.setEnabled(true).setUserManaged(true));
MetricDto disabledMetric = dbTester.measures().insertMetric(t -> t.setEnabled(false).setUserManaged(true));
- RegisterMetrics register = new RegisterMetrics(dbClient);
+ RegisterMetrics register = new RegisterMetrics(dbClient, uuidFactory);
register.register(asList(builderOf(enabledMetric).create(), builderOf(disabledMetric).create()));
assertThat(selectAllMetrics().values())
@@ -175,7 +178,7 @@ public class RegisterMetricsTest {
@Test
public void insert_core_metrics() {
- RegisterMetrics register = new RegisterMetrics(dbClient);
+ RegisterMetrics register = new RegisterMetrics(dbClient, uuidFactory);
register.start();
assertThat(dbTester.countRowsOfTable("metrics")).isEqualTo(CoreMetrics.getMetrics().size());
@@ -186,14 +189,14 @@ public class RegisterMetricsTest {
Metrics plugin1 = new TestMetrics(new Metric.Builder("m1", "In first plugin", Metric.ValueType.FLOAT).create());
Metrics plugin2 = new TestMetrics(new Metric.Builder("m1", "In second plugin", Metric.ValueType.FLOAT).create());
- new RegisterMetrics(dbClient, new Metrics[] {plugin1, plugin2}).start();
+ new RegisterMetrics(dbClient, uuidFactory, new Metrics[] {plugin1, plugin2}).start();
}
@Test(expected = IllegalStateException.class)
public void fail_if_plugin_duplicates_core_metric() {
Metrics plugin = new TestMetrics(new Metric.Builder("ncloc", "In plugin", Metric.ValueType.FLOAT).create());
- new RegisterMetrics(dbClient, new Metrics[] {plugin}).start();
+ new RegisterMetrics(dbClient, uuidFactory, new Metrics[] {plugin}).start();
}
private static class TestMetrics implements Metrics {
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/badge/ws/MeasureAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/badge/ws/MeasureAction.java
index 8b9dbbf5f43..930dacc3492 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/badge/ws/MeasureAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/badge/ws/MeasureAction.java
@@ -35,7 +35,6 @@ import org.sonar.api.server.ws.WebService.NewAction;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.component.BranchDto;
-import org.sonar.db.component.ComponentDto;
import org.sonar.db.measure.LiveMeasureDto;
import org.sonar.db.metric.MetricDto;
import org.sonar.server.badge.ws.SvgGenerator.Color;
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/badge/ws/QualityGateAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/badge/ws/QualityGateAction.java
index 33ad574ea4a..e89c280772a 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/badge/ws/QualityGateAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/badge/ws/QualityGateAction.java
@@ -32,7 +32,6 @@ import org.sonar.api.server.ws.WebService.NewAction;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.component.BranchDto;
-import org.sonar.db.component.ComponentDto;
import org.sonar.db.measure.LiveMeasureDto;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.NotFoundException;
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/ComponentViewerJsonWriter.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/ComponentViewerJsonWriter.java
index d2fd1fffea3..853cbb090ff 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/ComponentViewerJsonWriter.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/ComponentViewerJsonWriter.java
@@ -121,10 +121,10 @@ public class ComponentViewerJsonWriter {
private Map<String, LiveMeasureDto> loadMeasuresGroupedByMetricKey(ComponentDto component, DbSession dbSession) {
List<MetricDto> metrics = dbClient.metricDao().selectByKeys(dbSession, METRIC_KEYS);
- Map<Integer, MetricDto> metricsById = Maps.uniqueIndex(metrics, MetricDto::getId);
+ Map<String, MetricDto> metricsByUuid = Maps.uniqueIndex(metrics, MetricDto::getUuid);
List<LiveMeasureDto> measures = dbClient.liveMeasureDao()
- .selectByComponentUuidsAndMetricIds(dbSession, Collections.singletonList(component.uuid()), metricsById.keySet());
- return Maps.uniqueIndex(measures, m -> metricsById.get(m.getMetricId()).getKey());
+ .selectByComponentUuidsAndMetricUuids(dbSession, Collections.singletonList(component.uuid()), metricsByUuid.keySet());
+ return Maps.uniqueIndex(measures, m -> metricsByUuid.get(m.getMetricUuid()).getKey());
}
@CheckForNull
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/hotspot/ws/DeleteCommentAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/hotspot/ws/DeleteCommentAction.java
index 4d74a212c09..617d9c5e7de 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/hotspot/ws/DeleteCommentAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/hotspot/ws/DeleteCommentAction.java
@@ -23,7 +23,6 @@ import java.util.Objects;
import org.sonar.api.server.ws.Request;
import org.sonar.api.server.ws.Response;
import org.sonar.api.server.ws.WebService;
-import org.sonar.api.web.UserRole;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.issue.IssueChangeDto;
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/custom/ws/CreateAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/custom/ws/CreateAction.java
index b42a52c8dd9..7af1096bf34 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/custom/ws/CreateAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/custom/ws/CreateAction.java
@@ -123,7 +123,7 @@ public class CreateAction implements CustomMeasuresWsAction {
checkState(user != null, "User with uuid '%s' does not exist", userUuid);
CustomMeasureDto measure = new CustomMeasureDto()
.setComponentUuid(component.uuid())
- .setMetricId(metric.getId())
+ .setMetricUuid(metric.getUuid())
.setDescription(description)
.setUserUuid(user.getUuid())
.setCreatedAt(now)
@@ -143,24 +143,24 @@ public class CreateAction implements CustomMeasuresWsAction {
}
private void checkMeasureDoesNotExistAlready(DbSession dbSession, ComponentDto component, MetricDto metric) {
- int nbMeasuresOnSameMetricAndMeasure = dbClient.customMeasureDao().countByComponentIdAndMetricId(dbSession, component.uuid(), metric.getId());
+ int nbMeasuresOnSameMetricAndMeasure = dbClient.customMeasureDao().countByComponentIdAndMetricUuid(dbSession, component.uuid(), metric.getUuid());
checkRequest(nbMeasuresOnSameMetricAndMeasure == 0,
"A measure already exists for project '%s' and metric '%s'",
component.getDbKey(), metric.getKey());
}
private MetricDto searchMetric(DbSession dbSession, Request request) {
- Integer metricId = request.paramAsInt(PARAM_METRIC_ID);
+ String metricUuid = request.param(PARAM_METRIC_ID);
String metricKey = request.param(PARAM_METRIC_KEY);
- checkArgument(metricId != null ^ metricKey != null, "Either the metric id or the metric key must be provided");
+ checkArgument(metricUuid != null ^ metricKey != null, "Either the metric uuid or the metric key must be provided");
- if (metricId == null) {
+ if (metricUuid == null) {
MetricDto metric = dbClient.metricDao().selectByKey(dbSession, metricKey);
checkArgument(metric != null, "Metric with key '%s' does not exist", metricKey);
return metric;
}
- MetricDto metric = dbClient.metricDao().selectById(dbSession, metricId);
- checkArgument(metric != null, "Metric with id '%s' does not exist", metricId);
+ MetricDto metric = dbClient.metricDao().selectByUuid(dbSession, metricUuid);
+ checkArgument(metric != null, "Metric with uuid '%s' does not exist", metricUuid);
return metric;
}
}
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/custom/ws/SearchAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/custom/ws/SearchAction.java
index 8aaebd327f2..76c450dba46 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/custom/ws/SearchAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/custom/ws/SearchAction.java
@@ -19,16 +19,13 @@
*/
package org.sonar.server.measure.custom.ws;
-import com.google.common.base.Function;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
+import java.util.stream.Collectors;
import javax.annotation.CheckForNull;
-import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.sonar.api.server.ws.Request;
import org.sonar.api.server.ws.Response;
@@ -46,7 +43,6 @@ import org.sonar.server.component.ComponentFinder;
import org.sonar.server.es.SearchOptions;
import org.sonar.server.user.UserSession;
-import static com.google.common.collect.Sets.newHashSet;
import static org.sonar.server.component.ComponentFinder.ParamNames.PROJECT_ID_AND_KEY;
import static org.sonar.server.es.SearchOptions.MAX_LIMIT;
import static org.sonar.server.measure.custom.ws.CustomMeasureValidator.checkPermissions;
@@ -107,9 +103,9 @@ public class SearchAction implements CustomMeasuresWsAction {
List<CustomMeasureDto> customMeasures = searchCustomMeasures(dbSession, component, searchOptions);
int nbCustomMeasures = countTotalOfCustomMeasures(dbSession, component);
Map<String, UserDto> usersByUuid = usersByUuid(dbSession, customMeasures);
- Map<Integer, MetricDto> metricsById = metricsById(dbSession, customMeasures);
+ Map<String, MetricDto> metricsByUuid = metricsByUuid(dbSession, customMeasures);
- writeResponse(response, customMeasures, nbCustomMeasures, component, metricsById, usersByUuid, lastAnalysisDateMs, searchOptions, fieldsToReturn);
+ writeResponse(response, customMeasures, nbCustomMeasures, component, metricsByUuid, usersByUuid, lastAnalysisDateMs, searchOptions, fieldsToReturn);
}
}
@@ -128,31 +124,32 @@ public class SearchAction implements CustomMeasuresWsAction {
return dbClient.customMeasureDao().selectByComponentUuid(dbSession, project.uuid(), searchOptions.getOffset(), searchOptions.getLimit());
}
- private void writeResponse(Response response, List<CustomMeasureDto> customMeasures, int nbCustomMeasures, ComponentDto project, Map<Integer, MetricDto> metricsById,
+ private void writeResponse(Response response, List<CustomMeasureDto> customMeasures, int nbCustomMeasures, ComponentDto project, Map<String, MetricDto> metricsByUuid,
Map<String, UserDto> usersByUuid, @Nullable Long lastAnalysisDate, SearchOptions searchOptions, @Nullable List<String> fieldsToReturn) {
JsonWriter json = response.newJsonWriter();
json.beginObject();
- writeUsers(json, customMeasures, project, metricsById, usersByUuid, lastAnalysisDate, fieldsToReturn);
+ writeUsers(json, customMeasures, project, metricsByUuid, usersByUuid, lastAnalysisDate, fieldsToReturn);
searchOptions.writeJson(json, nbCustomMeasures);
json.endObject();
json.close();
}
- private void writeUsers(JsonWriter json, List<CustomMeasureDto> customMeasures, ComponentDto project, Map<Integer, MetricDto> metricsById, Map<String, UserDto> usersByUuids,
+ private void writeUsers(JsonWriter json, List<CustomMeasureDto> customMeasures, ComponentDto project, Map<String, MetricDto> metricsByUuid, Map<String, UserDto> usersByUuids,
@Nullable Long lastAnalysisTimestamp, @Nullable Collection<String> fieldsToReturn) {
json.name("customMeasures");
json.beginArray();
for (CustomMeasureDto customMeasure : customMeasures) {
boolean pending = lastAnalysisTimestamp == null || lastAnalysisTimestamp < customMeasure.getUpdatedAt();
- customMeasureJsonWriter.write(json, customMeasure, metricsById.get(customMeasure.getMetricId()), project, usersByUuids.get(customMeasure.getUserUuid()), pending,
+ customMeasureJsonWriter.write(json, customMeasure, metricsByUuid.get(customMeasure.getMetricUuid()), project, usersByUuids.get(customMeasure.getUserUuid()), pending,
fieldsToReturn);
}
json.endArray();
}
- private Map<Integer, MetricDto> metricsById(DbSession dbSession, List<CustomMeasureDto> customMeasures) {
- List<MetricDto> metrics = dbClient.metricDao().selectByIds(dbSession, newHashSet(Lists.transform(customMeasures, CustomMeasureToMetricIdFunction.INSTANCE)));
- return Maps.uniqueIndex(metrics, MetricToIdFunction.INSTANCE);
+ private Map<String, MetricDto> metricsByUuid(DbSession dbSession, List<CustomMeasureDto> customMeasures) {
+ Set<String> uuids = customMeasures.stream().map(CustomMeasureDto::getMetricUuid).collect(Collectors.toSet());
+ List<MetricDto> metrics = dbClient.metricDao().selectByUuids(dbSession, uuids);
+ return metrics.stream().collect(Collectors.toMap(MetricDto::getUuid, m -> m));
}
private Map<String, UserDto> usersByUuid(DbSession dbSession, List<CustomMeasureDto> customMeasures) {
@@ -160,22 +157,4 @@ public class SearchAction implements CustomMeasuresWsAction {
List<UserDto> users = dbClient.userDao().selectByUuids(dbSession, userUuids);
return users.stream().collect(MoreCollectors.uniqueIndex(UserDto::getUuid));
}
-
- private enum CustomMeasureToMetricIdFunction implements Function<CustomMeasureDto, Integer> {
- INSTANCE;
-
- @Override
- public Integer apply(@Nonnull CustomMeasureDto customMeasure) {
- return customMeasure.getMetricId();
- }
- }
-
- private enum MetricToIdFunction implements Function<MetricDto, Integer> {
- INSTANCE;
-
- @Override
- public Integer apply(@Nonnull MetricDto metric) {
- return metric.getId();
- }
- }
}
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/custom/ws/UpdateAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/custom/ws/UpdateAction.java
index a6b971682a2..fa8fc28edd2 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/custom/ws/UpdateAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/custom/ws/UpdateAction.java
@@ -92,9 +92,9 @@ public class UpdateAction implements CustomMeasuresWsAction {
try (DbSession dbSession = dbClient.openSession(true)) {
CustomMeasureDto customMeasure = dbClient.customMeasureDao().selectByUuid(dbSession, uuid)
.orElseThrow(() -> new IllegalArgumentException(format("Custom measure with id '%s' does not exist", uuid)));
- int customMetricId = customMeasure.getMetricId();
- MetricDto metric = dbClient.metricDao().selectById(dbSession, customMetricId);
- checkState(metric != null, "Metric with id '%s' does not exist", customMetricId);
+ String customMetricUuid = customMeasure.getMetricUuid();
+ MetricDto metric = dbClient.metricDao().selectByUuid(dbSession, customMetricUuid);
+ checkState(metric != null, "Metric with uuid '%s' does not exist", customMetricUuid);
ComponentDto component = dbClient.componentDao().selectOrFailByUuid(dbSession, customMeasure.getComponentUuid());
checkPermissions(userSession, component);
String userUuid = requireNonNull(userSession.getUuid(), "User uuid should not be null");
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/LiveMeasureComputerImpl.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/LiveMeasureComputerImpl.java
index 7ee3d039f4e..239cc0c72f5 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/LiveMeasureComputerImpl.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/LiveMeasureComputerImpl.java
@@ -107,10 +107,10 @@ public class LiveMeasureComputerImpl implements LiveMeasureComputer {
Collection<String> metricKeys = getKeysOfAllInvolvedMetrics(qualityGate);
List<MetricDto> metrics = dbClient.metricDao().selectByKeys(dbSession, metricKeys);
- Map<Integer, MetricDto> metricsPerId = metrics.stream()
- .collect(uniqueIndex(MetricDto::getId));
+ Map<String, MetricDto> metricsPerId = metrics.stream()
+ .collect(uniqueIndex(MetricDto::getUuid));
List<String> componentUuids = components.stream().map(ComponentDto::uuid).collect(toArrayList(components.size()));
- List<LiveMeasureDto> dbMeasures = dbClient.liveMeasureDao().selectByComponentUuidsAndMetricIds(dbSession, componentUuids, metricsPerId.keySet());
+ List<LiveMeasureDto> dbMeasures = dbClient.liveMeasureDao().selectByComponentUuidsAndMetricUuids(dbSession, componentUuids, metricsPerId.keySet());
// previous status must be load now as MeasureMatrix mutate the LiveMeasureDto which are passed to it
Metric.Level previousStatus = loadPreviousStatus(metrics, dbMeasures);
@@ -171,7 +171,7 @@ public class LiveMeasureComputerImpl implements LiveMeasureComputer {
.findAny()
.orElseThrow(() -> new IllegalStateException(String.format("Metric with key %s is not registered", ALERT_STATUS_KEY)));
return dbMeasures.stream()
- .filter(m -> m.getMetricId() == alertStatusMetric.getId())
+ .filter(m -> m.getMetricUuid().equals(alertStatusMetric.getUuid()))
.map(LiveMeasureDto::getTextValue)
.filter(Objects::nonNull)
.map(m -> {
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/LiveQualityGateComputerImpl.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/LiveQualityGateComputerImpl.java
index e0d4ff3220c..310bbeb09bb 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/LiveQualityGateComputerImpl.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/LiveQualityGateComputerImpl.java
@@ -68,13 +68,13 @@ public class LiveQualityGateComputerImpl implements LiveQualityGateComputer {
.orElseThrow(() -> new IllegalStateException(format("Quality Gate not found for project %s", project.getKey())))
.getQualityGate();
Collection<QualityGateConditionDto> conditionDtos = dbClient.gateConditionDao().selectForQualityGate(dbSession, gateDto.getId());
- Set<Integer> metricIds = conditionDtos.stream().map(c -> (int) c.getMetricId())
+ Set<String> metricUuids = conditionDtos.stream().map(QualityGateConditionDto::getMetricUuid)
.collect(toHashSet(conditionDtos.size()));
- Map<Integer, MetricDto> metricsById = dbClient.metricDao().selectByIds(dbSession, metricIds).stream()
- .collect(uniqueIndex(MetricDto::getId));
+ Map<String, MetricDto> metricsByUuid = dbClient.metricDao().selectByUuids(dbSession, metricUuids).stream()
+ .collect(uniqueIndex(MetricDto::getUuid));
Stream<Condition> conditions = conditionDtos.stream().map(conditionDto -> {
- String metricKey = metricsById.get((int) conditionDto.getMetricId()).getKey();
+ String metricKey = metricsByUuid.get(conditionDto.getMetricUuid()).getKey();
Condition.Operator operator = Condition.Operator.fromDbValue(conditionDto.getOperator());
return new Condition(metricKey, operator, conditionDto.getErrorThreshold());
});
@@ -93,7 +93,7 @@ public class LiveQualityGateComputerImpl implements LiveQualityGateComputer {
if (!liveMeasureDto.isPresent()) {
return Optional.empty();
}
- MetricDto metric = measureMatrix.getMetric(liveMeasureDto.get().getMetricId());
+ MetricDto metric = measureMatrix.getMetricByUuid(liveMeasureDto.get().getMetricUuid());
return Optional.of(new LiveMeasure(liveMeasureDto.get(), metric));
};
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/MeasureMatrix.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/MeasureMatrix.java
index 84234d83e24..b6f18bc4a68 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/MeasureMatrix.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/MeasureMatrix.java
@@ -54,21 +54,21 @@ class MeasureMatrix {
private final Table<String, String, MeasureCell> table;
private final Map<String, MetricDto> metricsByKeys = new HashMap<>();
- private final Map<Integer, MetricDto> metricsByIds = new HashMap<>();
+ private final Map<String, MetricDto> metricsByUuids = new HashMap<>();
MeasureMatrix(Collection<ComponentDto> components, Collection<MetricDto> metrics, List<LiveMeasureDto> dbMeasures) {
for (MetricDto metric : metrics) {
this.metricsByKeys.put(metric.getKey(), metric);
- this.metricsByIds.put(metric.getId(), metric);
+ this.metricsByUuids.put(metric.getUuid(), metric);
}
this.table = ArrayTable.create(Collections2.transform(components, ComponentDto::uuid), metricsByKeys.keySet());
for (LiveMeasureDto dbMeasure : dbMeasures) {
- table.put(dbMeasure.getComponentUuid(), metricsByIds.get(dbMeasure.getMetricId()).getKey(), new MeasureCell(dbMeasure, false));
+ table.put(dbMeasure.getComponentUuid(), metricsByUuids.get(dbMeasure.getMetricUuid()).getKey(), new MeasureCell(dbMeasure, false));
}
}
- MetricDto getMetric(int id) {
- return requireNonNull(metricsByIds.get(id), () -> String.format("Metric with id %d not found", id));
+ MetricDto getMetricByUuid(String uuid) {
+ return requireNonNull(metricsByUuids.get(uuid), () -> String.format("Metric with uuid %s not found", uuid));
}
private MetricDto getMetric(String key) {
@@ -158,7 +158,7 @@ class MeasureMatrix {
LiveMeasureDto measure = new LiveMeasureDto()
.setComponentUuid(component.uuid())
.setProjectUuid(component.projectUuid())
- .setMetricId(metricsByKeys.get(metricKey).getId());
+ .setMetricUuid(metricsByKeys.get(metricKey).getUuid());
cell = new MeasureCell(measure, true);
table.put(component.uuid(), metricKey, cell);
changer.apply(cell.getMeasure());
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentAction.java
index b6542ab39ef..1ee0fb12cf5 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentAction.java
@@ -174,17 +174,17 @@ public class ComponentAction implements MeasuresWsAction {
}
private List<LiveMeasureDto> searchMeasures(DbSession dbSession, ComponentDto component, Collection<MetricDto> metrics) {
- Set<Integer> metricIds = metrics.stream().map(MetricDto::getId).collect(Collectors.toSet());
- List<LiveMeasureDto> measures = dbClient.liveMeasureDao().selectByComponentUuidsAndMetricIds(dbSession, singletonList(component.uuid()), metricIds);
+ Set<String> metricUuids = metrics.stream().map(MetricDto::getUuid).collect(Collectors.toSet());
+ List<LiveMeasureDto> measures = dbClient.liveMeasureDao().selectByComponentUuidsAndMetricUuids(dbSession, singletonList(component.uuid()), metricUuids);
addBestValuesToMeasures(measures, component, metrics);
return measures;
}
private static Map<MetricDto, LiveMeasureDto> getMeasuresByMetric(List<LiveMeasureDto> measures, Collection<MetricDto> metrics) {
- Map<Integer, MetricDto> metricsById = Maps.uniqueIndex(metrics, MetricDto::getId);
+ Map<String, MetricDto> metricsByUuid = Maps.uniqueIndex(metrics, MetricDto::getUuid);
Map<MetricDto, LiveMeasureDto> measuresByMetric = new HashMap<>();
for (LiveMeasureDto measure : measures) {
- MetricDto metric = metricsById.get(measure.getMetricId());
+ MetricDto metric = metricsByUuid.get(measure.getMetricUuid());
measuresByMetric.put(metric, measure);
}
return measuresByMetric;
@@ -206,10 +206,10 @@ public class ComponentAction implements MeasuresWsAction {
.filter(MetricDtoFunctions.isOptimizedForBestValue())
.map(MetricDtoWithBestValue::new)
.collect(MoreCollectors.toList(metrics.size()));
- Map<Integer, LiveMeasureDto> measuresByMetricId = Maps.uniqueIndex(measures, LiveMeasureDto::getMetricId);
+ Map<String, LiveMeasureDto> measuresByMetricUuid = Maps.uniqueIndex(measures, LiveMeasureDto::getMetricUuid);
for (MetricDtoWithBestValue metricWithBestValue : metricWithBestValueList) {
- if (measuresByMetricId.get(metricWithBestValue.getMetric().getId()) == null) {
+ if (measuresByMetricUuid.get(metricWithBestValue.getMetric().getUuid()) == null) {
measures.add(metricWithBestValue.getBestValue());
}
}
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentTreeAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentTreeAction.java
index 236f05dda75..9855dd6e7ca 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentTreeAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentTreeAction.java
@@ -503,12 +503,12 @@ public class ComponentTreeAction implements MeasuresWsAction {
private Table<String, MetricDto, ComponentTreeData.Measure> searchMeasuresByComponentUuidAndMetric(DbSession dbSession, ComponentDto baseComponent,
ComponentTreeQuery componentTreeQuery, List<ComponentDto> components, List<MetricDto> metrics) {
- Map<Integer, MetricDto> metricsById = Maps.uniqueIndex(metrics, MetricDto::getId);
+ Map<String, MetricDto> metricsByUuid = Maps.uniqueIndex(metrics, MetricDto::getUuid);
MeasureTreeQuery measureQuery = MeasureTreeQuery.builder()
.setStrategy(MeasureTreeQuery.Strategy.valueOf(componentTreeQuery.getStrategy().name()))
.setNameOrKeyQuery(componentTreeQuery.getNameOrKeyQuery())
.setQualifiers(componentTreeQuery.getQualifiers())
- .setMetricIds(new ArrayList<>(metricsById.keySet()))
+ .setMetricUuids(new ArrayList<>(metricsByUuid.keySet()))
.build();
Table<String, MetricDto, ComponentTreeData.Measure> measuresByComponentUuidAndMetric = HashBasedTable.create(components.size(), metrics.size());
@@ -516,7 +516,7 @@ public class ComponentTreeAction implements MeasuresWsAction {
LiveMeasureDto measureDto = result.getResultObject();
measuresByComponentUuidAndMetric.put(
measureDto.getComponentUuid(),
- metricsById.get(measureDto.getMetricId()),
+ metricsByUuid.get(measureDto.getMetricUuid()),
ComponentTreeData.Measure.createFromMeasureDto(measureDto));
});
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/MetricDtoWithBestValue.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/MetricDtoWithBestValue.java
index d017dfe72f7..0c43ede2d45 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/MetricDtoWithBestValue.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/MetricDtoWithBestValue.java
@@ -37,7 +37,7 @@ public class MetricDtoWithBestValue {
MetricDtoWithBestValue(MetricDto metric) {
this.metric = metric;
- LiveMeasureDto measure = new LiveMeasureDto().setMetricId(metric.getId());
+ LiveMeasureDto measure = new LiveMeasureDto().setMetricUuid(metric.getUuid());
boolean isNewTypeMetric = metric.getKey().toLowerCase(Locale.ENGLISH).startsWith(LOWER_CASE_NEW_METRIC_PREFIX);
if (isNewTypeMetric) {
measure.setVariation(metric.getBestValue());
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/PrMeasureFix.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/PrMeasureFix.java
index 0393af59be0..498b5454a11 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/PrMeasureFix.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/PrMeasureFix.java
@@ -142,7 +142,7 @@ class PrMeasureFix {
if (originalKey != null && requestedMetricKeys.contains(originalKey)) {
MetricDto metricDto = metricByKey.get(originalKey);
- newEntries.put(metricDto, copyMeasureToVariation(e.getValue(), metricDto.getId()));
+ newEntries.put(metricDto, copyMeasureToVariation(e.getValue(), metricDto.getUuid()));
}
}
@@ -154,12 +154,12 @@ class PrMeasureFix {
return new ComponentTreeData.Measure(null, null, measure.getValue());
}
- private static LiveMeasureDto copyMeasureToVariation(LiveMeasureDto dto, Integer metricId) {
+ private static LiveMeasureDto copyMeasureToVariation(LiveMeasureDto dto, String metricUuid) {
LiveMeasureDto copy = new LiveMeasureDto();
copy.setVariation(dto.getValue());
copy.setProjectUuid(dto.getProjectUuid());
copy.setComponentUuid(dto.getComponentUuid());
- copy.setMetricId(metricId);
+ copy.setMetricUuid(metricUuid);
return copy;
}
}
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/SearchAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/SearchAction.java
index 1f464ff162d..7f7c0bc6771 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/SearchAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/SearchAction.java
@@ -162,9 +162,9 @@ public class SearchAction implements MeasuresWsAction {
}
private List<LiveMeasureDto> searchMeasures() {
- return dbClient.liveMeasureDao().selectByComponentUuidsAndMetricIds(dbSession,
+ return dbClient.liveMeasureDao().selectByComponentUuidsAndMetricUuids(dbSession,
projects.stream().map(ComponentDto::uuid).collect(MoreCollectors.toArrayList(projects.size())),
- metrics.stream().map(MetricDto::getId).collect(MoreCollectors.toArrayList(metrics.size())));
+ metrics.stream().map(MetricDto::getUuid).collect(MoreCollectors.toArrayList(metrics.size())));
}
private SearchWsResponse buildResponse() {
@@ -177,9 +177,9 @@ public class SearchAction implements MeasuresWsAction {
private List<Measure> buildWsMeasures() {
Map<String, ComponentDto> componentsByUuid = projects.stream().collect(toMap(ComponentDto::uuid, Function.identity()));
Map<String, String> componentNamesByKey = projects.stream().collect(toMap(ComponentDto::getDbKey, ComponentDto::name));
- Map<Integer, MetricDto> metricsById = metrics.stream().collect(toMap(MetricDto::getId, identity()));
+ Map<String, MetricDto> metricsByUuid = metrics.stream().collect(toMap(MetricDto::getUuid, identity()));
- Function<LiveMeasureDto, MetricDto> dbMeasureToDbMetric = dbMeasure -> metricsById.get(dbMeasure.getMetricId());
+ Function<LiveMeasureDto, MetricDto> dbMeasureToDbMetric = dbMeasure -> metricsByUuid.get(dbMeasure.getMetricUuid());
Function<Measure, String> byMetricKey = Measure::getMetric;
Function<Measure, String> byComponentName = wsMeasure -> componentNamesByKey.get(wsMeasure.getComponent());
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/SearchHistoryAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/SearchHistoryAction.java
index f40a27f3227..f32b9a93c3f 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/SearchHistoryAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/SearchHistoryAction.java
@@ -174,7 +174,7 @@ public class SearchHistoryAction implements MeasuresWsAction {
Date to = parseEndingDateOrDateTime(request.getTo());
PastMeasureQuery dbQuery = new PastMeasureQuery(
result.getComponent().uuid(),
- result.getMetrics().stream().map(MetricDto::getId).collect(MoreCollectors.toList()),
+ result.getMetrics().stream().map(MetricDto::getUuid).collect(MoreCollectors.toList()),
from == null ? null : from.getTime(),
to == null ? null : (to.getTime() + 1_000L));
return dbClient.measureDao().selectPastMeasures(dbSession, dbQuery);
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/SearchHistoryResponseFactory.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/SearchHistoryResponseFactory.java
index a34b2ea7282..f17bf9e5b01 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/SearchHistoryResponseFactory.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/SearchHistoryResponseFactory.java
@@ -61,10 +61,10 @@ class SearchHistoryResponseFactory {
}
private UnaryOperator<SearchHistoryResponse.Builder> addMeasures() {
- Map<Integer, MetricDto> metricsById = result.getMetrics().stream().collect(MoreCollectors.uniqueIndex(MetricDto::getId));
+ Map<String, MetricDto> metricsByUuid = result.getMetrics().stream().collect(MoreCollectors.uniqueIndex(MetricDto::getUuid));
Map<String, SnapshotDto> analysesByUuid = result.getAnalyses().stream().collect(MoreCollectors.uniqueIndex(SnapshotDto::getUuid));
Table<MetricDto, SnapshotDto, MeasureDto> measuresByMetricByAnalysis = HashBasedTable.create(result.getMetrics().size(), result.getAnalyses().size());
- result.getMeasures().forEach(m -> measuresByMetricByAnalysis.put(metricsById.get(m.getMetricId()), analysesByUuid.get(m.getAnalysisUuid()), m));
+ result.getMeasures().forEach(m -> measuresByMetricByAnalysis.put(metricsByUuid.get(m.getMetricUuid()), analysesByUuid.get(m.getAnalysisUuid()), m));
return response -> {
result.getMetrics().stream()
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/SearchHistoryResult.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/SearchHistoryResult.java
index a3dcb6b58a0..aed6700e217 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/SearchHistoryResult.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/SearchHistoryResult.java
@@ -115,13 +115,13 @@ public class SearchHistoryResult {
requireNonNull(metrics);
requireNonNull(analyses);
- Table<Integer, String, MeasureDto> measuresByMetricIdAndAnalysisUuid = HashBasedTable.create(metrics.size(), analyses.size());
- measures.forEach(measure -> measuresByMetricIdAndAnalysisUuid.put(measure.getMetricId(), measure.getAnalysisUuid(), measure));
+ Table<String, String, MeasureDto> measuresByMetricUuidAndAnalysisUuid = HashBasedTable.create(metrics.size(), analyses.size());
+ measures.forEach(measure -> measuresByMetricUuidAndAnalysisUuid.put(measure.getMetricUuid(), measure.getAnalysisUuid(), measure));
List<MeasureDto> bestValues = new ArrayList<>();
metrics.stream()
.filter(isOptimizedForBestValue())
.forEach(metric -> analyses.stream()
- .filter(analysis -> !measuresByMetricIdAndAnalysisUuid.contains(metric.getId(), analysis.getUuid()))
+ .filter(analysis -> !measuresByMetricUuidAndAnalysisUuid.contains(metric.getUuid(), analysis.getUuid()))
.map(analysis -> toBestValue(metric, analysis))
.forEach(bestValues::add));
@@ -130,7 +130,7 @@ public class SearchHistoryResult {
private static MeasureDto toBestValue(MetricDto metric, SnapshotDto analysis) {
MeasureDto measure = new MeasureDto()
- .setMetricId(metric.getId())
+ .setMetricUuid(metric.getUuid())
.setAnalysisUuid(analysis.getUuid());
if (metric.getKey().startsWith("new_")) {
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/metric/ws/CreateAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/metric/ws/CreateAction.java
index 08acdd947a0..13f8728b7b4 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/metric/ws/CreateAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/metric/ws/CreateAction.java
@@ -26,6 +26,7 @@ import org.sonar.api.server.ws.Request;
import org.sonar.api.server.ws.Response;
import org.sonar.api.server.ws.WebService;
import org.sonar.api.utils.text.JsonWriter;
+import org.sonar.core.util.UuidFactory;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.measure.custom.CustomMeasureDto;
@@ -57,10 +58,12 @@ public class CreateAction implements MetricsWsAction {
private final DbClient dbClient;
private final UserSession userSession;
+ private final UuidFactory uuidFactory;
- public CreateAction(DbClient dbClient, UserSession userSession) {
+ public CreateAction(DbClient dbClient, UserSession userSession, UuidFactory uuidFactory) {
this.dbClient = dbClient;
this.userSession = userSession;
+ this.uuidFactory = uuidFactory;
}
@Override
@@ -157,6 +160,7 @@ public class CreateAction implements MetricsWsAction {
private MetricDto insertNewMetric(DbSession dbSession, MetricDto metricTemplate) {
MetricDto metric = new MetricDto()
+ .setUuid(uuidFactory.create())
.setKey(metricTemplate.getKey())
.setShortName(metricTemplate.getShortName())
.setValueType(metricTemplate.getValueType())
@@ -183,7 +187,7 @@ public class CreateAction implements MetricsWsAction {
checkRequest(!isMetricEnabled(metricInDb), "An active metric already exist with key: " + metricInDb.getKey());
checkRequest(!isMetricNonCustom(metricInDb), "An non custom metric already exist with key: %s", metricInDb.getKey());
if (hasMetricTypeChanged(metricInDb, template)) {
- List<CustomMeasureDto> customMeasures = dbClient.customMeasureDao().selectByMetricId(dbSession, metricInDb.getId());
+ List<CustomMeasureDto> customMeasures = dbClient.customMeasureDao().selectByMetricUuid(dbSession, metricInDb.getUuid());
checkRequest(!hasAssociatedCustomMeasures(customMeasures), "You're trying to change the type '%s' while there are associated measures.", metricInDb.getValueType());
}
}
@@ -214,7 +218,7 @@ public class CreateAction implements MetricsWsAction {
private static void writeMetric(JsonWriter json, MetricDto metric) {
json.beginObject();
- json.prop(FIELD_ID, metric.getId().toString());
+ json.prop(FIELD_ID, metric.getUuid());
json.prop(FIELD_KEY, metric.getKey());
json.prop(FIELD_NAME, metric.getShortName());
json.prop(FIELD_TYPE, metric.getValueType());
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/metric/ws/DeleteAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/metric/ws/DeleteAction.java
index d3011931989..1ba3204019d 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/metric/ws/DeleteAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/metric/ws/DeleteAction.java
@@ -55,7 +55,7 @@ public class DeleteAction implements MetricsWsAction {
.setPost(true);
action.createParam(PARAM_IDS)
- .setDescription("Metrics ids to delete.")
+ .setDescription("Metrics uuids to delete.")
.setExampleValue("5, 23, 42");
action.createParam(PARAM_KEYS)
@@ -68,9 +68,9 @@ public class DeleteAction implements MetricsWsAction {
userSession.checkLoggedIn().checkIsSystemAdministrator();
try (DbSession dbSession = dbClient.openSession(false)) {
- List<Integer> ids = loadIds(dbSession, request);
- dbClient.metricDao().disableCustomByIds(dbSession, ids);
- dbClient.customMeasureDao().deleteByMetricIds(dbSession, ids);
+ List<String> uuids = loadUuids(dbSession, request);
+ dbClient.metricDao().disableCustomByUuids(dbSession, uuids);
+ dbClient.customMeasureDao().deleteByMetricUuids(dbSession, uuids);
dbClient.gateConditionDao().deleteConditionsWithInvalidMetrics(dbSession);
dbSession.commit();
}
@@ -78,17 +78,14 @@ public class DeleteAction implements MetricsWsAction {
response.noContent();
}
- private List<Integer> loadIds(DbSession dbSession, Request request) {
- List<String> idsAsStrings = request.paramAsStrings(PARAM_IDS);
+ private List<String> loadUuids(DbSession dbSession, Request request) {
+ List<String> uuids = request.paramAsStrings(PARAM_IDS);
List<String> keys = request.paramAsStrings(PARAM_KEYS);
- checkArgument(idsAsStrings != null || keys != null, "Ids or keys must be provided.");
- List<Integer> ids;
- if (idsAsStrings != null) {
- ids = Lists.transform(idsAsStrings, Integer::valueOf);
- } else {
- ids = Lists.transform(dbClient.metricDao().selectByKeys(dbSession, keys), MetricDto::getId);
+ checkArgument(uuids != null || keys != null, "Uuids or keys must be provided.");
+ if (uuids == null) {
+ uuids = Lists.transform(dbClient.metricDao().selectByKeys(dbSession, keys), MetricDto::getUuid);
}
- return ids;
+ return uuids;
}
}
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/metric/ws/MetricJsonWriter.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/metric/ws/MetricJsonWriter.java
index 7f62a9ef3ca..1e97d54b617 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/metric/ws/MetricJsonWriter.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/metric/ws/MetricJsonWriter.java
@@ -60,7 +60,7 @@ public class MetricJsonWriter {
public static void write(JsonWriter json, MetricDto metric, Set<String> fieldsToReturn) {
json.beginObject();
- json.prop(FIELD_ID, String.valueOf(metric.getId()));
+ json.prop(FIELD_ID, String.valueOf(metric.getUuid()));
json.prop(FIELD_KEY, metric.getKey());
json.prop(FIELD_TYPE, metric.getValueType());
writeIfNeeded(json, metric.getShortName(), FIELD_NAME, fieldsToReturn);
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/metric/ws/UpdateAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/metric/ws/UpdateAction.java
index b54b7164cd0..bbaa5b790f0 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/metric/ws/UpdateAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/metric/ws/UpdateAction.java
@@ -75,7 +75,7 @@ public class UpdateAction implements MetricsWsAction {
action.createParam(PARAM_ID)
.setRequired(true)
- .setDescription("Id of the custom metric to update")
+ .setDescription("UUID of the custom metric to update")
.setExampleValue("42");
action.createParam(PARAM_KEY)
@@ -107,11 +107,11 @@ public class UpdateAction implements MetricsWsAction {
@Override
public void handle(Request request, Response response) throws Exception {
userSession.checkLoggedIn().checkIsSystemAdministrator();
- int id = request.mandatoryParamAsInt(PARAM_ID);
+ String uuid = request.mandatoryParam(PARAM_ID);
try (DbSession dbSession = dbClient.openSession(false)) {
MetricDto metricTemplate = newMetricTemplate(request);
- MetricDto metricInDb = dbClient.metricDao().selectById(dbSession, id);
+ MetricDto metricInDb = dbClient.metricDao().selectByUuid(dbSession, uuid);
checkMetricInDbAndTemplate(dbSession, metricInDb, metricTemplate);
updateMetricInDb(dbSession, metricInDb, metricTemplate);
@@ -122,7 +122,7 @@ public class UpdateAction implements MetricsWsAction {
}
private static MetricDto newMetricTemplate(Request request) {
- int id = request.mandatoryParamAsInt(PARAM_ID);
+ String uuid = request.mandatoryParam(PARAM_ID);
String key = request.param(PARAM_KEY);
if (key != null) {
MetricKeyValidator.checkMetricKeyFormat(key);
@@ -132,7 +132,7 @@ public class UpdateAction implements MetricsWsAction {
String domain = request.param(PARAM_DOMAIN);
String description = request.param(PARAM_DESCRIPTION);
- MetricDto metricTemplate = new MetricDto().setId(id);
+ MetricDto metricTemplate = new MetricDto().setUuid(uuid);
if (key != null) {
metricTemplate.setKey(key);
}
@@ -178,10 +178,10 @@ public class UpdateAction implements MetricsWsAction {
private void checkMetricInDbAndTemplate(DbSession dbSession, @Nullable MetricDto metricInDb, MetricDto template) {
checkRequest(isMetricFoundInDb(metricInDb) && !isMetricDisabled(metricInDb) && isMetricCustom(metricInDb),
- "No active custom metric has been found for id '%d'.", template.getId());
+ "No active custom metric has been found for uuid '%s'.", template.getUuid());
checkNoOtherMetricWithTargetKey(dbSession, metricInDb, template);
if (haveMetricTypeChanged(metricInDb, template)) {
- List<CustomMeasureDto> customMeasures = dbClient.customMeasureDao().selectByMetricId(dbSession, metricInDb.getId());
+ List<CustomMeasureDto> customMeasures = dbClient.customMeasureDao().selectByMetricUuid(dbSession, metricInDb.getUuid());
checkRequest(!haveAssociatedCustomMeasures(customMeasures), "You're trying to change the type '%s' while there are associated custom measures.", metricInDb.getValueType());
}
}
@@ -189,13 +189,13 @@ public class UpdateAction implements MetricsWsAction {
private void checkNoOtherMetricWithTargetKey(DbSession dbSession, MetricDto metricInDb, MetricDto template) {
String targetKey = template.getKey();
MetricDto metricWithTargetKey = dbClient.metricDao().selectByKey(dbSession, targetKey);
- checkRequest(!isMetricFoundInDb(metricWithTargetKey) || metricInDb.getId().equals(metricWithTargetKey.getId()),
+ checkRequest(!isMetricFoundInDb(metricWithTargetKey) || metricInDb.getUuid().equals(metricWithTargetKey.getUuid()),
"The key '%s' is already used by an existing metric.", targetKey);
}
private static void writeMetric(JsonWriter json, MetricDto metric) {
json.beginObject();
- json.prop(FIELD_ID, String.valueOf(metric.getId()));
+ json.prop(FIELD_ID, String.valueOf(metric.getUuid()));
json.prop(FIELD_KEY, metric.getKey());
json.prop(FIELD_TYPE, metric.getValueType());
json.prop(FIELD_NAME, metric.getShortName());
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/QualityGateConditionsUpdater.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/QualityGateConditionsUpdater.java
index 81995bfb175..ab5c13bffcf 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/QualityGateConditionsUpdater.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/QualityGateConditionsUpdater.java
@@ -94,7 +94,7 @@ public class QualityGateConditionsUpdater {
QualityGateConditionDto newCondition = new QualityGateConditionDto().setQualityGateId(qualityGate.getId())
.setUuid(Uuids.create())
- .setMetricId(metric.getId()).setMetricKey(metric.getKey())
+ .setMetricUuid(metric.getUuid()).setMetricKey(metric.getKey())
.setOperator(operator)
.setErrorThreshold(errorThreshold);
dbClient.gateConditionDao().insert(newCondition, dbSession);
@@ -107,7 +107,7 @@ public class QualityGateConditionsUpdater {
validateCondition(metric, operator, errorThreshold);
condition
- .setMetricId(metric.getId())
+ .setMetricUuid(metric.getUuid())
.setMetricKey(metric.getKey())
.setOperator(operator)
.setErrorThreshold(errorThreshold);
@@ -163,7 +163,7 @@ public class QualityGateConditionsUpdater {
return;
}
- boolean conditionExists = conditions.stream().anyMatch(c -> c.getMetricId() == metric.getId());
+ boolean conditionExists = conditions.stream().anyMatch(c -> c.getMetricUuid().equals(metric.getUuid()));
checkRequest(!conditionExists, format("Condition on metric '%s' already exists.", metric.getShortName()));
}
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/QualityGateUpdater.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/QualityGateUpdater.java
index 29bb767aa7f..1f978335852 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/QualityGateUpdater.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/QualityGateUpdater.java
@@ -59,7 +59,7 @@ public class QualityGateUpdater {
dbClient.gateConditionDao().insert(new QualityGateConditionDto()
.setUuid(Uuids.create())
.setQualityGateId(destinationGate.getId())
- .setMetricId(sourceCondition.getMetricId())
+ .setMetricUuid(sourceCondition.getMetricUuid())
.setOperator(sourceCondition.getOperator())
.setErrorThreshold(sourceCondition.getErrorThreshold()),
dbSession);
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/RegisterQualityGates.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/RegisterQualityGates.java
index dad60af40b2..59ce7781722 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/RegisterQualityGates.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/RegisterQualityGates.java
@@ -110,12 +110,12 @@ public class RegisterQualityGates implements Startable {
}
private void updateQualityConditionsIfRequired(DbSession dbSession, QualityGateDto builtin) {
- Map<Long, String> idToKeyMetric = dbClient.metricDao().selectAll(dbSession).stream()
- .collect(toMap(metricDto -> metricDto.getId().longValue(), MetricDto::getKey));
+ Map<String, String> uuidToKeyMetric = dbClient.metricDao().selectAll(dbSession).stream()
+ .collect(toMap(MetricDto::getUuid, MetricDto::getKey));
List<QualityGateCondition> qualityGateConditions = qualityGateConditionDao.selectForQualityGate(dbSession, builtin.getId())
.stream()
- .map(dto -> QualityGateCondition.from(dto, idToKeyMetric))
+ .map(dto -> QualityGateCondition.from(dto, uuidToKeyMetric))
.collect(MoreCollectors.toList());
// Find all conditions that are not present in QUALITY_GATE_CONDITIONS
@@ -158,10 +158,10 @@ public class RegisterQualityGates implements Startable {
private String operator;
private String errorThreshold;
- public static QualityGateCondition from(QualityGateConditionDto qualityGateConditionDto, Map<Long, String> mapping) {
+ public static QualityGateCondition from(QualityGateConditionDto qualityGateConditionDto, Map<String, String> mapping) {
return new QualityGateCondition()
.setUuid(qualityGateConditionDto.getUuid())
- .setMetricKey(mapping.get(qualityGateConditionDto.getMetricId()))
+ .setMetricKey(mapping.get(qualityGateConditionDto.getMetricUuid()))
.setOperator(qualityGateConditionDto.getOperator())
.setErrorThreshold(qualityGateConditionDto.getErrorThreshold());
}
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/ShowAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/ShowAction.java
index fa41487a015..ae2806fd8f7 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/ShowAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/ShowAction.java
@@ -94,9 +94,9 @@ public class ShowAction implements QualityGatesWsAction {
OrganizationDto organization = wsSupport.getOrganization(dbSession, request);
QualityGateDto qualityGate = getByNameOrId(dbSession, organization, name, id);
Collection<QualityGateConditionDto> conditions = getConditions(dbSession, qualityGate);
- Map<Integer, MetricDto> metricsById = getMetricsById(dbSession, conditions);
+ Map<String, MetricDto> metricsByUuid = getMetricsByUuid(dbSession, conditions);
QualityGateDto defaultQualityGate = qualityGateFinder.getDefault(dbSession, organization);
- writeProtobuf(buildResponse(organization, qualityGate, defaultQualityGate, conditions, metricsById), request, response);
+ writeProtobuf(buildResponse(organization, qualityGate, defaultQualityGate, conditions, metricsByUuid), request, response);
}
}
@@ -114,31 +114,31 @@ public class ShowAction implements QualityGatesWsAction {
return dbClient.gateConditionDao().selectForQualityGate(dbSession, qualityGate.getId());
}
- private Map<Integer, MetricDto> getMetricsById(DbSession dbSession, Collection<QualityGateConditionDto> conditions) {
- Set<Integer> metricIds = conditions.stream().map(c -> (int) c.getMetricId()).collect(toSet());
- return dbClient.metricDao().selectByIds(dbSession, metricIds).stream()
+ private Map<String, MetricDto> getMetricsByUuid(DbSession dbSession, Collection<QualityGateConditionDto> conditions) {
+ Set<String> metricUuids = conditions.stream().map(QualityGateConditionDto::getMetricUuid).collect(toSet());
+ return dbClient.metricDao().selectByUuids(dbSession, metricUuids).stream()
.filter(MetricDto::isEnabled)
- .collect(uniqueIndex(MetricDto::getId));
+ .collect(uniqueIndex(MetricDto::getUuid));
}
private ShowWsResponse buildResponse(OrganizationDto organization, QualityGateDto qualityGate, QualityGateDto defaultQualityGate,
- Collection<QualityGateConditionDto> conditions, Map<Integer, MetricDto> metricsById) {
+ Collection<QualityGateConditionDto> conditions, Map<String, MetricDto> metricsByUuid) {
return ShowWsResponse.newBuilder()
.setId(qualityGate.getId())
.setName(qualityGate.getName())
.setIsBuiltIn(qualityGate.isBuiltIn())
.addAllConditions(conditions.stream()
- .map(toWsCondition(metricsById))
+ .map(toWsCondition(metricsByUuid))
.collect(toList()))
.setActions(wsSupport.getActions(organization, qualityGate, defaultQualityGate))
.build();
}
- private static Function<QualityGateConditionDto, ShowWsResponse.Condition> toWsCondition(Map<Integer, MetricDto> metricsById) {
+ private static Function<QualityGateConditionDto, ShowWsResponse.Condition> toWsCondition(Map<String, MetricDto> metricsByUuid) {
return condition -> {
- int metricId = (int) condition.getMetricId();
- MetricDto metric = metricsById.get(metricId);
- checkState(metric != null, "Could not find metric with id %s", metricId);
+ String metricUuid = condition.getMetricUuid();
+ MetricDto metric = metricsByUuid.get(metricUuid);
+ checkState(metric != null, "Could not find metric with id %s", metricUuid);
ShowWsResponse.Condition.Builder builder = ShowWsResponse.Condition.newBuilder()
.setId(condition.getUuid())
.setMetric(metric.getKey())
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/user/ws/DeactivateAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/user/ws/DeactivateAction.java
index 3a5bbf967d4..bde67839642 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/user/ws/DeactivateAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/user/ws/DeactivateAction.java
@@ -23,7 +23,6 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
-import org.sonar.api.config.Configuration;
import org.sonar.api.server.ws.Request;
import org.sonar.api.server.ws.Response;
import org.sonar.api.server.ws.WebService;
@@ -45,7 +44,6 @@ import org.sonar.server.user.index.UserIndexer;
import static java.lang.String.format;
import static java.util.Collections.singletonList;
import static org.sonar.api.CoreProperties.DEFAULT_ISSUE_ASSIGNEE;
-import static org.sonar.process.ProcessProperties.Property.SONARCLOUD_ENABLED;
import static org.sonar.server.exceptions.BadRequestException.checkRequest;
import static org.sonar.server.exceptions.NotFoundException.checkFound;
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/duplication/ws/ShowActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/duplication/ws/ShowActionTest.java
index b5ebb7b7c94..e590d713419 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/duplication/ws/ShowActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/duplication/ws/ShowActionTest.java
@@ -27,6 +27,7 @@ import org.junit.rules.ExpectedException;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.server.ws.WebService;
import org.sonar.api.web.UserRole;
+import org.sonar.core.util.Uuids;
import org.sonar.db.DbTester;
import org.sonar.db.component.BranchType;
import org.sonar.db.component.ComponentDto;
@@ -65,6 +66,7 @@ public class ShowActionTest {
@Before
public void setUp() {
+ dataMetric.setUuid(Uuids.createFast());
db.getDbClient().metricDao().insert(db.getSession(), dataMetric);
db.commit();
}
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/custom/ws/CreateActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/custom/ws/CreateActionTest.java
index 9855267032f..a93819d7501 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/custom/ws/CreateActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/custom/ws/CreateActionTest.java
@@ -78,12 +78,12 @@ public class CreateActionTest {
ws.newRequest()
.setParam(CreateAction.PARAM_PROJECT_ID, project.uuid())
- .setParam(CreateAction.PARAM_METRIC_ID, Integer.toString(metric.getId()))
+ .setParam(CreateAction.PARAM_METRIC_ID, metric.getUuid())
.setParam(CreateAction.PARAM_DESCRIPTION, "custom-measure-description")
.setParam(CreateAction.PARAM_VALUE, "true")
.execute();
- assertThat(db.getDbClient().customMeasureDao().selectByMetricId(db.getSession(), metric.getId()))
+ assertThat(db.getDbClient().customMeasureDao().selectByMetricUuid(db.getSession(), metric.getUuid()))
.extracting(CustomMeasureDto::getDescription, CustomMeasureDto::getTextValue, CustomMeasureDto::getValue, CustomMeasureDto::getComponentUuid)
.containsExactlyInAnyOrder(tuple("custom-measure-description", null, 1d, project.uuid()));
}
@@ -97,11 +97,11 @@ public class CreateActionTest {
ws.newRequest()
.setParam(CreateAction.PARAM_PROJECT_ID, project.uuid())
- .setParam(CreateAction.PARAM_METRIC_ID, metric.getId().toString())
+ .setParam(CreateAction.PARAM_METRIC_ID, metric.getUuid().toString())
.setParam(CreateAction.PARAM_VALUE, "42")
.execute();
- assertThat(db.getDbClient().customMeasureDao().selectByMetricId(db.getSession(), metric.getId()))
+ assertThat(db.getDbClient().customMeasureDao().selectByMetricUuid(db.getSession(), metric.getUuid()))
.extracting(CustomMeasureDto::getDescription, CustomMeasureDto::getTextValue, CustomMeasureDto::getValue, CustomMeasureDto::getComponentUuid)
.containsExactlyInAnyOrder(tuple(null, null, 42d, project.uuid()));
}
@@ -115,11 +115,11 @@ public class CreateActionTest {
ws.newRequest()
.setParam(CreateAction.PARAM_PROJECT_ID, project.uuid())
- .setParam(CreateAction.PARAM_METRIC_ID, metric.getId().toString())
+ .setParam(CreateAction.PARAM_METRIC_ID, metric.getUuid().toString())
.setParam(CreateAction.PARAM_VALUE, "custom-measure-free-text")
.execute();
- assertThat(db.getDbClient().customMeasureDao().selectByMetricId(db.getSession(), metric.getId()))
+ assertThat(db.getDbClient().customMeasureDao().selectByMetricUuid(db.getSession(), metric.getUuid()))
.extracting(CustomMeasureDto::getDescription, CustomMeasureDto::getTextValue, CustomMeasureDto::getValue, CustomMeasureDto::getComponentUuid)
.containsExactlyInAnyOrder(tuple(null, "custom-measure-free-text", 0d, project.uuid()));
}
@@ -137,7 +137,7 @@ public class CreateActionTest {
.setParam(CreateAction.PARAM_VALUE, "whatever-value")
.execute();
- assertThat(db.getDbClient().customMeasureDao().selectByMetricId(db.getSession(), metric.getId()))
+ assertThat(db.getDbClient().customMeasureDao().selectByMetricUuid(db.getSession(), metric.getUuid()))
.extracting(CustomMeasureDto::getDescription, CustomMeasureDto::getTextValue, CustomMeasureDto::getValue, CustomMeasureDto::getComponentUuid)
.containsExactlyInAnyOrder(tuple(null, "whatever-value", 0d, project.uuid()));
}
@@ -151,11 +151,11 @@ public class CreateActionTest {
ws.newRequest()
.setParam(CreateAction.PARAM_PROJECT_KEY, project.getKey())
- .setParam(CreateAction.PARAM_METRIC_ID, metric.getId().toString())
+ .setParam(CreateAction.PARAM_METRIC_ID, metric.getUuid().toString())
.setParam(CreateAction.PARAM_VALUE, "whatever-value")
.execute();
- assertThat(db.getDbClient().customMeasureDao().selectByMetricId(db.getSession(), metric.getId()))
+ assertThat(db.getDbClient().customMeasureDao().selectByMetricUuid(db.getSession(), metric.getUuid()))
.extracting(CustomMeasureDto::getDescription, CustomMeasureDto::getTextValue, CustomMeasureDto::getValue, CustomMeasureDto::getComponentUuid)
.containsExactlyInAnyOrder(tuple(null, "whatever-value", 0d, project.uuid()));
}
@@ -169,11 +169,11 @@ public class CreateActionTest {
ws.newRequest()
.setParam(CreateAction.PARAM_PROJECT_ID, project.uuid())
- .setParam(CreateAction.PARAM_METRIC_ID, metric.getId().toString())
+ .setParam(CreateAction.PARAM_METRIC_ID, metric.getUuid().toString())
.setParam(CreateAction.PARAM_VALUE, "4.2")
.execute();
- assertThat(db.getDbClient().customMeasureDao().selectByMetricId(db.getSession(), metric.getId()))
+ assertThat(db.getDbClient().customMeasureDao().selectByMetricUuid(db.getSession(), metric.getUuid()))
.extracting(CustomMeasureDto::getDescription, CustomMeasureDto::getTextValue, CustomMeasureDto::getValue, CustomMeasureDto::getComponentUuid)
.containsExactlyInAnyOrder(tuple(null, null, 4.2d, project.uuid()));
}
@@ -187,11 +187,11 @@ public class CreateActionTest {
ws.newRequest()
.setParam(CreateAction.PARAM_PROJECT_ID, project.uuid())
- .setParam(CreateAction.PARAM_METRIC_ID, metric.getId().toString())
+ .setParam(CreateAction.PARAM_METRIC_ID, metric.getUuid().toString())
.setParam(CreateAction.PARAM_VALUE, "253")
.execute();
- assertThat(db.getDbClient().customMeasureDao().selectByMetricId(db.getSession(), metric.getId()))
+ assertThat(db.getDbClient().customMeasureDao().selectByMetricUuid(db.getSession(), metric.getUuid()))
.extracting(CustomMeasureDto::getDescription, CustomMeasureDto::getTextValue, CustomMeasureDto::getValue, CustomMeasureDto::getComponentUuid)
.containsExactlyInAnyOrder(tuple(null, null, 253d, project.uuid()));
}
@@ -205,11 +205,11 @@ public class CreateActionTest {
ws.newRequest()
.setParam(CreateAction.PARAM_PROJECT_ID, project.uuid())
- .setParam(CreateAction.PARAM_METRIC_ID, metric.getId().toString())
+ .setParam(CreateAction.PARAM_METRIC_ID, metric.getUuid().toString())
.setParam(CreateAction.PARAM_VALUE, Metric.Level.ERROR.name())
.execute();
- assertThat(db.getDbClient().customMeasureDao().selectByMetricId(db.getSession(), metric.getId()))
+ assertThat(db.getDbClient().customMeasureDao().selectByMetricUuid(db.getSession(), metric.getUuid()))
.extracting(CustomMeasureDto::getDescription, CustomMeasureDto::getTextValue, CustomMeasureDto::getValue, CustomMeasureDto::getComponentUuid)
.containsExactlyInAnyOrder(tuple(null, Metric.Level.ERROR.name(), 0d, project.uuid()));
}
@@ -223,19 +223,19 @@ public class CreateActionTest {
String response = ws.newRequest()
.setParam(CreateAction.PARAM_PROJECT_ID, project.uuid())
- .setParam(CreateAction.PARAM_METRIC_ID, metric.getId().toString())
+ .setParam(CreateAction.PARAM_METRIC_ID, metric.getUuid().toString())
.setParam(CreateAction.PARAM_DESCRIPTION, "custom-measure-description")
.setParam(CreateAction.PARAM_VALUE, "custom-measure-free-text")
.execute()
.getInput();
- CustomMeasureDto customMeasure = db.getDbClient().customMeasureDao().selectByMetricId(db.getSession(), metric.getId()).get(0);
+ CustomMeasureDto customMeasure = db.getDbClient().customMeasureDao().selectByMetricUuid(db.getSession(), metric.getUuid()).get(0);
assertJson(response).isSimilarTo("{\n" +
" \"id\": \"" + customMeasure.getUuid() + "\",\n" +
" \"value\": \"custom-measure-free-text\",\n" +
" \"description\": \"custom-measure-description\",\n" +
" \"metric\": {\n" +
- " \"id\": \"" + metric.getId() + "\",\n" +
+ " \"id\": \"" + metric.getUuid() + "\",\n" +
" \"key\": \"" + metric.getKey() + "\",\n" +
" \"type\": \"" + metric.getValueType() + "\",\n" +
" \"name\": \"" + metric.getShortName() + "\",\n" +
@@ -257,12 +257,12 @@ public class CreateActionTest {
ws.newRequest()
.setParam(CreateAction.PARAM_PROJECT_ID, module.uuid())
- .setParam(CreateAction.PARAM_METRIC_ID, Integer.toString(metric.getId()))
+ .setParam(CreateAction.PARAM_METRIC_ID, metric.getUuid())
.setParam(CreateAction.PARAM_DESCRIPTION, "custom-measure-description")
.setParam(CreateAction.PARAM_VALUE, "true")
.execute();
- assertThat(db.getDbClient().customMeasureDao().selectByMetricId(db.getSession(), metric.getId()))
+ assertThat(db.getDbClient().customMeasureDao().selectByMetricUuid(db.getSession(), metric.getUuid()))
.extracting(CustomMeasureDto::getDescription, CustomMeasureDto::getTextValue, CustomMeasureDto::getValue, CustomMeasureDto::getComponentUuid)
.containsExactlyInAnyOrder(tuple("custom-measure-description", null, 1d, module.uuid()));
}
@@ -277,12 +277,12 @@ public class CreateActionTest {
ws.newRequest()
.setParam(CreateAction.PARAM_PROJECT_ID, view.uuid())
- .setParam(CreateAction.PARAM_METRIC_ID, metric.getId().toString())
+ .setParam(CreateAction.PARAM_METRIC_ID, metric.getUuid().toString())
.setParam(CreateAction.PARAM_DESCRIPTION, "custom-measure-description")
.setParam(CreateAction.PARAM_VALUE, "true")
.execute();
- assertThat(db.getDbClient().customMeasureDao().selectByMetricId(db.getSession(), metric.getId()))
+ assertThat(db.getDbClient().customMeasureDao().selectByMetricUuid(db.getSession(), metric.getUuid()))
.extracting(CustomMeasureDto::getDescription, CustomMeasureDto::getTextValue, CustomMeasureDto::getValue, CustomMeasureDto::getComponentUuid)
.containsExactlyInAnyOrder(tuple("custom-measure-description", null, 1d, view.uuid()));
}
@@ -298,12 +298,12 @@ public class CreateActionTest {
ws.newRequest()
.setParam(CreateAction.PARAM_PROJECT_ID, subView.uuid())
- .setParam(CreateAction.PARAM_METRIC_ID, metric.getId().toString())
+ .setParam(CreateAction.PARAM_METRIC_ID, metric.getUuid().toString())
.setParam(CreateAction.PARAM_DESCRIPTION, "custom-measure-description")
.setParam(CreateAction.PARAM_VALUE, "true")
.execute();
- assertThat(db.getDbClient().customMeasureDao().selectByMetricId(db.getSession(), metric.getId()))
+ assertThat(db.getDbClient().customMeasureDao().selectByMetricUuid(db.getSession(), metric.getUuid()))
.extracting(CustomMeasureDto::getDescription, CustomMeasureDto::getTextValue, CustomMeasureDto::getValue, CustomMeasureDto::getComponentUuid)
.containsExactlyInAnyOrder(tuple("custom-measure-description", null, 1d, subView.uuid()));
}
@@ -320,7 +320,7 @@ public class CreateActionTest {
ws.newRequest()
.setParam(CreateAction.PARAM_METRIC_ID, "whatever-id")
- .setParam(CreateAction.PARAM_VALUE, metric.getId().toString())
+ .setParam(CreateAction.PARAM_VALUE, metric.getUuid().toString())
.execute();
}
@@ -337,7 +337,7 @@ public class CreateActionTest {
ws.newRequest()
.setParam(CreateAction.PARAM_PROJECT_ID, project.uuid())
.setParam(CreateAction.PARAM_PROJECT_KEY, project.getKey())
- .setParam(CreateAction.PARAM_METRIC_ID, metric.getId().toString())
+ .setParam(CreateAction.PARAM_METRIC_ID, metric.getUuid().toString())
.setParam(CreateAction.PARAM_VALUE, "whatever-value")
.execute();
}
@@ -354,7 +354,7 @@ public class CreateActionTest {
ws.newRequest()
.setParam(CreateAction.PARAM_PROJECT_KEY, "another-project-key")
- .setParam(CreateAction.PARAM_METRIC_ID, metric.getId().toString())
+ .setParam(CreateAction.PARAM_METRIC_ID, metric.getUuid().toString())
.setParam(CreateAction.PARAM_VALUE, "whatever-value")
.execute();
}
@@ -371,19 +371,19 @@ public class CreateActionTest {
ws.newRequest()
.setParam(CreateAction.PARAM_PROJECT_ID, "another-project-uuid")
- .setParam(CreateAction.PARAM_METRIC_ID, metric.getId().toString())
+ .setParam(CreateAction.PARAM_METRIC_ID, metric.getUuid().toString())
.setParam(CreateAction.PARAM_VALUE, "whatever-value")
.execute();
}
@Test
- public void fail_when_metric_id_nor_metric_key_is_provided() {
+ public void fail_when_metric_uuid_nor_metric_key_is_provided() {
ComponentDto project = db.components().insertPrivateProject();
UserDto user = db.users().insertUser();
userSession.logIn(user).addProjectPermission(ADMIN, project);
expectedException.expect(IllegalArgumentException.class);
- expectedException.expectMessage("Either the metric id or the metric key must be provided");
+ expectedException.expectMessage("Either the metric uuid or the metric key must be provided");
ws.newRequest()
.setParam(CreateAction.PARAM_PROJECT_ID, project.uuid())
@@ -392,18 +392,18 @@ public class CreateActionTest {
}
@Test
- public void fail_when_metric_id_and_metric_key_are_provided() {
+ public void fail_when_metric_uuid_and_metric_key_are_provided() {
MetricDto metric = db.measures().insertMetric(m -> m.setUserManaged(true).setValueType(STRING.name()));
ComponentDto project = db.components().insertPrivateProject();
UserDto user = db.users().insertUser();
userSession.logIn(user).addProjectPermission(ADMIN, project);
expectedException.expect(IllegalArgumentException.class);
- expectedException.expectMessage("Either the metric id or the metric key must be provided");
+ expectedException.expectMessage("Either the metric uuid or the metric key must be provided");
ws.newRequest()
.setParam(CreateAction.PARAM_PROJECT_ID, project.uuid())
- .setParam(CreateAction.PARAM_METRIC_ID, metric.getId().toString())
+ .setParam(CreateAction.PARAM_METRIC_ID, metric.getUuid().toString())
.setParam(CreateAction.PARAM_METRIC_KEY, metric.getKey())
.setParam(CreateAction.PARAM_VALUE, "whatever-value")
.execute();
@@ -426,13 +426,13 @@ public class CreateActionTest {
}
@Test
- public void fail_when_metric_id_is_not_found_in_db() {
+ public void fail_when_metric_uuid_is_not_found_in_db() {
ComponentDto project = db.components().insertPrivateProject();
UserDto user = db.users().insertUser();
userSession.logIn(user).addProjectPermission(ADMIN, project);
expectedException.expect(IllegalArgumentException.class);
- expectedException.expectMessage("Metric with id '42' does not exist");
+ expectedException.expectMessage("Metric with uuid '42' does not exist");
ws.newRequest()
.setParam(CreateAction.PARAM_PROJECT_ID, project.uuid())
@@ -455,7 +455,7 @@ public class CreateActionTest {
ws.newRequest()
.setParam(CreateAction.PARAM_PROJECT_ID, project.uuid())
- .setParam(CreateAction.PARAM_METRIC_ID, metric.getId().toString())
+ .setParam(CreateAction.PARAM_METRIC_ID, metric.getUuid().toString())
.setParam(CreateAction.PARAM_VALUE, "whatever-value")
.execute();
}
@@ -472,7 +472,7 @@ public class CreateActionTest {
ws.newRequest()
.setParam(CreateAction.PARAM_PROJECT_ID, project.uuid())
- .setParam(CreateAction.PARAM_METRIC_ID, metric.getId().toString())
+ .setParam(CreateAction.PARAM_METRIC_ID, metric.getUuid().toString())
.setParam(CreateAction.PARAM_VALUE, "non-correct-boolean-value")
.execute();
}
@@ -488,7 +488,7 @@ public class CreateActionTest {
ws.newRequest()
.setParam(CreateAction.PARAM_PROJECT_ID, project.uuid())
- .setParam(CreateAction.PARAM_METRIC_ID, metric.getId().toString())
+ .setParam(CreateAction.PARAM_METRIC_ID, metric.getUuid().toString())
.setParam(CreateAction.PARAM_VALUE, "whatever-value")
.execute();
}
@@ -506,7 +506,7 @@ public class CreateActionTest {
ws.newRequest()
.setParam(CreateAction.PARAM_PROJECT_ID, directory.uuid())
- .setParam(CreateAction.PARAM_METRIC_ID, metric.getId().toString())
+ .setParam(CreateAction.PARAM_METRIC_ID, metric.getUuid().toString())
.setParam(CreateAction.PARAM_VALUE, "whatever-value")
.execute();
}
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/custom/ws/MetricsActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/custom/ws/MetricsActionTest.java
index c40e4cfa117..b314dc970bc 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/custom/ws/MetricsActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/custom/ws/MetricsActionTest.java
@@ -102,7 +102,7 @@ public class MetricsActionTest {
CustomMeasureDto customMeasure = newCustomMeasureDto()
.setComponentUuid(defaultProject.uuid())
- .setMetricId(metric.getId());
+ .setMetricUuid(metric.getUuid());
dbClient.customMeasureDao().insert(dbSession, customMeasure);
dbSession.commit();
@@ -120,7 +120,7 @@ public class MetricsActionTest {
CustomMeasureDto customMeasure = newCustomMeasureDto()
.setComponentUuid(defaultProject.uuid())
- .setMetricId(metric.getId());
+ .setMetricUuid(metric.getUuid());
dbClient.customMeasureDao().insert(dbSession, customMeasure);
dbSession.commit();
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/custom/ws/SearchActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/custom/ws/SearchActionTest.java
index ce9495736ec..49a9a44946d 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/custom/ws/SearchActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/custom/ws/SearchActionTest.java
@@ -87,7 +87,7 @@ public class SearchActionTest {
" \"value\": \"" + customMeasure1.getTextValue() + "\",\n" +
" \"description\": \"" + customMeasure1.getDescription() + "\",\n" +
" \"metric\": {\n" +
- " \"id\": \"" + metric1.getId() + "\",\n" +
+ " \"id\": \"" + metric1.getUuid() + "\",\n" +
" \"key\": \"" + metric1.getKey() + "\",\n" +
" \"type\": \"" + metric1.getValueType() + "\",\n" +
" \"name\": \"" + metric1.getShortName() + "\",\n" +
@@ -102,7 +102,7 @@ public class SearchActionTest {
" \"value\": \"" + customMeasure2.getTextValue() + "\",\n" +
" \"description\": \"" + customMeasure2.getDescription() + "\",\n" +
" \"metric\": {\n" +
- " \"id\": \"" + metric2.getId() + "\",\n" +
+ " \"id\": \"" + metric2.getUuid() + "\",\n" +
" \"key\": \"" + metric2.getKey() + "\",\n" +
" \"type\": \"" + metric2.getValueType() + "\",\n" +
" \"name\": \"" + metric2.getShortName() + "\",\n" +
@@ -117,7 +117,7 @@ public class SearchActionTest {
" \"value\": \"" + customMeasure3.getTextValue() + "\",\n" +
" \"description\": \"" + customMeasure3.getDescription() + "\",\n" +
" \"metric\": {\n" +
- " \"id\": \"" + metric3.getId() + "\",\n" +
+ " \"id\": \"" + metric3.getUuid() + "\",\n" +
" \"key\": \"" + metric3.getKey() + "\",\n" +
" \"type\": \"" + metric3.getValueType() + "\",\n" +
" \"name\": \"" + metric3.getShortName() + "\",\n" +
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/custom/ws/UpdateActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/custom/ws/UpdateActionTest.java
index e1970f8840c..dc6832f3161 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/custom/ws/UpdateActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/custom/ws/UpdateActionTest.java
@@ -81,7 +81,7 @@ public class UpdateActionTest {
.setParam(PARAM_VALUE, "new-text-measure-value")
.execute();
- assertThat(db.getDbClient().customMeasureDao().selectByMetricId(db.getSession(), metric.getId()))
+ assertThat(db.getDbClient().customMeasureDao().selectByMetricUuid(db.getSession(), metric.getUuid()))
.extracting(CustomMeasureDto::getDescription, CustomMeasureDto::getTextValue, CustomMeasureDto::getValue, CustomMeasureDto::getUserUuid, CustomMeasureDto::getComponentUuid,
CustomMeasureDto::getCreatedAt, CustomMeasureDto::getUpdatedAt)
.containsExactlyInAnyOrder(
@@ -103,7 +103,7 @@ public class UpdateActionTest {
.setParam(PARAM_VALUE, "1984")
.execute();
- assertThat(db.getDbClient().customMeasureDao().selectByMetricId(db.getSession(), metric.getId()))
+ assertThat(db.getDbClient().customMeasureDao().selectByMetricUuid(db.getSession(), metric.getUuid()))
.extracting(CustomMeasureDto::getDescription, CustomMeasureDto::getTextValue, CustomMeasureDto::getValue, CustomMeasureDto::getUserUuid, CustomMeasureDto::getComponentUuid,
CustomMeasureDto::getCreatedAt, CustomMeasureDto::getUpdatedAt)
.containsExactlyInAnyOrder(
@@ -131,7 +131,7 @@ public class UpdateActionTest {
" \"value\": \"new-text-measure-value\",\n" +
" \"description\": \"new-custom-measure-description\",\n" +
" \"metric\": {\n" +
- " \"id\": \"" + metric.getId() + "\",\n" +
+ " \"id\": \"" + metric.getUuid() + "\",\n" +
" \"key\": \"" + metric.getKey() + "\",\n" +
" \"type\": \"" + metric.getValueType() + "\",\n" +
" \"name\": \"" + metric.getShortName() + "\",\n" +
@@ -155,7 +155,7 @@ public class UpdateActionTest {
.setParam(PARAM_DESCRIPTION, "new-custom-measure-description")
.execute();
- assertThat(db.getDbClient().customMeasureDao().selectByMetricId(db.getSession(), metric.getId()))
+ assertThat(db.getDbClient().customMeasureDao().selectByMetricUuid(db.getSession(), metric.getUuid()))
.extracting(CustomMeasureDto::getDescription, CustomMeasureDto::getTextValue, CustomMeasureDto::getValue)
.containsExactlyInAnyOrder(
tuple("new-custom-measure-description", customMeasure.getTextValue(), customMeasure.getValue()));
@@ -174,7 +174,7 @@ public class UpdateActionTest {
.setParam(PARAM_VALUE, "new-text-measure-value")
.execute();
- assertThat(db.getDbClient().customMeasureDao().selectByMetricId(db.getSession(), metric.getId()))
+ assertThat(db.getDbClient().customMeasureDao().selectByMetricUuid(db.getSession(), metric.getUuid()))
.extracting(CustomMeasureDto::getDescription, CustomMeasureDto::getTextValue, CustomMeasureDto::getValue)
.containsExactlyInAnyOrder(
tuple(customMeasure.getDescription(), "new-text-measure-value", customMeasure.getValue()));
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/live/LiveMeasureComputerImplTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/live/LiveMeasureComputerImplTest.java
index 29a13e09864..6aab3109298 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/live/LiveMeasureComputerImplTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/live/LiveMeasureComputerImplTest.java
@@ -421,7 +421,7 @@ public class LiveMeasureComputerImplTest {
LiveMeasureDto measure = db.getDbClient().liveMeasureDao().selectMeasure(db.getSession(), component.uuid(), intMetric.getKey()).get();
assertThat(measure.getComponentUuid()).isEqualTo(component.uuid());
assertThat(measure.getProjectUuid()).isEqualTo(component.projectUuid());
- assertThat(measure.getMetricId()).isEqualTo(intMetric.getId());
+ assertThat(measure.getMetricUuid()).isEqualTo(intMetric.getUuid());
assertThat(measure.getValue()).isEqualTo(expectedValue);
return measure;
}
@@ -430,7 +430,7 @@ public class LiveMeasureComputerImplTest {
LiveMeasureDto measure = db.getDbClient().liveMeasureDao().selectMeasure(db.getSession(), component.uuid(), ratingMetric.getKey()).get();
assertThat(measure.getComponentUuid()).isEqualTo(component.uuid());
assertThat(measure.getProjectUuid()).isEqualTo(component.projectUuid());
- assertThat(measure.getMetricId()).isEqualTo(ratingMetric.getId());
+ assertThat(measure.getMetricUuid()).isEqualTo(ratingMetric.getUuid());
assertThat(measure.getValue()).isEqualTo(expectedRating.getIndex());
assertThat(measure.getDataAsString()).isEqualTo(expectedRating.name());
return measure;
@@ -440,7 +440,7 @@ public class LiveMeasureComputerImplTest {
LiveMeasureDto measure = db.getDbClient().liveMeasureDao().selectMeasure(db.getSession(), component.uuid(), intMetric.getKey()).get();
assertThat(measure.getComponentUuid()).isEqualTo(component.uuid());
assertThat(measure.getProjectUuid()).isEqualTo(component.projectUuid());
- assertThat(measure.getMetricId()).isEqualTo(intMetric.getId());
+ assertThat(measure.getMetricUuid()).isEqualTo(intMetric.getUuid());
assertThat(measure.getValue()).isNull();
assertThat(measure.getVariation()).isEqualTo(expectedValue);
}
@@ -449,7 +449,7 @@ public class LiveMeasureComputerImplTest {
LiveMeasureDto measure = db.getDbClient().liveMeasureDao().selectMeasure(db.getSession(), component.uuid(), ratingMetric.getKey()).get();
assertThat(measure.getComponentUuid()).isEqualTo(component.uuid());
assertThat(measure.getProjectUuid()).isEqualTo(component.projectUuid());
- assertThat(measure.getMetricId()).isEqualTo(ratingMetric.getId());
+ assertThat(measure.getMetricUuid()).isEqualTo(ratingMetric.getUuid());
assertThat(measure.getVariation()).isEqualTo((double) expectedValue.getIndex());
}
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/live/LiveQualityGateComputerImplTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/live/LiveQualityGateComputerImplTest.java
index ef718d263d6..4e96db9ff50 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/live/LiveQualityGateComputerImplTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/live/LiveQualityGateComputerImplTest.java
@@ -153,9 +153,9 @@ public class LiveQualityGateComputerImplTest {
MetricDto statusMetric = newMetricDto().setKey(CoreMetrics.ALERT_STATUS_KEY);
MetricDto detailsMetric = newMetricDto().setKey(CoreMetrics.QUALITY_GATE_DETAILS_KEY);
QualityGate gate = new QualityGate("1", "foo", Collections.emptySet());
- LiveMeasureDto numericMeasure = new LiveMeasureDto().setMetricId(numericMetric.getId()).setValue(1.23).setVariation(4.56).setComponentUuid(project.uuid());
- LiveMeasureDto numericNewMeasure = new LiveMeasureDto().setMetricId(numericNewMetric.getId()).setValue(7.8).setVariation(8.9).setComponentUuid(project.uuid());
- LiveMeasureDto stringMeasure = new LiveMeasureDto().setMetricId(stringMetric.getId()).setData("bar").setComponentUuid(project.uuid());
+ LiveMeasureDto numericMeasure = new LiveMeasureDto().setMetricUuid(numericMetric.getUuid()).setValue(1.23).setVariation(4.56).setComponentUuid(project.uuid());
+ LiveMeasureDto numericNewMeasure = new LiveMeasureDto().setMetricUuid(numericNewMetric.getUuid()).setValue(7.8).setVariation(8.9).setComponentUuid(project.uuid());
+ LiveMeasureDto stringMeasure = new LiveMeasureDto().setMetricUuid(stringMetric.getUuid()).setData("bar").setComponentUuid(project.uuid());
MeasureMatrix matrix = new MeasureMatrix(singleton(project), asList(statusMetric, detailsMetric, numericMetric, numericNewMetric, stringMetric),
asList(numericMeasure, numericNewMeasure, stringMeasure));
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/live/MeasureMatrixTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/live/MeasureMatrixTest.java
index b8f4ce00500..f71f39a1600 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/live/MeasureMatrixTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/live/MeasureMatrixTest.java
@@ -43,8 +43,8 @@ public class MeasureMatrixTest {
private static final OrganizationDto ORGANIZATION = newOrganizationDto();
private static final ComponentDto PROJECT = ComponentTesting.newPublicProjectDto(ORGANIZATION);
private static final ComponentDto FILE = ComponentTesting.newFileDto(PROJECT);
- private static final MetricDto METRIC_1 = newMetricDto().setId(100);
- private static final MetricDto METRIC_2 = newMetricDto().setId(200);
+ private static final MetricDto METRIC_1 = newMetricDto().setUuid("100");
+ private static final MetricDto METRIC_2 = newMetricDto().setUuid("200");
@Rule
public ExpectedException expectedException = ExpectedException.none();
@@ -55,7 +55,7 @@ public class MeasureMatrixTest {
MeasureMatrix underTest = new MeasureMatrix(asList(PROJECT, FILE), metrics, new ArrayList<>());
- assertThat(underTest.getMetric(METRIC_2.getId())).isSameAs(METRIC_2);
+ assertThat(underTest.getMetricByUuid(METRIC_2.getUuid())).isSameAs(METRIC_2);
}
@Test
@@ -64,9 +64,9 @@ public class MeasureMatrixTest {
MeasureMatrix underTest = new MeasureMatrix(asList(PROJECT, FILE), metrics, new ArrayList<>());
expectedException.expect(NullPointerException.class);
- expectedException.expectMessage("Metric with id " + METRIC_2.getId() + " not found");
+ expectedException.expectMessage("Metric with uuid " + METRIC_2.getUuid() + " not found");
- underTest.getMetric(METRIC_2.getId());
+ underTest.getMetricByUuid(METRIC_2.getUuid());
}
@Test
@@ -204,6 +204,6 @@ public class MeasureMatrixTest {
}
private LiveMeasureDto newMeasure(MetricDto metric, ComponentDto component) {
- return new LiveMeasureDto().setMetricId(metric.getId()).setData("foo").setComponentUuid(component.uuid());
+ return new LiveMeasureDto().setMetricUuid(metric.getUuid()).setData("foo").setComponentUuid(component.uuid());
}
}
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/prMeasureFixTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/prMeasureFixTest.java
index e373bd082b8..818d82cc25f 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/prMeasureFixTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/prMeasureFixTest.java
@@ -50,10 +50,10 @@ public class prMeasureFixTest {
@Test
public void should_remove_metrics_not_initially_requested() {
Set<String> originalMetricList = new HashSet<>(Arrays.asList(NEW_BUGS_KEY, MINOR_VIOLATIONS_KEY, NEW_MINOR_VIOLATIONS_KEY));
- MetricDto dto1 = new MetricDto().setKey(BUGS_KEY).setId(1);
- MetricDto dto2 = new MetricDto().setKey(NEW_BUGS_KEY).setId(2);
- MetricDto dto3 = new MetricDto().setKey(MINOR_VIOLATIONS_KEY).setId(3);
- MetricDto dto4 = new MetricDto().setKey(NEW_MINOR_VIOLATIONS_KEY).setId(4);
+ MetricDto dto1 = new MetricDto().setKey(BUGS_KEY).setUuid("1");
+ MetricDto dto2 = new MetricDto().setKey(NEW_BUGS_KEY).setUuid("2");
+ MetricDto dto3 = new MetricDto().setKey(MINOR_VIOLATIONS_KEY).setUuid("3");
+ MetricDto dto4 = new MetricDto().setKey(NEW_MINOR_VIOLATIONS_KEY).setUuid("4");
List<MetricDto> metricList = new ArrayList<>(Arrays.asList(dto1, dto2, dto3, dto4));
@@ -65,17 +65,17 @@ public class prMeasureFixTest {
public void should_transform_measures() {
Set<String> requestedKeys = new HashSet<>(Arrays.asList(NEW_BUGS_KEY, MINOR_VIOLATIONS_KEY, NEW_MINOR_VIOLATIONS_KEY));
- MetricDto bugsMetric = new MetricDto().setKey(BUGS_KEY).setId(1);
- MetricDto newBugsMetric = new MetricDto().setKey(NEW_BUGS_KEY).setId(2);
- MetricDto violationsMetric = new MetricDto().setKey(MINOR_VIOLATIONS_KEY).setId(3);
- MetricDto newViolationsMetric = new MetricDto().setKey(NEW_MINOR_VIOLATIONS_KEY).setId(4);
+ MetricDto bugsMetric = new MetricDto().setKey(BUGS_KEY).setUuid("1");
+ MetricDto newBugsMetric = new MetricDto().setKey(NEW_BUGS_KEY).setUuid("2");
+ MetricDto violationsMetric = new MetricDto().setKey(MINOR_VIOLATIONS_KEY).setUuid("3");
+ MetricDto newViolationsMetric = new MetricDto().setKey(NEW_MINOR_VIOLATIONS_KEY).setUuid("4");
List<MetricDto> metricList = Arrays.asList(bugsMetric, newBugsMetric, violationsMetric, newViolationsMetric);
- LiveMeasureDto bugs = createLiveMeasure(bugsMetric.getId(), 10.0, null);
- LiveMeasureDto newBugs = createLiveMeasure(newBugsMetric.getId(), null, 5.0);
- LiveMeasureDto violations = createLiveMeasure(violationsMetric.getId(), 20.0, null);
- LiveMeasureDto newViolations = createLiveMeasure(newViolationsMetric.getId(), null, 3.0);
+ LiveMeasureDto bugs = createLiveMeasure(bugsMetric.getUuid(), 10.0, null);
+ LiveMeasureDto newBugs = createLiveMeasure(newBugsMetric.getUuid(), null, 5.0);
+ LiveMeasureDto violations = createLiveMeasure(violationsMetric.getUuid(), 20.0, null);
+ LiveMeasureDto newViolations = createLiveMeasure(newViolationsMetric.getUuid(), null, 3.0);
Map<MetricDto, LiveMeasureDto> measureByMetric = new HashMap<>();
measureByMetric.put(bugsMetric, bugs);
@@ -90,7 +90,7 @@ public class prMeasureFixTest {
tuple(NEW_MINOR_VIOLATIONS_KEY, null, 20.0));
}
- private static LiveMeasureDto createLiveMeasure(int metricId, @Nullable Double value, @Nullable Double variation) {
- return new LiveMeasureDto().setMetricId(metricId).setVariation(variation).setValue(value);
+ private static LiveMeasureDto createLiveMeasure(String metricUuid, @Nullable Double value, @Nullable Double variation) {
+ return new LiveMeasureDto().setMetricUuid(metricUuid).setVariation(variation).setValue(value);
}
}
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/metric/ws/CreateActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/metric/ws/CreateActionTest.java
index 7afaf4c82b5..600efa98b43 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/metric/ws/CreateActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/metric/ws/CreateActionTest.java
@@ -25,6 +25,7 @@ import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.sonar.api.measures.Metric.ValueType;
import org.sonar.api.utils.System2;
+import org.sonar.core.util.SequenceUuidFactory;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
@@ -62,7 +63,7 @@ public class CreateActionTest {
private DbClient dbClient = db.getDbClient();
private final DbSession dbSession = db.getSession();
- private CreateAction underTest = new CreateAction(dbClient, userSessionRule);
+ private CreateAction underTest = new CreateAction(dbClient, userSessionRule, new SequenceUuidFactory());
private WsActionTester tester = new WsActionTester(underTest);
@Before
@@ -109,7 +110,7 @@ public class CreateActionTest {
}
@Test
- public void return_metric_with_id() {
+ public void return_metric_with_uuid() {
TestResponse result = tester.newRequest()
.setParam(PARAM_KEY, DEFAULT_KEY)
.setParam(PARAM_NAME, DEFAULT_NAME)
@@ -141,9 +142,9 @@ public class CreateActionTest {
.execute();
result.assertJson(getClass(), "metric.json");
- result.getInput().matches("\"id\"\\s*:\\s*\"" + metricInDb.getId() + "\"");
+ result.getInput().matches("\"id\"\\s*:\\s*\"" + metricInDb.getUuid() + "\"");
MetricDto metricAfterWs = dbClient.metricDao().selectByKey(dbSession, DEFAULT_KEY);
- assertThat(metricAfterWs.getId()).isEqualTo(metricInDb.getId());
+ assertThat(metricAfterWs.getUuid()).isEqualTo(metricInDb.getUuid());
assertThat(metricAfterWs.getDomain()).isEqualTo(DEFAULT_DOMAIN);
assertThat(metricAfterWs.getDescription()).isEqualTo(DEFAULT_DESCRIPTION);
assertThat(metricAfterWs.getValueType()).isEqualTo(DEFAULT_TYPE);
@@ -191,7 +192,7 @@ public class CreateActionTest {
.setUserManaged(true)
.setEnabled(false);
dbClient.metricDao().insert(dbSession, metric);
- dbClient.customMeasureDao().insert(dbSession, CustomMeasureTesting.newCustomMeasureDto().setMetricId(metric.getId()));
+ dbClient.customMeasureDao().insert(dbSession, CustomMeasureTesting.newCustomMeasureDto().setMetricUuid(metric.getUuid()));
dbSession.commit();
tester.newRequest()
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/metric/ws/DeleteActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/metric/ws/DeleteActionTest.java
index a1f3a40fc10..5a0aaf6b582 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/metric/ws/DeleteActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/metric/ws/DeleteActionTest.java
@@ -71,7 +71,7 @@ public class DeleteActionTest {
loggedAsSystemAdministrator();
MetricDto metric = insertCustomMetric("custom-key");
- TestResponse response = newRequest().setParam("ids", String.valueOf(metric.getId())).execute();
+ TestResponse response = newRequest().setParam("ids", String.valueOf(metric.getUuid())).execute();
assertThat(db.getDbClient().metricDao().selectEnabled(db.getSession())).isEmpty();
assertThat(response.getStatus()).isEqualTo(204);
@@ -93,8 +93,8 @@ public class DeleteActionTest {
public void delete_associated_measures() {
loggedAsSystemAdministrator();
MetricDto metric = insertCustomMetric("custom-key");
- CustomMeasureDto customMeasure = newCustomMeasureDto().setMetricId(metric.getId());
- CustomMeasureDto undeletedCustomMeasure = newCustomMeasureDto().setMetricId(metric.getId() + 1);
+ CustomMeasureDto customMeasure = newCustomMeasureDto().setMetricUuid(metric.getUuid());
+ CustomMeasureDto undeletedCustomMeasure = newCustomMeasureDto().setMetricUuid("unknown");
dbClient.customMeasureDao().insert(db.getSession(), customMeasure);
dbClient.customMeasureDao().insert(db.getSession(), undeletedCustomMeasure);
db.getSession().commit();
@@ -120,7 +120,7 @@ public class DeleteActionTest {
assertThat(dbClient.gateConditionDao().selectForQualityGate(db.getSession(), qualityGate1.getId())).isEmpty();
assertThat(dbClient.gateConditionDao().selectForQualityGate(db.getSession(), qualityGate2.getId()))
- .extracting(QualityGateConditionDto::getMetricId).containsOnly(nonCustomMetric.getId().longValue());
+ .extracting(QualityGateConditionDto::getMetricUuid).containsOnly(nonCustomMetric.getUuid());
}
@Test
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/metric/ws/MetricsWsTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/metric/ws/MetricsWsTest.java
index ffea37eb4aa..a0f396e84a5 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/metric/ws/MetricsWsTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/metric/ws/MetricsWsTest.java
@@ -21,6 +21,8 @@ package org.sonar.server.metric.ws;
import org.junit.Test;
import org.sonar.api.server.ws.WebService;
+import org.sonar.core.util.SequenceUuidFactory;
+import org.sonar.core.util.UuidFactory;
import org.sonar.db.DbClient;
import org.sonar.server.user.UserSession;
@@ -31,9 +33,10 @@ public class MetricsWsTest {
private DbClient dbClient = mock(DbClient.class);
private UserSession userSession = mock(UserSession.class);
+ private UuidFactory uuidFactory = new SequenceUuidFactory();
private MetricsWs underTest = new MetricsWs(
new SearchAction(dbClient),
- new CreateAction(dbClient, userSession),
+ new CreateAction(dbClient, userSession, uuidFactory),
new UpdateAction(dbClient, userSession),
new DeleteAction(dbClient, userSession),
new TypesAction(),
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/metric/ws/UpdateActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/metric/ws/UpdateActionTest.java
index 82697a7ed03..0b9ce49f186 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/metric/ws/UpdateActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/metric/ws/UpdateActionTest.java
@@ -47,6 +47,7 @@ import static org.sonar.server.metric.ws.UpdateAction.PARAM_TYPE;
public class UpdateActionTest {
+ private static final String DEFAULT_UUID = "custom-metric-uuid";
private static final String DEFAULT_KEY = "custom-metric-key";
private static final String DEFAULT_NAME = "custom-metric-name";
private static final String DEFAULT_DOMAIN = "custom-metric-domain";
@@ -72,10 +73,10 @@ public class UpdateActionTest {
@Test
public void update_all_fields() {
- int id = insertMetric(newDefaultMetric());
+ String uuid = insertMetric(newDefaultMetric());
tester.newRequest()
- .setParam(PARAM_ID, String.valueOf(id))
+ .setParam(PARAM_ID, uuid)
.setParam(PARAM_KEY, "another-key")
.setParam(PARAM_NAME, "another-name")
.setParam(PARAM_TYPE, ValueType.BOOL.name())
@@ -84,7 +85,7 @@ public class UpdateActionTest {
.execute();
dbSession.commit();
- MetricDto result = dbClient.metricDao().selectById(dbSession, id);
+ MetricDto result = dbClient.metricDao().selectByUuid(dbSession, uuid);
assertThat(result.getKey()).isEqualTo("another-key");
assertThat(result.getShortName()).isEqualTo("another-name");
assertThat(result.getValueType()).isEqualTo(ValueType.BOOL.name());
@@ -94,17 +95,17 @@ public class UpdateActionTest {
@Test
public void update_one_field() {
- int id = insertMetric(newDefaultMetric());
- dbClient.customMeasureDao().insert(dbSession, newCustomMeasureDto().setMetricId(id));
+ String uuid = insertMetric(newDefaultMetric());
+ dbClient.customMeasureDao().insert(dbSession, newCustomMeasureDto().setMetricUuid(uuid));
dbSession.commit();
tester.newRequest()
- .setParam(PARAM_ID, String.valueOf(id))
+ .setParam(PARAM_ID, uuid)
.setParam(PARAM_DESCRIPTION, "another-description")
.execute();
dbSession.commit();
- MetricDto result = dbClient.metricDao().selectById(dbSession, id);
+ MetricDto result = dbClient.metricDao().selectByUuid(dbSession, uuid);
assertThat(result.getKey()).isEqualTo(DEFAULT_KEY);
assertThat(result.getShortName()).isEqualTo(DEFAULT_NAME);
assertThat(result.getValueType()).isEqualTo(DEFAULT_TYPE);
@@ -114,16 +115,16 @@ public class UpdateActionTest {
@Test
public void update_return_the_full_object_with_id() {
- int id = insertMetric(newDefaultMetric().setDescription("another-description"));
+ String uuid = insertMetric(newDefaultMetric().setDescription("another-description"));
TestResponse requestResult = tester.newRequest()
- .setParam(PARAM_ID, String.valueOf(id))
+ .setParam(PARAM_ID, uuid)
.setParam(PARAM_DESCRIPTION, DEFAULT_DESCRIPTION)
.execute();
dbSession.commit();
requestResult.assertJson(getClass(), "metric.json");
- assertThat(requestResult.getInput()).matches(".*\"id\"\\s*:\\s*\"" + id + "\".*");
+ assertThat(requestResult.getInput()).matches(".*\"id\"\\s*:\\s*\"" + uuid + "\".*");
}
@Test
@@ -131,10 +132,10 @@ public class UpdateActionTest {
expectedException.expect(ServerException.class);
expectedException.expectMessage("The key 'metric-key' is already used by an existing metric.");
insertMetric(newDefaultMetric().setKey("metric-key"));
- int id = insertMetric(newDefaultMetric().setKey("another-key"));
+ String uuid = insertMetric(newDefaultMetric().setUuid("another-uuid").setKey("another-key"));
tester.newRequest()
- .setParam(PARAM_ID, String.valueOf(id))
+ .setParam(PARAM_ID, uuid)
.setParam(PARAM_KEY, "metric-key")
.execute();
}
@@ -149,28 +150,28 @@ public class UpdateActionTest {
@Test
public void fail_when_metric_is_deactivated() {
expectedException.expect(ServerException.class);
- int id = insertMetric(newDefaultMetric().setEnabled(false));
+ String uuid = insertMetric(newDefaultMetric().setEnabled(false));
- tester.newRequest().setParam(PARAM_ID, String.valueOf(id)).execute();
+ tester.newRequest().setParam(PARAM_ID, uuid).execute();
}
@Test
public void fail_when_metric_is_not_custom() {
expectedException.expect(ServerException.class);
- int id = insertMetric(newDefaultMetric().setUserManaged(false));
+ String uuid = insertMetric(newDefaultMetric().setUserManaged(false));
- tester.newRequest().setParam(PARAM_ID, String.valueOf(id)).execute();
+ tester.newRequest().setParam(PARAM_ID, uuid).execute();
}
@Test
public void fail_when_custom_measures_and_type_changed() {
expectedException.expect(ServerException.class);
- int id = insertMetric(newDefaultMetric());
- dbClient.customMeasureDao().insert(dbSession, newCustomMeasureDto().setMetricId(id));
+ String uuid = insertMetric(newDefaultMetric());
+ dbClient.customMeasureDao().insert(dbSession, newCustomMeasureDto().setMetricUuid(uuid));
dbSession.commit();
tester.newRequest()
- .setParam(PARAM_ID, String.valueOf(id))
+ .setParam(PARAM_ID, uuid)
.setParam(PARAM_TYPE, ValueType.BOOL.name())
.execute();
}
@@ -204,21 +205,22 @@ public class UpdateActionTest {
@Test
public void fail_when_metric_key_is_not_well_formatted() {
- int id = insertMetric(newDefaultMetric());
- dbClient.customMeasureDao().insert(dbSession, newCustomMeasureDto().setMetricId(id));
+ String uuid = insertMetric(newDefaultMetric());
+ dbClient.customMeasureDao().insert(dbSession, newCustomMeasureDto().setMetricUuid(uuid));
dbSession.commit();
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("Malformed metric key 'not well formatted key'. Allowed characters are alphanumeric, '-', '_', with at least one non-digit.");
tester.newRequest()
- .setParam(PARAM_ID, String.valueOf(id))
+ .setParam(PARAM_ID, uuid)
.setParam(PARAM_KEY, "not well formatted key")
.execute();
}
private MetricDto newDefaultMetric() {
return new MetricDto()
+ .setUuid(DEFAULT_UUID)
.setKey(DEFAULT_KEY)
.setShortName(DEFAULT_NAME)
.setValueType(DEFAULT_TYPE)
@@ -228,10 +230,10 @@ public class UpdateActionTest {
.setEnabled(true);
}
- private int insertMetric(MetricDto metricDto) {
+ private String insertMetric(MetricDto metricDto) {
dbClient.metricDao().insert(dbSession, metricDto);
dbSession.commit();
- return metricDto.getId();
+ return metricDto.getUuid();
}
}
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/QualityGateConditionsUpdaterTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/QualityGateConditionsUpdaterTest.java
index c7470ddaebf..6aed8d789a1 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/QualityGateConditionsUpdaterTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/QualityGateConditionsUpdaterTest.java
@@ -394,12 +394,12 @@ public class QualityGateConditionsUpdaterTest {
private void verifyCondition(QualityGateConditionDto dto, QualityGateDto qualityGate, MetricDto metric, String operator, String error) {
QualityGateConditionDto reloaded = db.getDbClient().gateConditionDao().selectByUuid(dto.getUuid(), db.getSession());
assertThat(reloaded.getQualityGateId()).isEqualTo(qualityGate.getId());
- assertThat(reloaded.getMetricId()).isEqualTo(metric.getId().longValue());
+ assertThat(reloaded.getMetricUuid()).isEqualTo(metric.getUuid());
assertThat(reloaded.getOperator()).isEqualTo(operator);
assertThat(reloaded.getErrorThreshold()).isEqualTo(error);
assertThat(dto.getQualityGateId()).isEqualTo(qualityGate.getId());
- assertThat(dto.getMetricId()).isEqualTo(metric.getId().longValue());
+ assertThat(dto.getMetricUuid()).isEqualTo(metric.getUuid());
assertThat(dto.getOperator()).isEqualTo(operator);
assertThat(dto.getErrorThreshold()).isEqualTo(error);
}
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/RegisterQualityGatesTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/RegisterQualityGatesTest.java
index 3b1f58fecef..730a3f00104 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/RegisterQualityGatesTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/RegisterQualityGatesTest.java
@@ -215,7 +215,7 @@ public class RegisterQualityGatesTest {
insertMetrics();
QualityGateConditionDto conditionDto = new QualityGateConditionDto()
.setUuid(Uuids.createFast())
- .setMetricId(-1) // This Id does not exist
+ .setMetricUuid("unknown") // This uuid does not exist
.setOperator(OPERATOR_GREATER_THAN)
.setErrorThreshold("1");
gateConditionDao.insert(conditionDto, dbSession);
@@ -254,15 +254,15 @@ public class RegisterQualityGatesTest {
assertThat(qualityGateDto.getCreatedAt()).isNotNull();
assertThat(qualityGateDto.isBuiltIn()).isTrue();
assertThat(gateConditionDao.selectForQualityGate(dbSession, qualityGateDto.getId()))
- .extracting(QualityGateConditionDto::getMetricId, QualityGateConditionDto::getOperator,
+ .extracting(QualityGateConditionDto::getMetricUuid, QualityGateConditionDto::getOperator,
QualityGateConditionDto::getErrorThreshold)
.containsExactlyInAnyOrder(
- tuple(newReliability.getId().longValue(), OPERATOR_GREATER_THAN, "1"),
- tuple(newSecurity.getId().longValue(), OPERATOR_GREATER_THAN, "1"),
- tuple(newMaintainability.getId().longValue(), OPERATOR_GREATER_THAN, "1"),
- tuple(newCoverage.getId().longValue(), OPERATOR_LESS_THAN, "80"),
- tuple(newDuplication.getId().longValue(), OPERATOR_GREATER_THAN, "3"),
- tuple(newSecurityHotspots.getId().longValue(), OPERATOR_LESS_THAN, "100"));
+ tuple(newReliability.getUuid(), OPERATOR_GREATER_THAN, "1"),
+ tuple(newSecurity.getUuid(), OPERATOR_GREATER_THAN, "1"),
+ tuple(newMaintainability.getUuid(), OPERATOR_GREATER_THAN, "1"),
+ tuple(newCoverage.getUuid(), OPERATOR_LESS_THAN, "80"),
+ tuple(newDuplication.getUuid(), OPERATOR_GREATER_THAN, "3"),
+ tuple(newSecurityHotspots.getUuid(), OPERATOR_LESS_THAN, "100"));
}
private List<QualityGateConditionDto> createBuiltInConditions(QualityGateDto qg) {
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/CopyActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/CopyActionTest.java
index d13937f0baa..f5aef0be314 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/CopyActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/CopyActionTest.java
@@ -118,8 +118,8 @@ public class CopyActionTest {
assertThat(actual.getUuid()).isNotEqualTo(qualityGate.getUuid());
assertThat(db.getDbClient().gateConditionDao().selectForQualityGate(dbSession, qualityGate.getId()))
- .extracting(c-> (int) c.getMetricId(), QualityGateConditionDto::getErrorThreshold)
- .containsExactlyInAnyOrder(tuple(metric.getId(), condition.getErrorThreshold()));
+ .extracting(QualityGateConditionDto::getMetricUuid, QualityGateConditionDto::getErrorThreshold)
+ .containsExactlyInAnyOrder(tuple(metric.getUuid(), condition.getErrorThreshold()));
}
@Test
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/CreateConditionActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/CreateConditionActionTest.java
index 31b4829efc0..57300d18011 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/CreateConditionActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/CreateConditionActionTest.java
@@ -257,9 +257,9 @@ public class CreateConditionActionTest {
private void assertCondition(QualityGateDto qualityGate, MetricDto metric, String operator, String error) {
assertThat(dbClient.gateConditionDao().selectForQualityGate(dbSession, qualityGate.getId()))
- .extracting(QualityGateConditionDto::getQualityGateId, QualityGateConditionDto::getMetricId, QualityGateConditionDto::getOperator,
+ .extracting(QualityGateConditionDto::getQualityGateId, QualityGateConditionDto::getMetricUuid, QualityGateConditionDto::getOperator,
QualityGateConditionDto::getErrorThreshold)
- .containsExactlyInAnyOrder(tuple(qualityGate.getId(), metric.getId().longValue(), operator, error));
+ .containsExactlyInAnyOrder(tuple(qualityGate.getId(), metric.getUuid(), operator, error));
}
private void logInAsQualityGateAdmin(OrganizationDto organization) {
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/DeleteConditionActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/DeleteConditionActionTest.java
index bdfdf5c02e7..15cd608a4f7 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/DeleteConditionActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/DeleteConditionActionTest.java
@@ -175,7 +175,7 @@ public class DeleteConditionActionTest {
public void fail_when_condition_match_unknown_quality_gate() {
OrganizationDto organization = db.organizations().insert();
userSession.addPermission(ADMINISTER_QUALITY_PROFILES, organization);
- QualityGateConditionDto condition = new QualityGateConditionDto().setUuid("uuid").setQualityGateId(123L);
+ QualityGateConditionDto condition = new QualityGateConditionDto().setUuid("uuid").setMetricUuid("metric").setQualityGateId(123L);
db.getDbClient().gateConditionDao().insert(condition, db.getSession());
db.commit();
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/ShowActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/ShowActionTest.java
index 00cdc03166e..afe8370fce4 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/ShowActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/ShowActionTest.java
@@ -295,7 +295,7 @@ public class ShowActionTest {
db.commit();
expectedException.expect(IllegalStateException.class);
- expectedException.expectMessage(format("Could not find metric with id %s", metric.getId()));
+ expectedException.expectMessage(format("Could not find metric with id %s", metric.getUuid()));
ws.newRequest()
.setParam("name", qualityGate.getName())
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/UpdateConditionActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/UpdateConditionActionTest.java
index 5dfe619802c..e6d773ad89c 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/UpdateConditionActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/UpdateConditionActionTest.java
@@ -182,7 +182,9 @@ public class UpdateConditionActionTest {
OrganizationDto organization = db.organizations().insert();
userSession.addPermission(ADMINISTER_QUALITY_GATES, organization);
MetricDto metric = insertMetric();
- QualityGateConditionDto condition = new QualityGateConditionDto().setUuid("uuid").setQualityGateId(123L);
+ QualityGateConditionDto condition = new QualityGateConditionDto().setUuid("uuid")
+ .setMetricUuid("metric")
+ .setQualityGateId(123L);
db.getDbClient().gateConditionDao().insert(condition, dbSession);
db.commit();
@@ -288,9 +290,9 @@ public class UpdateConditionActionTest {
private void assertCondition(QualityGateDto qualityGate, MetricDto metric, String operator, String error) {
assertThat(dbClient.gateConditionDao().selectForQualityGate(dbSession, qualityGate.getId()))
- .extracting(QualityGateConditionDto::getQualityGateId, QualityGateConditionDto::getMetricId, QualityGateConditionDto::getOperator,
+ .extracting(QualityGateConditionDto::getQualityGateId, QualityGateConditionDto::getMetricUuid, QualityGateConditionDto::getOperator,
QualityGateConditionDto::getErrorThreshold)
- .containsExactlyInAnyOrder(tuple(qualityGate.getId(), metric.getId().longValue(), operator, error));
+ .containsExactlyInAnyOrder(tuple(qualityGate.getId(), metric.getUuid(), operator, error));
}
private MetricDto insertMetric() {
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/measures/Metric.java b/sonar-plugin-api/src/main/java/org/sonar/api/measures/Metric.java
index 74802ebd14e..2c06a92a67d 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/measures/Metric.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/measures/Metric.java
@@ -129,7 +129,7 @@ public class Metric<G extends Serializable> implements Serializable, org.sonar.a
}
}
- private Integer id;
+ private String uuid;
private String key;
private String description;
private ValueType type;
@@ -239,15 +239,15 @@ public class Metric<G extends Serializable> implements Serializable, org.sonar.a
/**
* For internal use only
*/
- public Integer getId() {
- return id;
+ public String getUuid() {
+ return uuid;
}
/**
* For internal use only
*/
- public Metric<G> setId(@Nullable Integer id) {
- this.id = id;
+ public Metric<G> setUuid(@Nullable String uuid) {
+ this.uuid = uuid;
return this;
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/measures/MetricFinder.java b/sonar-plugin-api/src/main/java/org/sonar/api/measures/MetricFinder.java
index 978bd27f200..317eb35f578 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/measures/MetricFinder.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/measures/MetricFinder.java
@@ -37,7 +37,7 @@ import org.sonar.api.server.ServerSide;
public interface MetricFinder {
@CheckForNull
- Metric findById(int id);
+ Metric findByUuid(String uuid);
@CheckForNull
Metric findByKey(String key);
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/measures/MetricTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/measures/MetricTest.java
index 2332571c60e..b4168483535 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/measures/MetricTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/measures/MetricTest.java
@@ -51,7 +51,7 @@ public class MetricTest {
assertThat(metric.getWorstValue()).isNull();
assertThat(metric.getDirection()).isEqualTo(Metric.DIRECTION_NONE);
assertThat(metric.getEnabled()).isTrue();
- assertThat(metric.getId()).isNull();
+ assertThat(metric.getUuid()).isNull();
assertThat(metric.getUserManaged()).isFalse();
assertThat(metric.isHidden()).isFalse();
assertThat(metric.isOptimizedBestValue()).isFalse();
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/DefaultMetricsRepositoryLoader.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/DefaultMetricsRepositoryLoader.java
index 02bbdf02e92..f5abad5bb9a 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/DefaultMetricsRepositoryLoader.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/DefaultMetricsRepositoryLoader.java
@@ -63,7 +63,7 @@ public class DefaultMetricsRepositoryLoader implements MetricsRepositoryLoader {
.setQualitative(metric.isQualitative())
.setUserManaged(metric.isCustom())
.setDescription(metric.getDescription())
- .setId(metric.getId()));
+ .setUuid(metric.getUuid()));
}
}
page++;
@@ -71,7 +71,7 @@ public class DefaultMetricsRepositoryLoader implements MetricsRepositoryLoader {
}
private static class WsMetric {
- private int id;
+ private String uuid;
private String key;
private String type;
private String name;
@@ -80,8 +80,8 @@ public class DefaultMetricsRepositoryLoader implements MetricsRepositoryLoader {
private boolean qualitative;
private boolean custom;
- public int getId() {
- return id;
+ public String getUuid() {
+ return uuid;
}
public String getKey() {
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/ScannerMediumTester.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/ScannerMediumTester.java
index 6e4aad7c736..a3a1024621d 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/ScannerMediumTester.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/ScannerMediumTester.java
@@ -354,7 +354,7 @@ public class ScannerMediumTester extends ExternalResource {
}
public FakeMetricsRepositoryLoader add(Metric<?> metric) {
- metric.setId(metricId++);
+ metric.setUuid("metric" + metricId++);
metrics.add(metric);
metricId++;
return this;