Browse Source

SONAR-6818 Add revision column in file_sources db table

tags/5.2-RC1
Teryk Bellahsene 8 years ago
parent
commit
5c28803132

+ 30
- 0
server/sonar-web/src/main/webapp/WEB-INF/db/migrate/929_add_commit_in_file_sources.rb View File

@@ -0,0 +1,30 @@
#
# SonarQube, open source software quality management tool.
# Copyright (C) 2008-2014 SonarSource
# mailto:contact AT sonarsource DOT com
#
# SonarQube 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.
#
# SonarQube 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.
#

#
# SonarQube 5.2
#
class AddCommitInFileSources < ActiveRecord::Migration

def self.up
add_column 'file_sources', 'revision', :string, :limit => 100
end

end

+ 10
- 0
sonar-db/src/main/java/org/sonar/db/source/FileSourceDto.java View File

@@ -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";

+ 1
- 1
sonar-db/src/main/java/org/sonar/db/version/DatabaseVersion.java View File

@@ -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

+ 7
- 5
sonar-db/src/main/resources/org/sonar/db/source/FileSourceMapper.xml View File

@@ -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>


+ 1
- 0
sonar-db/src/main/resources/org/sonar/db/version/schema-h2.ddl View File

@@ -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
);

+ 8
- 5
sonar-db/src/test/java/org/sonar/db/source/FileSourceDaoTest.java View File

@@ -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> {

+ 2
- 2
sonar-db/src/test/resources/org/sonar/db/purge/PurgeDaoTest/delete_file_sources_of_disabled_resources-result.xml View File

@@ -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>

+ 4
- 4
sonar-db/src/test/resources/org/sonar/db/purge/PurgeDaoTest/delete_file_sources_of_disabled_resources.xml View File

@@ -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>

+ 2
- 2
sonar-db/src/test/resources/org/sonar/db/source/FileSourceDaoTest/insert-result.xml View File

@@ -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>

+ 2
- 2
sonar-db/src/test/resources/org/sonar/db/source/FileSourceDaoTest/shared.xml View File

@@ -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>

+ 1
- 1
sonar-db/src/test/resources/org/sonar/db/source/FileSourceDaoTest/update-result.xml View File

@@ -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" />



+ 3
- 3
sonar-db/src/test/resources/org/sonar/db/source/FileSourceDaoTest/update_date_when_updated_date_is_zero-result.xml View File

@@ -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" />


+ 3
- 3
sonar-db/src/test/resources/org/sonar/db/source/FileSourceDaoTest/update_date_when_updated_date_is_zero.xml View File

@@ -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" />


Loading…
Cancel
Save