diff options
20 files changed, 204 insertions, 71 deletions
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistAnalysisPropertiesStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistAnalysisPropertiesStep.java index 57b39a71fd3..66a29b81ddb 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistAnalysisPropertiesStep.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistAnalysisPropertiesStep.java @@ -66,7 +66,7 @@ public class PersistAnalysisPropertiesStep implements ComputationStep { .setUuid(uuidFactory.create()) .setKey(propertyKey) .setValue(contextProperty.getValue()) - .setSnapshotUuid(analysisMetadataHolder.getUuid())); + .setAnalysisUuid(analysisMetadataHolder.getUuid())); } }); } diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistAnalysisPropertiesStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistAnalysisPropertiesStepTest.java index 2c54b1aaa68..89db208ff78 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistAnalysisPropertiesStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistAnalysisPropertiesStepTest.java @@ -81,10 +81,10 @@ public class PersistAnalysisPropertiesStepTest { assertThat(dbTester.countRowsOfTable("analysis_properties")).isEqualTo(8); List<AnalysisPropertyDto> propertyDtos = dbTester.getDbClient() - .analysisPropertiesDao().selectBySnapshotUuid(dbTester.getSession(), SNAPSHOT_UUID); + .analysisPropertiesDao().selectByAnalysisUuid(dbTester.getSession(), SNAPSHOT_UUID); assertThat(propertyDtos) - .extracting(AnalysisPropertyDto::getSnapshotUuid, AnalysisPropertyDto::getKey, AnalysisPropertyDto::getValue) + .extracting(AnalysisPropertyDto::getAnalysisUuid, AnalysisPropertyDto::getKey, AnalysisPropertyDto::getValue) .containsExactlyInAnyOrder( tuple(SNAPSHOT_UUID, "sonar.analysis.branch", SMALL_VALUE2), tuple(SNAPSHOT_UUID, "sonar.analysis.empty_string", ""), diff --git a/server/sonar-db-core/src/main/resources/org/sonar/db/version/schema-h2.ddl b/server/sonar-db-core/src/main/resources/org/sonar/db/version/schema-h2.ddl index af7c91f6c75..157cdd5e334 100644 --- a/server/sonar-db-core/src/main/resources/org/sonar/db/version/schema-h2.ddl +++ b/server/sonar-db-core/src/main/resources/org/sonar/db/version/schema-h2.ddl @@ -858,7 +858,7 @@ CREATE UNIQUE INDEX "PROJECT_BRANCHES_KEE_KEY_TYPE" ON "PROJECT_BRANCHES" ("PROJ CREATE TABLE "ANALYSIS_PROPERTIES" ( "UUID" VARCHAR(40) NOT NULL, - "SNAPSHOT_UUID" VARCHAR(40) NOT NULL, + "ANALYSIS_UUID" VARCHAR(40) NOT NULL, "KEE" VARCHAR(512) NOT NULL, "TEXT_VALUE" VARCHAR(4000), "CLOB_VALUE" CLOB, @@ -867,7 +867,7 @@ CREATE TABLE "ANALYSIS_PROPERTIES" ( CONSTRAINT "PK_ANALYSIS_PROPERTIES" PRIMARY KEY ("UUID") ); -CREATE INDEX "SNAPSHOT_UUID" ON "ANALYSIS_PROPERTIES" ("SNAPSHOT_UUID"); +CREATE INDEX "ANALYSIS_PROPERTIES_ANALYSIS" ON "ANALYSIS_PROPERTIES" ("ANALYSIS_UUID"); CREATE TABLE "WEBHOOKS" ( diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/AnalysisPropertiesDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/AnalysisPropertiesDao.java index 4de57910489..d29a32bf5b1 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/AnalysisPropertiesDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/component/AnalysisPropertiesDao.java @@ -36,9 +36,9 @@ public class AnalysisPropertiesDao implements Dao { this.system2 = system2; } - public List<AnalysisPropertyDto> selectBySnapshotUuid(DbSession session, String snapshotUuid) { - requireNonNull(snapshotUuid); - return getMapper(session).selectBySnapshotUuid(snapshotUuid); + public List<AnalysisPropertyDto> selectByAnalysisUuid(DbSession session, String analysisUuid) { + requireNonNull(analysisUuid); + return getMapper(session).selectByAnalysisUuid(analysisUuid); } public void insert(DbSession session, List<AnalysisPropertyDto> analysisPropertyDto) { @@ -48,7 +48,7 @@ public class AnalysisPropertiesDao implements Dao { public void insert(DbSession session, AnalysisPropertyDto analysisPropertyDto) { requireNonNull(analysisPropertyDto.getUuid(), "uuid cannot be null"); requireNonNull(analysisPropertyDto.getKey(), "key cannot be null"); - requireNonNull(analysisPropertyDto.getSnapshotUuid(), "snapshot uuid cannot be null"); + requireNonNull(analysisPropertyDto.getAnalysisUuid(), "analysis uuid cannot be null"); requireNonNull(analysisPropertyDto.getValue(), "value cannot be null"); String value = analysisPropertyDto.getValue(); diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/AnalysisPropertiesMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/AnalysisPropertiesMapper.java index 775eda9faba..d3ed929aff6 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/AnalysisPropertiesMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/component/AnalysisPropertiesMapper.java @@ -24,7 +24,7 @@ import org.apache.ibatis.annotations.Param; public interface AnalysisPropertiesMapper { - List<AnalysisPropertyDto> selectBySnapshotUuid(@Param("snapshotUuid") String snapshotUuid); + List<AnalysisPropertyDto> selectByAnalysisUuid(@Param("analysisUuid") String analysisUuid); void insertAsEmpty(@Param("analysisPropertyDto") AnalysisPropertyDto analysisPropertyDto, @Param("createdAt") long createdAt); diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/AnalysisPropertyDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/AnalysisPropertyDto.java index 3010728bed8..5dad7ff73d3 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/AnalysisPropertyDto.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/component/AnalysisPropertyDto.java @@ -26,7 +26,7 @@ import static java.util.Objects.requireNonNull; public class AnalysisPropertyDto { private String uuid; - private String snapshotUuid; + private String analysisUuid; private String key; private String value; private Long createdAt; @@ -42,13 +42,13 @@ public class AnalysisPropertyDto { return this; } - public String getSnapshotUuid() { - return snapshotUuid; + public String getAnalysisUuid() { + return analysisUuid; } - public AnalysisPropertyDto setSnapshotUuid(String snapshotUuid) { - requireNonNull(snapshotUuid, "snapshotUuid cannot be null"); - this.snapshotUuid = snapshotUuid; + public AnalysisPropertyDto setAnalysisUuid(String analysisUuid) { + requireNonNull(analysisUuid, "analysisUuid cannot be null"); + this.analysisUuid = analysisUuid; return this; } @@ -84,7 +84,7 @@ public class AnalysisPropertyDto { @Override public String toString() { return "BranchDto{" + "uuid='" + uuid + '\'' + - ", snapshotUuid='" + snapshotUuid + '\'' + + ", analysisUuid='" + analysisUuid + '\'' + ", key='" + key + '\'' + ", value='" + value + "'" + ", createdAt=" + createdAt + @@ -101,7 +101,7 @@ public class AnalysisPropertyDto { } AnalysisPropertyDto that = (AnalysisPropertyDto) o; return Objects.equals(uuid, that.uuid) && - Objects.equals(snapshotUuid, that.snapshotUuid) && + Objects.equals(analysisUuid, that.analysisUuid) && Objects.equals(key, that.key) && Objects.equals(value, that.value) && Objects.equals(createdAt, that.createdAt); @@ -109,6 +109,6 @@ public class AnalysisPropertyDto { @Override public int hashCode() { - return Objects.hash(uuid, snapshotUuid, key, value, createdAt); + return Objects.hash(uuid, analysisUuid, key, value, createdAt); } } diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/component/AnalysisPropertiesMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/component/AnalysisPropertiesMapper.xml index 2dcfb5bc662..865f072c2b1 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/component/AnalysisPropertiesMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/component/AnalysisPropertiesMapper.xml @@ -4,7 +4,7 @@ <sql id="columns"> uuid as "uuid", - snapshot_uuid as "snapshotUuid", + analysis_uuid as "analysisUuid", kee as "key", text_value as "textValue", clob_value as "clobValue", @@ -12,25 +12,25 @@ created_at as "createdAt" </sql> - <select id="selectBySnapshotUuid" parameterType="string" resultType="ScrapAnalysisProperty"> + <select id="selectByAnalysisUuid" parameterType="string" resultType="ScrapAnalysisProperty"> SELECT <include refid="columns"/> FROM analysis_properties WHERE - snapshot_uuid = #{snapshotUuid} + analysis_uuid = #{analysisUuid} </select> <insert id="insertAsEmpty" parameterType="map" useGeneratedKeys="false"> INSERT INTO analysis_properties ( uuid, - snapshot_uuid, + analysis_uuid, kee, is_empty, created_at ) VALUES ( #{analysisPropertyDto.uuid, jdbcType=VARCHAR}, - #{analysisPropertyDto.snapshotUuid, jdbcType=VARCHAR}, + #{analysisPropertyDto.analysisUuid, jdbcType=VARCHAR}, #{analysisPropertyDto.key, jdbcType=VARCHAR}, ${_true}, #{createdAt} @@ -40,14 +40,14 @@ <insert id="insertAsText" parameterType="map" useGeneratedKeys="false"> INSERT INTO analysis_properties ( uuid, - snapshot_uuid, + analysis_uuid, kee, text_value, is_empty, created_at ) VALUES ( #{analysisPropertyDto.uuid, jdbcType=VARCHAR}, - #{analysisPropertyDto.snapshotUuid, jdbcType=VARCHAR}, + #{analysisPropertyDto.analysisUuid, jdbcType=VARCHAR}, #{analysisPropertyDto.key, jdbcType=VARCHAR}, #{analysisPropertyDto.value, jdbcType=VARCHAR}, ${_false}, @@ -58,14 +58,14 @@ <insert id="insertAsClob" parameterType="Map" useGeneratedKeys="false"> INSERT INTO analysis_properties ( uuid, - snapshot_uuid, + analysis_uuid, kee, clob_value, is_empty, created_at ) VALUES ( #{analysisPropertyDto.uuid, jdbcType=VARCHAR}, - #{analysisPropertyDto.snapshotUuid, jdbcType=VARCHAR}, + #{analysisPropertyDto.analysisUuid, jdbcType=VARCHAR}, #{analysisPropertyDto.key, jdbcType=VARCHAR}, #{analysisPropertyDto.value, jdbcType=VARCHAR}, ${_false}, diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/purge/PurgeMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/purge/PurgeMapper.xml index 1b6aad991c9..b84f1842468 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/purge/PurgeMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/purge/PurgeMapper.xml @@ -185,7 +185,7 @@ <delete id="deleteAnalysisProperties" parameterType="map"> DELETE FROM analysis_properties WHERE - snapshot_uuid IN + analysis_uuid IN <foreach collection="analysisUuids" open="(" close=")" item="analysisUuid" separator=","> #{analysisUuid,jdbcType=VARCHAR} </foreach> diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/component/AnalysisPropertiesDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/component/AnalysisPropertiesDaoTest.java index cd739ae558e..6c27c730682 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/component/AnalysisPropertiesDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/component/AnalysisPropertiesDaoTest.java @@ -49,7 +49,7 @@ public class AnalysisPropertiesDaoTest { @Test public void insert_with_null_uuid_throws_NPE() { AnalysisPropertyDto analysisPropertyDto = new AnalysisPropertyDto() - .setSnapshotUuid(randomAlphanumeric(10)) + .setAnalysisUuid(randomAlphanumeric(10)) .setKey(randomAlphanumeric(10)) .setValue(randomAlphanumeric(10)); @@ -62,7 +62,7 @@ public class AnalysisPropertiesDaoTest { @Test public void insert_with_null_key_throws_NPE() { AnalysisPropertyDto analysisPropertyDto = new AnalysisPropertyDto() - .setSnapshotUuid(randomAlphanumeric(10)) + .setAnalysisUuid(randomAlphanumeric(10)) .setUuid(randomAlphanumeric(10)) .setValue(randomAlphanumeric(10)); @@ -73,14 +73,14 @@ public class AnalysisPropertiesDaoTest { } @Test - public void insert_with_null_snapshot_uuid_throws_NPE() { + public void insert_with_null_analysis_uuid_throws_NPE() { AnalysisPropertyDto analysisPropertyDto = new AnalysisPropertyDto() .setUuid(randomAlphanumeric(10)) .setKey(randomAlphanumeric(10)) .setValue(randomAlphanumeric(10)); expectedException.expect(NullPointerException.class); - expectedException.expectMessage("snapshot uuid cannot be null"); + expectedException.expectMessage("analysis uuid cannot be null"); underTest.insert(dbSession, analysisPropertyDto); } @@ -88,7 +88,7 @@ public class AnalysisPropertiesDaoTest { @Test public void insert_with_null_value_throws_NPE() { AnalysisPropertyDto analysisPropertyDto = new AnalysisPropertyDto() - .setSnapshotUuid(randomAlphanumeric(10)) + .setAnalysisUuid(randomAlphanumeric(10)) .setUuid(randomAlphanumeric(10)) .setKey(randomAlphanumeric(10)); @@ -140,22 +140,22 @@ public class AnalysisPropertiesDaoTest { @Test public void selectByAnalysisUuid_should_return_correct_values() { - String snapshotUuid = randomAlphanumeric(40); + String analysisUuid = randomAlphanumeric(40); List<AnalysisPropertyDto> propertyDtos = Arrays.asList( - newAnalysisPropertyDto(random.nextInt(8000), snapshotUuid), - newAnalysisPropertyDto(random.nextInt(8000), snapshotUuid), - newAnalysisPropertyDto(random.nextInt(8000), snapshotUuid), - newAnalysisPropertyDto(random.nextInt(8000), snapshotUuid), - newAnalysisPropertyDto(random.nextInt(8000), snapshotUuid), - newAnalysisPropertyDto(random.nextInt(8000), snapshotUuid), - newAnalysisPropertyDto(random.nextInt(8000), snapshotUuid), - newAnalysisPropertyDto(random.nextInt(8000), snapshotUuid)); + newAnalysisPropertyDto(random.nextInt(8000), analysisUuid), + newAnalysisPropertyDto(random.nextInt(8000), analysisUuid), + newAnalysisPropertyDto(random.nextInt(8000), analysisUuid), + newAnalysisPropertyDto(random.nextInt(8000), analysisUuid), + newAnalysisPropertyDto(random.nextInt(8000), analysisUuid), + newAnalysisPropertyDto(random.nextInt(8000), analysisUuid), + newAnalysisPropertyDto(random.nextInt(8000), analysisUuid), + newAnalysisPropertyDto(random.nextInt(8000), analysisUuid)); underTest.insert(dbSession, propertyDtos); assertThat(dbTester.countRowsOfTable(dbSession, "ANALYSIS_PROPERTIES")).isEqualTo(propertyDtos.size()); - List<AnalysisPropertyDto> result = underTest.selectBySnapshotUuid(dbSession, snapshotUuid); + List<AnalysisPropertyDto> result = underTest.selectByAnalysisUuid(dbSession, analysisUuid); assertThat(result).containsExactlyInAnyOrder(propertyDtos.toArray(new AnalysisPropertyDto[0])); } @@ -165,9 +165,9 @@ public class AnalysisPropertiesDaoTest { return analysisPropertyDto; } - private AnalysisPropertyDto newAnalysisPropertyDto(int valueLength, String snapshotUuid) { + private AnalysisPropertyDto newAnalysisPropertyDto(int valueLength, String analysisUuid) { return new AnalysisPropertyDto() - .setSnapshotUuid(snapshotUuid) + .setAnalysisUuid(analysisUuid) .setKey(randomAlphanumeric(512)) .setUuid(randomAlphanumeric(40)) .setValue(randomAlphanumeric(valueLength)) @@ -175,7 +175,7 @@ public class AnalysisPropertiesDaoTest { } private void compareFirstValueWith(AnalysisPropertyDto analysisPropertyDto) { - AnalysisPropertyDto dtoFromDatabase = underTest.selectBySnapshotUuid(dbSession, analysisPropertyDto.getSnapshotUuid()).get(0); + AnalysisPropertyDto dtoFromDatabase = underTest.selectByAnalysisUuid(dbSession, analysisPropertyDto.getAnalysisUuid()).get(0); assertThat(dtoFromDatabase).isEqualTo(analysisPropertyDto); } } diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/component/AnalysisPropertyDtoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/component/AnalysisPropertyDtoTest.java index 911ece8f535..49f7cad04b5 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/component/AnalysisPropertyDtoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/component/AnalysisPropertyDtoTest.java @@ -64,55 +64,55 @@ public class AnalysisPropertyDtoTest { } @Test - public void null_snapshot_uuid_should_throw_NPE() { + public void null_analysis_uuid_should_throw_NPE() { underTest = new AnalysisPropertyDto(); expectedException.expect(NullPointerException.class); - expectedException.expectMessage("snapshotUuid cannot be null"); + expectedException.expectMessage("analysisUuid cannot be null"); - underTest.setSnapshotUuid(null); + underTest.setAnalysisUuid(null); } @Test public void test_equality() { underTest = new AnalysisPropertyDto() .setUuid(randomAlphanumeric(40)) - .setSnapshotUuid(randomAlphanumeric(40)) + .setAnalysisUuid(randomAlphanumeric(40)) .setKey(randomAlphanumeric(512)) .setValue(randomAlphanumeric(10000)); assertThat(underTest).isEqualTo( new AnalysisPropertyDto() .setUuid(underTest.getUuid()) - .setSnapshotUuid(underTest.getSnapshotUuid()) + .setAnalysisUuid(underTest.getAnalysisUuid()) .setKey(underTest.getKey()) .setValue(underTest.getValue())); assertThat(underTest).isNotEqualTo( new AnalysisPropertyDto() .setUuid("1" + underTest.getUuid()) - .setSnapshotUuid(underTest.getSnapshotUuid()) + .setAnalysisUuid(underTest.getAnalysisUuid()) .setKey(underTest.getKey()) .setValue(underTest.getValue())); assertThat(underTest).isNotEqualTo( new AnalysisPropertyDto() .setUuid(underTest.getUuid()) - .setSnapshotUuid("1" + underTest.getSnapshotUuid()) + .setAnalysisUuid("1" + underTest.getAnalysisUuid()) .setKey(underTest.getKey()) .setValue(underTest.getValue())); assertThat(underTest).isNotEqualTo( new AnalysisPropertyDto() .setUuid(underTest.getUuid()) - .setSnapshotUuid(underTest.getSnapshotUuid()) + .setAnalysisUuid(underTest.getAnalysisUuid()) .setKey("1" + underTest.getKey()) .setValue(underTest.getValue())); assertThat(underTest).isNotEqualTo( new AnalysisPropertyDto() .setUuid(underTest.getUuid()) - .setSnapshotUuid(underTest.getSnapshotUuid()) + .setAnalysisUuid(underTest.getAnalysisUuid()) .setKey(underTest.getKey()) .setValue("1" + underTest.getValue())); } @@ -121,14 +121,14 @@ public class AnalysisPropertyDtoTest { public void test_hashcode() { underTest = new AnalysisPropertyDto() .setUuid(randomAlphanumeric(40)) - .setSnapshotUuid(randomAlphanumeric(40)) + .setAnalysisUuid(randomAlphanumeric(40)) .setKey(randomAlphanumeric(512)) .setValue(randomAlphanumeric(10000)); assertThat(underTest.hashCode()).isEqualTo( new AnalysisPropertyDto() .setUuid(underTest.getUuid()) - .setSnapshotUuid(underTest.getSnapshotUuid()) + .setAnalysisUuid(underTest.getAnalysisUuid()) .setKey(underTest.getKey()) .setValue(underTest.getValue()) .hashCode()); @@ -136,7 +136,7 @@ public class AnalysisPropertyDtoTest { assertThat(underTest.hashCode()).isNotEqualTo( new AnalysisPropertyDto() .setUuid("1" + underTest.getUuid()) - .setSnapshotUuid(underTest.getSnapshotUuid()) + .setAnalysisUuid(underTest.getAnalysisUuid()) .setKey(underTest.getKey()) .setValue(underTest.getValue()) .hashCode()); @@ -144,7 +144,7 @@ public class AnalysisPropertyDtoTest { assertThat(underTest.hashCode()).isNotEqualTo( new AnalysisPropertyDto() .setUuid(underTest.getUuid()) - .setSnapshotUuid("1" + underTest.getSnapshotUuid()) + .setAnalysisUuid("1" + underTest.getAnalysisUuid()) .setKey(underTest.getKey()) .setValue(underTest.getValue()) .hashCode()); @@ -152,7 +152,7 @@ public class AnalysisPropertyDtoTest { assertThat(underTest.hashCode()).isNotEqualTo( new AnalysisPropertyDto() .setUuid(underTest.getUuid()) - .setSnapshotUuid(underTest.getSnapshotUuid()) + .setAnalysisUuid(underTest.getAnalysisUuid()) .setKey("1" + underTest.getKey()) .setValue(underTest.getValue()) .hashCode()); @@ -160,7 +160,7 @@ public class AnalysisPropertyDtoTest { assertThat(underTest.hashCode()).isNotEqualTo( new AnalysisPropertyDto() .setUuid(underTest.getUuid()) - .setSnapshotUuid(underTest.getSnapshotUuid()) + .setAnalysisUuid(underTest.getAnalysisUuid()) .setKey(underTest.getKey()) .setValue("1" + underTest.getValue()) .hashCode()); diff --git a/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeCommandsTest/shouldDeleteResource.xml b/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeCommandsTest/shouldDeleteResource.xml index 3660be0b472..741b6672f11 100644 --- a/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeCommandsTest/shouldDeleteResource.xml +++ b/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeCommandsTest/shouldDeleteResource.xml @@ -46,7 +46,7 @@ /> <analysis_properties uuid="u1" - snapshot_uuid="u1" + analysis_uuid="u1" kee="key1" clob_value="[null]" text_value="value1" diff --git a/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeCommandsTest/shouldPurgeAnalysis-result.xml b/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeCommandsTest/shouldPurgeAnalysis-result.xml index e41b1f1d7ab..db451bf70ca 100644 --- a/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeCommandsTest/shouldPurgeAnalysis-result.xml +++ b/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeCommandsTest/shouldPurgeAnalysis-result.xml @@ -36,7 +36,7 @@ Note that measures, events and reviews are not deleted. revision="[null]" /> <analysis_properties uuid="u1" - snapshot_uuid="u1" + analysis_uuid="u1" kee="key1" text_value="value1" clob_value="[null]" @@ -111,7 +111,7 @@ Note that measures, events and reviews are not deleted. /> <analysis_properties uuid="u2" - snapshot_uuid="u2" + analysis_uuid="u2" kee="key2" clob_value="[null]" text_value="value2" diff --git a/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeCommandsTest/shouldPurgeAnalysis.xml b/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeCommandsTest/shouldPurgeAnalysis.xml index 44d70d4f14f..75bef287174 100644 --- a/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeCommandsTest/shouldPurgeAnalysis.xml +++ b/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeCommandsTest/shouldPurgeAnalysis.xml @@ -28,7 +28,7 @@ /> <analysis_properties uuid="u1" - snapshot_uuid="u1" + analysis_uuid="u1" kee="key1" clob_value="[null]" text_value="value1" @@ -102,7 +102,7 @@ /> <analysis_properties uuid="u2" - snapshot_uuid="u2" + analysis_uuid="u2" kee="key2" clob_value="[null]" text_value="value2" diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v80/DbVersion80.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v80/DbVersion80.java index f3f4721ef6d..71f1748e51d 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v80/DbVersion80.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v80/DbVersion80.java @@ -29,6 +29,8 @@ public class DbVersion80 implements DbVersion { .add(3000, "Set Organizations#guarded column nullable", MakeOrganizationsGuardedNullable.class) .add(3001, "Create ProjectQualityGates table", CreateProjectQualityGatesTable.class) .add(3002, "Make index on DEPRECATED_RULE_KEYS.RULE_ID non unique", MakeDeprecatedRuleKeysRuleIdIndexNonUnique.class) - .add(3003, "Populate ProjectQualityGate table from Properties table", PopulateProjectQualityGatesTable.class); + .add(3003, "Populate ProjectQualityGate table from Properties table", PopulateProjectQualityGatesTable.class) + .add(3004, "Rename ANALYSIS_PROPERTIES.SNAPSHOT_UUID to ANALYSIS_UUID", RenameAnalysisPropertiesSnapshotUuid.class) + ; } } diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v80/RenameAnalysisPropertiesSnapshotUuid.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v80/RenameAnalysisPropertiesSnapshotUuid.java new file mode 100644 index 00000000000..85a747bf3da --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v80/RenameAnalysisPropertiesSnapshotUuid.java @@ -0,0 +1,63 @@ +/* + * SonarQube + * Copyright (C) 2009-2019 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.v80; + +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.CreateIndexBuilder; +import org.sonar.server.platform.db.migration.sql.DropIndexBuilder; +import org.sonar.server.platform.db.migration.sql.RenameColumnsBuilder; +import org.sonar.server.platform.db.migration.step.DdlChange; + +import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.UUID_SIZE; + +public class RenameAnalysisPropertiesSnapshotUuid extends DdlChange { + private static final VarcharColumnDef ANALYSIS_UUID_COLUMN = VarcharColumnDef.newVarcharColumnDefBuilder() + .setColumnName("analysis_uuid") + .setIsNullable(false) + .setLimit(UUID_SIZE) + .build(); + + public RenameAnalysisPropertiesSnapshotUuid(Database db) { + super(db); + } + + @Override + public void execute(Context context) throws SQLException { + String tableName = "analysis_properties"; + + context.execute(new DropIndexBuilder(getDialect()) + .setTable(tableName) + .setName("ix_snapshot_uuid") + .build()); + + context.execute(new RenameColumnsBuilder(getDialect(), tableName) + .renameColumn("snapshot_uuid", ANALYSIS_UUID_COLUMN) + .build()); + + context.execute(new CreateIndexBuilder() + .setTable(tableName) + .setName("analysis_properties_analysis") + .setUnique(false) + .addColumn(ANALYSIS_UUID_COLUMN) + .build()); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v80/DbVersion80Test.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v80/DbVersion80Test.java index f69a48b5e7c..2ce869795bc 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v80/DbVersion80Test.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v80/DbVersion80Test.java @@ -35,7 +35,7 @@ public class DbVersion80Test { @Test public void verify_migration_count() { - verifyMigrationCount(underTest, 4); + verifyMigrationCount(underTest, 5); } } diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v80/RenameAnalysisPropertiesSnapshotUuidTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v80/RenameAnalysisPropertiesSnapshotUuidTest.java new file mode 100644 index 00000000000..e64f33f5cb9 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v80/RenameAnalysisPropertiesSnapshotUuidTest.java @@ -0,0 +1,56 @@ +/* + * SonarQube + * Copyright (C) 2009-2019 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.v80; + +import java.sql.SQLException; +import java.sql.Types; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.sonar.db.CoreDbTester; + +public class RenameAnalysisPropertiesSnapshotUuidTest { + + private static final String TABLE_NAME = "analysis_properties"; + + @Rule + public CoreDbTester dbTester = CoreDbTester.createForSchema(RenameAnalysisPropertiesSnapshotUuidTest.class, "analysis_properties.sql"); + @Rule + public ExpectedException expectedException = ExpectedException.none(); + + private RenameAnalysisPropertiesSnapshotUuid underTest = new RenameAnalysisPropertiesSnapshotUuid(dbTester.database()); + + @Test + public void execute_renames_column_snapshot_uuid_and_recreate_index_snapshot_uuid_with_a_new_name() throws SQLException { + underTest.execute(); + + dbTester.assertColumnDefinition(TABLE_NAME, "analysis_uuid", Types.VARCHAR, 40, false); + dbTester.assertIndex(TABLE_NAME, "analysis_properties_analysis", "analysis_uuid"); + } + + @Test + public void execute_is_not_reentrant() throws SQLException { + underTest.execute(); + + expectedException.expect(IllegalStateException.class); + + underTest.execute(); + } +} diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v80/RenameAnalysisPropertiesSnapshotUuidTest/analysis_properties.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v80/RenameAnalysisPropertiesSnapshotUuidTest/analysis_properties.sql new file mode 100644 index 00000000000..0a131046edc --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v80/RenameAnalysisPropertiesSnapshotUuidTest/analysis_properties.sql @@ -0,0 +1,12 @@ +CREATE TABLE "ANALYSIS_PROPERTIES" ( + "UUID" VARCHAR(40) NOT NULL, + "SNAPSHOT_UUID" VARCHAR(40) NOT NULL, + "KEE" VARCHAR(512) NOT NULL, + "TEXT_VALUE" VARCHAR(4000), + "CLOB_VALUE" CLOB, + "IS_EMPTY" BOOLEAN NOT NULL, + "CREATED_AT" BIGINT NOT NULL, + + CONSTRAINT "PK_ANALYSIS_PROPERTIES" PRIMARY KEY ("UUID") +); +CREATE INDEX "SNAPSHOT_UUID" ON "ANALYSIS_PROPERTIES" ("SNAPSHOT_UUID"); diff --git a/server/sonar-server/src/main/java/org/sonar/server/webhook/WebhookQGChangeEventListener.java b/server/sonar-server/src/main/java/org/sonar/server/webhook/WebhookQGChangeEventListener.java index 5c611b581ae..098302e7816 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/webhook/WebhookQGChangeEventListener.java +++ b/server/sonar-server/src/main/java/org/sonar/server/webhook/WebhookQGChangeEventListener.java @@ -87,7 +87,7 @@ public class WebhookQGChangeEventListener implements QGChangeEventListener { ComponentDto project = event.getProject(); BranchDto branch = event.getBranch(); SnapshotDto analysis = event.getAnalysis(); - Map<String, String> analysisProperties = dbClient.analysisPropertiesDao().selectBySnapshotUuid(dbSession, analysis.getUuid()) + Map<String, String> analysisProperties = dbClient.analysisPropertiesDao().selectByAnalysisUuid(dbSession, analysis.getUuid()) .stream() .collect(Collectors.toMap(AnalysisPropertyDto::getKey, AnalysisPropertyDto::getValue)); String projectUuid = StringUtils.defaultString(project.getMainBranchProjectUuid(), project.projectUuid()); diff --git a/server/sonar-server/src/test/java/org/sonar/server/webhook/WebhookQGChangeEventListenerTest.java b/server/sonar-server/src/test/java/org/sonar/server/webhook/WebhookQGChangeEventListenerTest.java index 4fb435e8024..7d82731e6a3 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/webhook/WebhookQGChangeEventListenerTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/webhook/WebhookQGChangeEventListenerTest.java @@ -245,7 +245,7 @@ public class WebhookQGChangeEventListenerTest { List<AnalysisPropertyDto> analysisProperties = properties.entrySet().stream() .map(entry -> new AnalysisPropertyDto() .setUuid(UuidFactoryFast.getInstance().create()) - .setSnapshotUuid(snapshotUuid) + .setAnalysisUuid(snapshotUuid) .setKey(entry.getKey()) .setValue(entry.getValue())) .collect(toArrayList(properties.size())); |