diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2019-02-01 10:29:50 +0100 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2019-02-11 09:11:43 +0100 |
commit | cc7ee64201bf5dece53fdbcb3a986c4206e0bf78 (patch) | |
tree | 11ff406519dbb468525020cb560f700b6c03c053 /server | |
parent | 27d19d7a35c91d702b4c3b411bbf97fe71256125 (diff) | |
download | sonarqube-cc7ee64201bf5dece53fdbcb3a986c4206e0bf78.tar.gz sonarqube-cc7ee64201bf5dece53fdbcb3a986c4206e0bf78.zip |
Revert "SONAR-11650 Drop DATA_TYPE from FILE_SOURCES"
This reverts commit 54ddc262
Diffstat (limited to 'server')
17 files changed, 63 insertions, 154 deletions
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 f4564b57007..dae2190297c 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 @@ -674,6 +674,7 @@ CREATE TABLE "FILE_SOURCES" ( "LINE_HASHES_VERSION" INTEGER, "LINE_COUNT" INTEGER NOT NULL, "BINARY_DATA" BLOB, + "DATA_TYPE" VARCHAR(20), "DATA_HASH" VARCHAR(50), "SRC_HASH" VARCHAR(50), "REVISION" VARCHAR(100), @@ -681,7 +682,7 @@ CREATE TABLE "FILE_SOURCES" ( "UPDATED_AT" BIGINT NOT NULL ); CREATE INDEX "FILE_SOURCES_PROJECT_UUID" ON "FILE_SOURCES" ("PROJECT_UUID"); -CREATE UNIQUE INDEX "FILE_SOURCES_FILE_UUID" ON "FILE_SOURCES" ("FILE_UUID"); +CREATE UNIQUE INDEX "FILE_SOURCES_UUID_TYPE" ON "FILE_SOURCES" ("FILE_UUID", "DATA_TYPE"); CREATE INDEX "FILE_SOURCES_UPDATED_AT" ON "FILE_SOURCES" ("UPDATED_AT"); diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/source/FileSourceDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/source/FileSourceDao.java index 1085b2c59e9..3a1567ccb3c 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/source/FileSourceDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/source/FileSourceDao.java @@ -59,7 +59,7 @@ public class FileSourceDao implements Dao { PreparedStatement pstmt = null; ResultSet rs = null; try { - pstmt = connection.prepareStatement("SELECT line_hashes FROM file_sources WHERE file_uuid=?"); + pstmt = connection.prepareStatement("SELECT line_hashes FROM file_sources WHERE file_uuid=? AND data_type='SOURCE'"); pstmt.setString(1, fileUuid); rs = pstmt.executeQuery(); if (rs.next()) { @@ -93,7 +93,7 @@ public class FileSourceDao implements Dao { ResultSet rs = null; Reader reader = null; try { - pstmt = connection.prepareStatement("SELECT line_hashes FROM file_sources WHERE file_uuid=?"); + pstmt = connection.prepareStatement("SELECT line_hashes FROM file_sources WHERE file_uuid=? AND data_type='SOURCE'"); pstmt.setString(1, fileUuid); rs = pstmt.executeQuery(); if (rs.next()) { diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/source/FileSourceMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/source/FileSourceMapper.java index 98de827933f..0da4f1980d9 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/source/FileSourceMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/source/FileSourceMapper.java @@ -27,7 +27,7 @@ import org.apache.ibatis.session.ResultHandler; public interface FileSourceMapper { - List<FileSourceDto> selectHashesForProject(@Param("projectUuid") String projectUuid); + List<FileSourceDto> selectHashesForProject(@Param("projectUuid") String projectUuid, @Param("dataType") String dataType); @CheckForNull FileSourceDto selectByFileUuid(@Param("fileUuid") String fileUuid); diff --git a/server/sonar-db-dao/src/main/protobuf/db-file-sources.proto b/server/sonar-db-dao/src/main/protobuf/db-file-sources.proto index 5c073555fe3..bad663a92d0 100644 --- a/server/sonar-db-dao/src/main/protobuf/db-file-sources.proto +++ b/server/sonar-db-dao/src/main/protobuf/db-file-sources.proto @@ -74,3 +74,24 @@ message Data { repeated Line lines = 1; } +message Test { + optional string uuid = 1; + optional string name = 2; + optional TestStatus status = 3; + optional int64 execution_time_ms = 4; + optional string stacktrace = 5; + optional string msg = 6; + repeated CoveredFile covered_file = 7; + + message CoveredFile { + optional string file_uuid = 1; + repeated int32 covered_line = 2 [packed = true]; + } + + enum TestStatus { + OK = 1; + FAILURE = 2; + ERROR = 3; + SKIPPED = 4; + } +} 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 fc0a1a5cf37..40ab818d93a 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 @@ -226,6 +226,7 @@ and p.scope='FIL' INNER JOIN file_sources fs ON fs.file_uuid=p.uuid + and fs.data_type='SOURCE' where root.uuid=#{projectUuid,jdbcType=VARCHAR} </select> @@ -240,6 +241,7 @@ FROM projects p INNER JOIN file_sources fs ON fs.file_uuid=p.uuid + and fs.data_type='SOURCE' <include refid="modulesTreeQuery"/> </select> @@ -588,6 +590,7 @@ from projects p inner join file_sources fs on fs.file_uuid = p.uuid + and fs.data_type = 'SOURCE' where p.project_uuid = #{projectUuid,jdbcType=VARCHAR} and p.enabled = ${_true} diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/source/FileSourceMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/source/FileSourceMapper.xml index 7e017a68b8f..b45f1f1f669 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/source/FileSourceMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/source/FileSourceMapper.xml @@ -22,6 +22,7 @@ file_sources where file_uuid = #{fileUuid,jdbcType=VARCHAR} + and data_type = 'SOURCE' </select> <select id="selectHashesForProject" parameterType="map" resultType="org.sonar.db.source.FileSourceDto"> @@ -32,10 +33,11 @@ src_hash as srcHash, revision, updated_at as updatedAt - from + from file_sources where project_uuid = #{projectUuid,jdbcType=VARCHAR} + and data_type = 'SOURCE' </select> <select id="scrollLineHashes" parameterType="map" resultType="org.sonar.db.source.LineHashesWithUuidDto" fetchSize="${_scrollFetchSize}" resultSetType="FORWARD_ONLY"> @@ -46,6 +48,7 @@ from projects p inner join file_sources fs on fs.file_uuid = p.uuid + and fs.data_type = 'SOURCE' where p.uuid in <foreach collection="fileUuids" item="fileUuid" open="(" close=")" separator=","> @@ -61,6 +64,7 @@ file_sources WHERE file_uuid = #{fileUuid,jdbcType=VARCHAR} + and data_type = 'SOURCE' </select> <insert id="insert" parameterType="org.sonar.db.source.FileSourceDto" useGeneratedKeys="false"> @@ -76,6 +80,7 @@ line_count, data_hash, src_hash, + data_type, revision ) values @@ -90,6 +95,7 @@ #{lineCount,jdbcType=INTEGER}, #{dataHash,jdbcType=VARCHAR}, #{srcHash,jdbcType=VARCHAR}, + 'SOURCE', #{revision,jdbcType=VARCHAR} ) </insert> diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/source/FileSourceDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/source/FileSourceDaoTest.java index d62bb2757c9..0524b9e7234 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/source/FileSourceDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/source/FileSourceDaoTest.java @@ -97,6 +97,16 @@ public class FileSourceDaoTest { } @Test + public void no_line_hashes_when_only_test_data() { + dbTester.prepareDbUnit(getClass(), "no_line_hashes_when_only_test_data.xml"); + + ReaderToStringConsumer fn = new ReaderToStringConsumer(); + underTest.readLineHashesStream(dbSession, "FILE1_UUID", fn); + + assertThat(fn.result).isNull(); + } + + @Test public void insert() { FileSourceDto expected = new FileSourceDto() .setProjectUuid("PRJ_UUID") diff --git a/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteProject.xml b/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteProject.xml index 11c383b63fd..f0e0ed49218 100644 --- a/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteProject.xml +++ b/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteProject.xml @@ -224,5 +224,6 @@ line_count="0" data_hash="321654987" created_at="123456789" - updated_at="123456789"/> + updated_at="123456789" + data_type="SOURCE"/> </dataset> diff --git a/server/sonar-db-dao/src/test/resources/org/sonar/db/source/FileSourceDaoTest/no_line_hashes_when_only_test_data.xml b/server/sonar-db-dao/src/test/resources/org/sonar/db/source/FileSourceDaoTest/no_line_hashes_when_only_test_data.xml new file mode 100644 index 00000000000..01bc65ac204 --- /dev/null +++ b/server/sonar-db-dao/src/test/resources/org/sonar/db/source/FileSourceDaoTest/no_line_hashes_when_only_test_data.xml @@ -0,0 +1,11 @@ +<dataset> + + <file_sources id="101" project_uuid="PRJ_UUID" file_uuid="FILE1_UUID" + binary_data="abcde" data_hash="[null]" + line_hashes="[null]" + line_count="0" + src_hash="[null]" + line_hashes_version="[null]" + created_at="1500000000000" updated_at="1500000000000" data_type="TEST" /> + +</dataset> diff --git a/server/sonar-db-dao/src/test/resources/org/sonar/db/source/FileSourceDaoTest/shared.xml b/server/sonar-db-dao/src/test/resources/org/sonar/db/source/FileSourceDaoTest/shared.xml index 53556dae846..77d242162c6 100644 --- a/server/sonar-db-dao/src/test/resources/org/sonar/db/source/FileSourceDaoTest/shared.xml +++ b/server/sonar-db-dao/src/test/resources/org/sonar/db/source/FileSourceDaoTest/shared.xml @@ -5,7 +5,7 @@ line_hashes="ABC\nDEF\nGHI" line_count="3" src_hash="FILE_HASH" revision="123456789" - created_at="1500000000000" updated_at="1500000000000" + created_at="1500000000000" updated_at="1500000000000" data_type="SOURCE" line_hashes_version="[null]"/> </dataset> diff --git a/server/sonar-db-dao/src/test/resources/org/sonar/db/source/FileSourceDaoTest/update-result.xml b/server/sonar-db-dao/src/test/resources/org/sonar/db/source/FileSourceDaoTest/update-result.xml index 139656474e2..e51106a4630 100644 --- a/server/sonar-db-dao/src/test/resources/org/sonar/db/source/FileSourceDaoTest/update-result.xml +++ b/server/sonar-db-dao/src/test/resources/org/sonar/db/source/FileSourceDaoTest/update-result.xml @@ -6,7 +6,7 @@ line_hashes="NEW_LINE_HASHES" line_count="1" src_hash="NEW_FILE_HASH" revision="987654321" - created_at="1500000000000" updated_at="1500000000002" + created_at="1500000000000" updated_at="1500000000002" data_type="SOURCE" line_hashes_version="1" /> diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/DdlChange.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/DdlChange.java index cdea9a7fd03..c4620a40d80 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/DdlChange.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/DdlChange.java @@ -24,7 +24,6 @@ import java.sql.SQLException; import java.sql.Statement; import java.util.List; import java.util.regex.Pattern; -import org.sonar.api.config.Configuration; import org.sonar.db.Database; import org.sonar.db.dialect.Dialect; @@ -55,10 +54,6 @@ public abstract class DdlChange implements MigrationStep { public abstract void execute(Context context) throws SQLException; - protected static boolean isSonarCloud(Configuration configuration) { - return configuration.getBoolean("sonar.sonarcloud.enabled").orElse(false); - } - protected Database getDatabase() { return db; } diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v77/DbVersion77.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v77/DbVersion77.java index c15e615b167..402538f10be 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v77/DbVersion77.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v77/DbVersion77.java @@ -30,7 +30,6 @@ public class DbVersion77 implements DbVersion { .add(2600, "Drop elasticsearch index 'tests'", DropElasticsearchIndexTests.class) .add(2601, "Delete lines with DATA_TYPE='TEST' from table FILES_SOURCE", DeleteTestDataTypeFromFileSources.class) .add(2602, "Add column LAST_CONNECTION_DATE to USERS table", AddLastConnectionDateToUsers.class) - .add(2603, "Add column LAST_USED_DATE to USER_TOKENS table", AddLastConnectionDateToUserTokens.class) - .add(2604, "Drop DATA_TYPE column from FILE_SOURCES table", DropDataTypeFromFileSources.class); + .add(2603, "Add column LAST_USED_DATE to USER_TOKENS table", AddLastConnectionDateToUserTokens.class); } } diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v77/DropDataTypeFromFileSources.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v77/DropDataTypeFromFileSources.java deleted file mode 100644 index 8e87f66b49f..00000000000 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v77/DropDataTypeFromFileSources.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * 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.v77; - -import java.sql.SQLException; -import org.sonar.db.Database; -import org.sonar.server.platform.db.migration.SupportsBlueGreen; -import org.sonar.server.platform.db.migration.sql.CreateIndexBuilder; -import org.sonar.server.platform.db.migration.sql.DropColumnsBuilder; -import org.sonar.server.platform.db.migration.sql.DropIndexBuilder; -import org.sonar.server.platform.db.migration.step.DdlChange; - -import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder; - -@SupportsBlueGreen -public class DropDataTypeFromFileSources extends DdlChange { - - private static final String TABLE_NAME = "file_sources"; - - public DropDataTypeFromFileSources(Database db) { - super(db); - } - - @Override - public void execute(Context context) throws SQLException { - context.execute(new DropIndexBuilder(getDialect()) - .setTable(TABLE_NAME) - .setName("file_sources_uuid_type") - .build()); - - context.execute(new DropColumnsBuilder(getDialect(), TABLE_NAME, "data_type") - .build()); - - context.execute(new CreateIndexBuilder(getDialect()) - .setTable(TABLE_NAME) - .setName("file_sources_file_uuid") - .setUnique(true) - .addColumn(newVarcharColumnDefBuilder() - .setColumnName("file_uuid") - .setIsNullable(false) - .setLimit(50) - .build()) - .build()); - } - -} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v77/DbVersion77Test.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v77/DbVersion77Test.java index cb1ac440b36..ffd24978cc8 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v77/DbVersion77Test.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v77/DbVersion77Test.java @@ -36,7 +36,7 @@ public class DbVersion77Test { @Test public void verify_migration_count() { - verifyMigrationCount(underTest, 5); + verifyMigrationCount(underTest, 4); } } diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v77/DropDataTypeFromFileSourcesTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v77/DropDataTypeFromFileSourcesTest.java deleted file mode 100644 index f69e374edd2..00000000000 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v77/DropDataTypeFromFileSourcesTest.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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.v77; - -import java.sql.SQLException; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.sonar.db.CoreDbTester; - -public class DropDataTypeFromFileSourcesTest { - - private static final String TABLE = "file_sources"; - - @Rule - public final CoreDbTester db = CoreDbTester.createForSchema(DropDataTypeFromFileSourcesTest.class, "file_sources.sql"); - @Rule - public ExpectedException expectedException = ExpectedException.none(); - - private DropDataTypeFromFileSources underTest = new DropDataTypeFromFileSources(db.database()); - - @Test - public void drop_column_and_recreate_index() throws SQLException { - underTest.execute(); - - db.assertColumnDoesNotExist(TABLE, "data_type"); - db.assertUniqueIndex(TABLE, "file_sources_file_uuid", "file_uuid"); - } - - @Test - public void migration_is_not_re_entrant() 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/v77/DropDataTypeFromFileSourcesTest/file_sources.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v77/DropDataTypeFromFileSourcesTest/file_sources.sql deleted file mode 100644 index 9a93cbcee9d..00000000000 --- a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v77/DropDataTypeFromFileSourcesTest/file_sources.sql +++ /dev/null @@ -1,18 +0,0 @@ -CREATE TABLE "FILE_SOURCES" ( - "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), - "PROJECT_UUID" VARCHAR(50) NOT NULL, - "FILE_UUID" VARCHAR(50) NOT NULL, - "LINE_HASHES" CLOB, - "LINE_HASHES_VERSION" INTEGER, - "LINE_COUNT" INTEGER NOT NULL, - "BINARY_DATA" BLOB, - "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 -); -CREATE INDEX "FILE_SOURCES_PROJECT_UUID" ON "FILE_SOURCES" ("PROJECT_UUID"); -CREATE UNIQUE INDEX "FILE_SOURCES_UUID_TYPE" ON "FILE_SOURCES" ("FILE_UUID", "DATA_TYPE"); -CREATE INDEX "FILE_SOURCES_UPDATED_AT" ON "FILE_SOURCES" ("UPDATED_AT");
\ No newline at end of file |