diff options
author | Teryk Bellahsene <teryk.bellahsene@sonarsource.com> | 2015-09-16 18:40:00 +0200 |
---|---|---|
committer | Teryk Bellahsene <teryk.bellahsene@sonarsource.com> | 2015-09-16 18:44:51 +0200 |
commit | 5c288031321de250b5d2e90c4281bd25cd80f9e4 (patch) | |
tree | 67514c6997d91afa1a73b55bad8a2c7f50f3fb91 /sonar-db | |
parent | 87f52cb4b058a9fd4c286e24e8c37cf4b53ba958 (diff) | |
download | sonarqube-5c288031321de250b5d2e90c4281bd25cd80f9e4.tar.gz sonarqube-5c288031321de250b5d2e90c4281bd25cd80f9e4.zip |
SONAR-6818 Add revision column in file_sources db table
Diffstat (limited to 'sonar-db')
12 files changed, 44 insertions, 28 deletions
diff --git a/sonar-db/src/main/java/org/sonar/db/source/FileSourceDto.java b/sonar-db/src/main/java/org/sonar/db/source/FileSourceDto.java index 3948fe6f4ff..686635e0142 100644 --- a/sonar-db/src/main/java/org/sonar/db/source/FileSourceDto.java +++ b/sonar-db/src/main/java/org/sonar/db/source/FileSourceDto.java @@ -44,6 +44,7 @@ public class FileSourceDto { private byte[] binaryData; private String dataType; private String dataHash; + private String revision; public Long getId() { return id; @@ -265,6 +266,15 @@ public class FileSourceDto { return this; } + public String getRevision() { + return revision; + } + + public FileSourceDto setRevision(String revision) { + this.revision = revision; + return this; + } + public static class Type { public static final String SOURCE = "SOURCE"; public static final String TEST = "TEST"; diff --git a/sonar-db/src/main/java/org/sonar/db/version/DatabaseVersion.java b/sonar-db/src/main/java/org/sonar/db/version/DatabaseVersion.java index 2b51ffbafd6..b29b1aec861 100644 --- a/sonar-db/src/main/java/org/sonar/db/version/DatabaseVersion.java +++ b/sonar-db/src/main/java/org/sonar/db/version/DatabaseVersion.java @@ -29,7 +29,7 @@ import org.sonar.db.MyBatis; public class DatabaseVersion { - public static final int LAST_VERSION = 928; + public static final int LAST_VERSION = 929; /** * The minimum supported version which can be upgraded. Lower diff --git a/sonar-db/src/main/resources/org/sonar/db/source/FileSourceMapper.xml b/sonar-db/src/main/resources/org/sonar/db/source/FileSourceMapper.xml index dd6a83ed5ff..53410f998bb 100644 --- a/sonar-db/src/main/resources/org/sonar/db/source/FileSourceMapper.xml +++ b/sonar-db/src/main/resources/org/sonar/db/source/FileSourceMapper.xml @@ -7,23 +7,24 @@ <select id="select" parameterType="map" resultType="org.sonar.db.source.FileSourceDto"> SELECT id, project_uuid as projectUuid, file_uuid as fileUuid, created_at as createdAt, updated_at as updatedAt, binary_data as binaryData, line_hashes as lineHashes, data_hash as dataHash, src_hash as srcHash, data_type as - dataType + dataType, revision FROM file_sources WHERE file_uuid = #{fileUuid} and data_type = #{dataType} </select> <select id="selectHashesForProject" parameterType="map" resultType="org.sonar.db.source.FileSourceDto"> - SELECT id, file_uuid as fileUuid, data_hash as dataHash, src_hash as srcHash, updated_at as updatedAt + SELECT id, file_uuid as fileUuid, data_hash as dataHash, src_hash as srcHash, revision, updated_at as updatedAt FROM file_sources WHERE project_uuid = #{projectUuid} and data_type=#{dataType} </select> <insert id="insert" parameterType="org.sonar.db.source.FileSourceDto" useGeneratedKeys="false"> INSERT INTO file_sources (project_uuid, file_uuid, created_at, updated_at, binary_data, line_hashes, data_hash, - src_hash, data_type) + src_hash, data_type, revision) VALUES (#{projectUuid,jdbcType=VARCHAR}, #{fileUuid,jdbcType=VARCHAR}, #{createdAt,jdbcType=BIGINT}, #{updatedAt,jdbcType=BIGINT}, #{binaryData,jdbcType=BLOB}, #{lineHashes,jdbcType=CLOB}, - #{dataHash,jdbcType=VARCHAR}, #{srcHash,jdbcType=VARCHAR},#{dataType,jdbcType=VARCHAR}) + #{dataHash,jdbcType=VARCHAR}, #{srcHash,jdbcType=VARCHAR},#{dataType,jdbcType=VARCHAR}, + #{revision,jdbcType=VARCHAR}) </insert> <update id="update" parameterType="org.sonar.db.source.FileSourceDto" useGeneratedKeys="false"> @@ -32,7 +33,8 @@ binary_data = #{binaryData,jdbcType=BLOB}, line_hashes = #{lineHashes,jdbcType=CLOB}, data_hash = #{dataHash,jdbcType=VARCHAR}, - src_hash = #{srcHash,jdbcType=VARCHAR} + src_hash = #{srcHash,jdbcType=VARCHAR}, + revision = #{revision,jdbcType=VARCHAR} WHERE id = #{id} </update> diff --git a/sonar-db/src/main/resources/org/sonar/db/version/schema-h2.ddl b/sonar-db/src/main/resources/org/sonar/db/version/schema-h2.ddl index 29e46ea45b1..2ea8ececdef 100644 --- a/sonar-db/src/main/resources/org/sonar/db/version/schema-h2.ddl +++ b/sonar-db/src/main/resources/org/sonar/db/version/schema-h2.ddl @@ -529,6 +529,7 @@ CREATE TABLE "FILE_SOURCES" ( "DATA_TYPE" VARCHAR(20), "DATA_HASH" VARCHAR(50), "SRC_HASH" VARCHAR(50), + "REVISION" VARCHAR(100), "CREATED_AT" BIGINT NOT NULL, "UPDATED_AT" BIGINT NOT NULL ); diff --git a/sonar-db/src/test/java/org/sonar/db/source/FileSourceDaoTest.java b/sonar-db/src/test/java/org/sonar/db/source/FileSourceDaoTest.java index 1ea318ab10c..6971a700aec 100644 --- a/sonar-db/src/test/java/org/sonar/db/source/FileSourceDaoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/source/FileSourceDaoTest.java @@ -55,6 +55,7 @@ public class FileSourceDaoTest { assertThat(fileSourceDto.getCreatedAt()).isEqualTo(1500000000000L); assertThat(fileSourceDto.getUpdatedAt()).isEqualTo(1500000000000L); assertThat(fileSourceDto.getDataType()).isEqualTo(Type.SOURCE); + assertThat(fileSourceDto.getRevision()).isEqualTo("123456789"); } @Test @@ -100,10 +101,11 @@ public class FileSourceDaoTest { .setSrcHash("FILE2_HASH") .setDataType(Type.SOURCE) .setCreatedAt(1500000000000L) - .setUpdatedAt(1500000000001L)); + .setUpdatedAt(1500000000001L) + .setRevision("123456789")); dbTester.assertDbUnitTable(getClass(), "insert-result.xml", "file_sources", - "project_uuid", "file_uuid", "data_hash", "line_hashes", "src_hash", "created_at", "updated_at", "data_type"); + "project_uuid", "file_uuid", "data_hash", "line_hashes", "src_hash", "created_at", "updated_at", "data_type", "revision"); } @Test @@ -119,10 +121,11 @@ public class FileSourceDaoTest { .setSrcHash("NEW_FILE_HASH") .setLineHashes("NEW_LINE_HASHES") .setDataType(Type.SOURCE) - .setUpdatedAt(1500000000002L)); + .setUpdatedAt(1500000000002L) + .setRevision("987654321")); dbTester.assertDbUnitTable(getClass(), "update-result.xml", "file_sources", - "project_uuid", "file_uuid", "data_hash", "line_hashes", "src_hash", "created_at", "updated_at", "data_type"); + "project_uuid", "file_uuid", "data_hash", "line_hashes", "src_hash", "created_at", "updated_at", "data_type", "revision"); } @Test @@ -133,7 +136,7 @@ public class FileSourceDaoTest { dbTester.getSession().commit(); dbTester.assertDbUnitTable(getClass(), "update_date_when_updated_date_is_zero-result.xml", "file_sources", - "project_uuid", "file_uuid", "data_hash", "line_hashes", "src_hash", "created_at", "updated_at", "data_type"); + "project_uuid", "file_uuid", "data_hash", "line_hashes", "src_hash", "created_at", "updated_at", "data_type", "revision"); } private static class ReaderToStringFunction implements Function<Reader, String> { diff --git a/sonar-db/src/test/resources/org/sonar/db/purge/PurgeDaoTest/delete_file_sources_of_disabled_resources-result.xml b/sonar-db/src/test/resources/org/sonar/db/purge/PurgeDaoTest/delete_file_sources_of_disabled_resources-result.xml index 2cb6b58826f..919e713b25b 100644 --- a/sonar-db/src/test/resources/org/sonar/db/purge/PurgeDaoTest/delete_file_sources_of_disabled_resources-result.xml +++ b/sonar-db/src/test/resources/org/sonar/db/purge/PurgeDaoTest/delete_file_sources_of_disabled_resources-result.xml @@ -1,9 +1,9 @@ <dataset> <file_sources id="2" project_uuid="ABCD" file_uuid="KLMN" binary_data="[null]" line_hashes="[null]" - data_hash="321654988" + data_hash="321654988" revision="123456789" created_at="123456789" updated_at="123456789" src_hash="123456" data_type="SOURCE"/> <file_sources id="4" project_uuid="ABCD" file_uuid="KLMN" binary_data="[null]" line_hashes="[null]" - data_hash="321654988" + data_hash="321654988" revision="123456789" created_at="123456789" updated_at="123456789" src_hash="123456" data_type="TEST"/> </dataset> diff --git a/sonar-db/src/test/resources/org/sonar/db/purge/PurgeDaoTest/delete_file_sources_of_disabled_resources.xml b/sonar-db/src/test/resources/org/sonar/db/purge/PurgeDaoTest/delete_file_sources_of_disabled_resources.xml index 5307fc8219a..0f86e179613 100644 --- a/sonar-db/src/test/resources/org/sonar/db/purge/PurgeDaoTest/delete_file_sources_of_disabled_resources.xml +++ b/sonar-db/src/test/resources/org/sonar/db/purge/PurgeDaoTest/delete_file_sources_of_disabled_resources.xml @@ -73,15 +73,15 @@ build_date="1228222680000" version="[null]" path="[null]"/> <file_sources id="1" project_uuid="ABCD" file_uuid="GHIJ" binary_data="[null]" line_hashes="[null]" - data_hash="321654987" + data_hash="321654987" revision="123456789" created_at="123456789" updated_at="123456789" src_hash="12345" data_type="SOURCE"/> <file_sources id="2" project_uuid="ABCD" file_uuid="KLMN" binary_data="[null]" line_hashes="[null]" - data_hash="321654988" + data_hash="321654988" revision="123456789" created_at="123456789" updated_at="123456789" src_hash="123456" data_type="SOURCE"/> <file_sources id="3" project_uuid="ABCD" file_uuid="GHIJ" binary_data="[null]" line_hashes="[null]" - data_hash="321654987" + data_hash="321654987" revision="123456789" created_at="123456789" updated_at="123456789" src_hash="12345" data_type="TEST"/> <file_sources id="4" project_uuid="ABCD" file_uuid="KLMN" binary_data="[null]" line_hashes="[null]" - data_hash="321654988" + data_hash="321654988" revision="123456789" created_at="123456789" updated_at="123456789" src_hash="123456" data_type="TEST"/> </dataset> diff --git a/sonar-db/src/test/resources/org/sonar/db/source/FileSourceDaoTest/insert-result.xml b/sonar-db/src/test/resources/org/sonar/db/source/FileSourceDaoTest/insert-result.xml index 4f347782dca..95f9882e86f 100644 --- a/sonar-db/src/test/resources/org/sonar/db/source/FileSourceDaoTest/insert-result.xml +++ b/sonar-db/src/test/resources/org/sonar/db/source/FileSourceDaoTest/insert-result.xml @@ -3,7 +3,7 @@ <file_sources id="101" project_uuid="PRJ_UUID" file_uuid="FILE1_UUID" binary_data="abcde" data_hash="hash" line_hashes="ABC\nDEF\nGHI" - src_hash="FILE_HASH" + src_hash="FILE_HASH" revision="123456789" created_at="1500000000000" updated_at="1500000000000" data_type="SOURCE" /> @@ -11,7 +11,7 @@ binary_data="[ignore]" data_hash="FILE2_DATA_HASH" line_hashes="LINE1_HASH\nLINE2_HASH" - src_hash="FILE2_HASH" + src_hash="FILE2_HASH" revision="123456789" created_at="1500000000000" updated_at="1500000000001" data_type="SOURCE" /> </dataset> diff --git a/sonar-db/src/test/resources/org/sonar/db/source/FileSourceDaoTest/shared.xml b/sonar-db/src/test/resources/org/sonar/db/source/FileSourceDaoTest/shared.xml index 5187ca217af..f7374caf041 100644 --- a/sonar-db/src/test/resources/org/sonar/db/source/FileSourceDaoTest/shared.xml +++ b/sonar-db/src/test/resources/org/sonar/db/source/FileSourceDaoTest/shared.xml @@ -3,7 +3,7 @@ <file_sources id="101" project_uuid="PRJ_UUID" file_uuid="FILE1_UUID" binary_data="abcde" data_hash="hash" line_hashes="ABC\nDEF\nGHI" - src_hash="FILE_HASH" - created_at="1500000000000" updated_at="1500000000000" data_type="SOURCE" /> + src_hash="FILE_HASH" revision="123456789" + created_at="1500000000000" updated_at="1500000000000" data_type="SOURCE"/> </dataset> diff --git a/sonar-db/src/test/resources/org/sonar/db/source/FileSourceDaoTest/update-result.xml b/sonar-db/src/test/resources/org/sonar/db/source/FileSourceDaoTest/update-result.xml index 8dbe32d946d..1bcf34dac4e 100644 --- a/sonar-db/src/test/resources/org/sonar/db/source/FileSourceDaoTest/update-result.xml +++ b/sonar-db/src/test/resources/org/sonar/db/source/FileSourceDaoTest/update-result.xml @@ -4,7 +4,7 @@ binary_data="[ignore]" data_hash="NEW_DATA_HASH" line_hashes="NEW_LINE_HASHES" - src_hash="NEW_FILE_HASH" + src_hash="NEW_FILE_HASH" revision="987654321" created_at="1500000000000" updated_at="1500000000002" data_type="SOURCE" /> diff --git a/sonar-db/src/test/resources/org/sonar/db/source/FileSourceDaoTest/update_date_when_updated_date_is_zero-result.xml b/sonar-db/src/test/resources/org/sonar/db/source/FileSourceDaoTest/update_date_when_updated_date_is_zero-result.xml index 1ba1fe63a55..0b8802560ef 100644 --- a/sonar-db/src/test/resources/org/sonar/db/source/FileSourceDaoTest/update_date_when_updated_date_is_zero-result.xml +++ b/sonar-db/src/test/resources/org/sonar/db/source/FileSourceDaoTest/update_date_when_updated_date_is_zero-result.xml @@ -1,17 +1,17 @@ <dataset> <!-- Updated --> - <file_sources id="101" project_uuid="ABCD" file_uuid="FILE1_UUID" + <file_sources id="101" project_uuid="ABCD" file_uuid="FILE1_UUID" revision="123456789" binary_data="abcde" data_hash="hash" line_hashes="ABC\nDEF\nGHI" src_hash="FILE_HASH" created_at="1500000000000" updated_at="1500000000002" data_type="SOURCE" /> <!-- Not updated because updated_at is not null --> - <file_sources id="102" project_uuid="ABCD" file_uuid="FILE2_UUID" + <file_sources id="102" project_uuid="ABCD" file_uuid="FILE2_UUID" revision="123456789" binary_data="abcde" data_hash="hash" line_hashes="ABC\nDEF\nGHI" src_hash="FILE_HASH" created_at="1500000000000" updated_at="1500000000000" data_type="SOURCE" /> <!-- Not updated because on another project --> - <file_sources id="103" project_uuid="BCDE" file_uuid="FILE3_UUID" + <file_sources id="103" project_uuid="BCDE" file_uuid="FILE3_UUID" revision="123456789" binary_data="abcde" data_hash="hash" line_hashes="ABC\nDEF\nGHI" src_hash="FILE_HASH" created_at="1500000000000" updated_at="0" data_type="SOURCE" /> diff --git a/sonar-db/src/test/resources/org/sonar/db/source/FileSourceDaoTest/update_date_when_updated_date_is_zero.xml b/sonar-db/src/test/resources/org/sonar/db/source/FileSourceDaoTest/update_date_when_updated_date_is_zero.xml index 77a1f85b06a..7dd4686d680 100644 --- a/sonar-db/src/test/resources/org/sonar/db/source/FileSourceDaoTest/update_date_when_updated_date_is_zero.xml +++ b/sonar-db/src/test/resources/org/sonar/db/source/FileSourceDaoTest/update_date_when_updated_date_is_zero.xml @@ -1,15 +1,15 @@ <dataset> <!-- Only this source should be updated --> - <file_sources id="101" project_uuid="ABCD" file_uuid="FILE1_UUID" + <file_sources id="101" project_uuid="ABCD" file_uuid="FILE1_UUID" revision="123456789" binary_data="abcde" data_hash="hash" line_hashes="ABC\nDEF\nGHI" src_hash="FILE_HASH" created_at="1500000000000" updated_at="0" data_type="SOURCE" /> - <file_sources id="102" project_uuid="ABCD" file_uuid="FILE2_UUID" + <file_sources id="102" project_uuid="ABCD" file_uuid="FILE2_UUID" revision="123456789" binary_data="abcde" data_hash="hash" line_hashes="ABC\nDEF\nGHI" src_hash="FILE_HASH" created_at="1500000000000" updated_at="1500000000000" data_type="SOURCE" /> - <file_sources id="103" project_uuid="BCDE" file_uuid="FILE3_UUID" + <file_sources id="103" project_uuid="BCDE" file_uuid="FILE3_UUID" revision="123456789" binary_data="abcde" data_hash="hash" line_hashes="ABC\nDEF\nGHI" src_hash="FILE_HASH" created_at="1500000000000" updated_at="0" data_type="SOURCE" /> |