]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-10430 add FILE_SOURCES.LINE_COUNT
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Mon, 23 Apr 2018 14:25:45 +0000 (16:25 +0200)
committerSonarTech <sonartech@sonarsource.com>
Mon, 28 May 2018 18:20:44 +0000 (20:20 +0200)
17 files changed:
server/sonar-db-core/src/main/resources/org/sonar/db/version/schema-h2.ddl
server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/close_issues_clean_index_and_files_sources_of_specified_components.xml
server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteProject.xml
server/sonar-db-dao/src/test/resources/org/sonar/db/source/FileSourceDaoTest/no_line_hashes_when_only_test_data.xml
server/sonar-db-dao/src/test/resources/org/sonar/db/source/FileSourceDaoTest/shared.xml
server/sonar-db-dao/src/test/resources/org/sonar/db/source/FileSourceDaoTest/update-result.xml
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v72/AddFileSourceLineCount.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v72/DbVersion72.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v72/MakeFileSourceLineCountNotNullable.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v72/PopulateFileSourceLineCount.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v72/AddFileSourceLineCountTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v72/DbVersion72Test.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v72/MakeFileSourceLineCountNotNullableTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v72/PopulateFileSourceLineCountTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v72/AddFileSourceLineCountTest/file_sources.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v72/MakeFileSourceLineCountNotNullableTest/file_sources.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v72/PopulateFileSourceLineCountTest/file_sources.sql [new file with mode: 0644]

index 83a3091a455e671d502744c55ea1057649c7224a..d480b16e24abc99aa80b62e51b8b6ed17c16165b 100644 (file)
@@ -615,6 +615,7 @@ CREATE TABLE "FILE_SOURCES" (
   "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),
index 40c2ae8f4f7706422673322fa8b0dcf4081d38bf..d371b7cd9558664fc244a206a4664b47a70910ff 100644 (file)
                 file_uuid="GHIJ"
                 binary_data="[null]"
                 line_hashes="[null]"
+                line_count="0"
                 data_hash="321654987"
                 revision="123456789"
                 created_at="123456789"
                 file_uuid="KLMN"
                 binary_data="[null]"
                 line_hashes="[null]"
+                line_count="0"
                 data_hash="321654988"
                 revision="123456789"
                 created_at="123456789"
                 file_uuid="GHIJ"
                 binary_data="[null]"
                 line_hashes="[null]"
+                line_count="0"
                 data_hash="321654987"
                 revision="123456789"
                 created_at="123456789"
                 file_uuid="KLMN"
                 binary_data="[null]"
                 line_hashes="[null]"
+                line_count="0"
                 data_hash="321654988"
                 revision="123456789"
                 created_at="123456789"
index deb3b1511d65232543195ee8e9477fd36f75977f..f0e0ed492188db4e391706efd67627cf35cacd38 100644 (file)
                 file_uuid="D"
                 binary_data="[null]"
                 line_hashes="[null]"
+                line_count="0"
                 data_hash="321654987"
                 created_at="123456789"
                 updated_at="123456789"
index 481445affdc87ba69f8af3b9a57f5ce3c147dceb..01bc65ac204417a6c17a12d28c76b7457d05057e 100644 (file)
@@ -3,6 +3,7 @@
     <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" />
index a2d372095c0880f9ccdf74f29b3fa47c77972148..77d242162c6baea2f526907aeed849dac5857140 100644 (file)
@@ -3,6 +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"
+                  line_count="3"
                   src_hash="FILE_HASH" revision="123456789"
                   created_at="1500000000000" updated_at="1500000000000"  data_type="SOURCE"
                   line_hashes_version="[null]"/>
index f57da523a84049ec0e41c59ddafbd5572c425f5d..e51106a4630283060f8ed4693f3045575d83228e 100644 (file)
@@ -4,6 +4,7 @@
                 binary_data="[ignore]"
                 data_hash="NEW_DATA_HASH"
                 line_hashes="NEW_LINE_HASHES"
+                line_count="1"
                 src_hash="NEW_FILE_HASH" revision="987654321"
                 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/version/v72/AddFileSourceLineCount.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v72/AddFileSourceLineCount.java
new file mode 100644 (file)
index 0000000..643339a
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2018 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.v72;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.def.IntegerColumnDef;
+import org.sonar.server.platform.db.migration.sql.AddColumnsBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+public class AddFileSourceLineCount extends DdlChange {
+  public AddFileSourceLineCount(Database db) {
+    super(db);
+  }
+
+  @Override
+  public void execute(Context context) throws SQLException {
+    context.execute(new AddColumnsBuilder(getDialect(), "file_sources")
+      .addColumn(IntegerColumnDef.newIntegerColumnDefBuilder()
+        .setColumnName("line_count")
+        .setIsNullable(true)
+        .build())
+      .build());
+  }
+}
index d072d97038643b9370fe154da043dd81c323a327..243ec08c19fad86313b888d5cfa2a87c54f1f3c6 100644 (file)
@@ -51,6 +51,9 @@ public class DbVersion72 implements DbVersion {
       .add(2121, "Rename NOTE_USER_LOGIN TO NOTE_USER_UUID on table RULES_METADATA", RenameNoteUserLoginToNoteUserUuidOnTableRulesMetadata.class)
       .add(2122, "Rename SUBMITTER_LOGIN TO SUBMITTER_UUID on table CE_QUEUE", RenameSubmitterLoginToSubmitterUuidOnTableCeQueue.class)
       .add(2123, "Rename SUBMITTER_LOGIN TO SUBMITTER_UUID on table CE_ACTIVITY", RenameSubmitterLoginToSubmitterUuidOnTableCeActivity.class)
+      .add(2124, "Add FILE_SOURCE.LINE_COUNT", AddFileSourceLineCount.class)
+      .add(2125, "Populate FILE_SOURCE.LINE_COUNT", PopulateFileSourceLineCount.class)
+      .add(2126, "Make FILE_SOURCE.LINE_COUNT not nullable", MakeFileSourceLineCountNotNullable.class)
     ;
   }
 }
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v72/MakeFileSourceLineCountNotNullable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v72/MakeFileSourceLineCountNotNullable.java
new file mode 100644 (file)
index 0000000..3b196d7
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2018 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.v72;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+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.IntegerColumnDef.newIntegerColumnDefBuilder;
+
+public class MakeFileSourceLineCountNotNullable extends DdlChange {
+  public MakeFileSourceLineCountNotNullable(Database db) {
+    super(db);
+  }
+
+  @Override
+  public void execute(Context context) throws SQLException {
+    context.execute(new AlterColumnsBuilder(getDialect(), "file_sources")
+      .updateColumn(newIntegerColumnDefBuilder()
+        .setColumnName("line_count")
+        .setIsNullable(false)
+        .build())
+      .build());
+  }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v72/PopulateFileSourceLineCount.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v72/PopulateFileSourceLineCount.java
new file mode 100644 (file)
index 0000000..756f4d9
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2018 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.v72;
+
+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;
+import org.sonar.server.platform.db.migration.step.Select;
+import org.sonar.server.platform.db.migration.step.SqlStatement;
+
+/**
+ * New column is populated with value {@code -1} rather than with the number of lines computed from the value of column
+ * {@code line_hashes} (which would be the correct value for this column).
+ * <p>
+ * Column will be populated with the correct value by the new "DB migration step" of the analysis report processing the
+ * first time a project is analyzed after SonarQube's upgrade.
+ * <p>
+ * This innovative approach to DB migration is used because populating the column from {@code line_hashes} will take
+ * a very long time on large DBs.
+ */
+public class PopulateFileSourceLineCount extends DataChange {
+  private static final int LINE_COUNT_NOT_POPULATED = -1;
+
+  public PopulateFileSourceLineCount(Database db) {
+    super(db);
+  }
+
+  @Override
+  protected void execute(Context context) throws SQLException {
+    MassUpdate massUpdate = context.prepareMassUpdate();
+    massUpdate.select("select distinct project_uuid from file_sources where line_count is null");
+    massUpdate.update("update file_sources set line_count = ? where project_uuid = ?");
+    massUpdate.rowPluralName("file source line counts");
+    massUpdate.execute(PopulateFileSourceLineCount::handle);
+  }
+
+  private static boolean handle(Select.Row row, SqlStatement update) throws SQLException {
+    String projectUuid = row.getString(1);
+
+    update.setInt(1, LINE_COUNT_NOT_POPULATED);
+    update.setString(2, projectUuid);
+    return true;
+  }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v72/AddFileSourceLineCountTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v72/AddFileSourceLineCountTest.java
new file mode 100644 (file)
index 0000000..a65dafd
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2018 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.v72;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.sonar.db.CoreDbTester;
+
+import static java.sql.Types.INTEGER;
+
+public class AddFileSourceLineCountTest {
+  private static final String TABLE_NAME = "file_sources";
+
+  @Rule
+  public CoreDbTester dbTester = CoreDbTester.createForSchema(AddFileSourceLineCountTest.class, "file_sources.sql");
+  @Rule
+  public ExpectedException expectedException = ExpectedException.none();
+
+  private AddFileSourceLineCount underTest = new AddFileSourceLineCount(dbTester.database());
+
+  @Test
+  public void column_is_added_to_table() throws SQLException {
+    underTest.execute();
+
+    dbTester.assertColumnDefinition(TABLE_NAME, "line_count", INTEGER, null, true);
+  }
+
+  @Test
+  public void migration_is_not_reentrant() throws SQLException {
+    underTest.execute();
+
+    expectedException.expect(IllegalStateException.class);
+
+    underTest.execute();
+  }
+}
index 3109b8f8735a33a610d925528955b75f0c86071a..bd24b8f02ecff4f1a385c80df7d79fc4f54f68df 100644 (file)
@@ -34,7 +34,7 @@ public class DbVersion72Test {
 
   @Test
   public void verify_migration_count() {
-    verifyMigrationCount(underTest, 24);
+    verifyMigrationCount(underTest, 27);
   }
 
 }
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v72/MakeFileSourceLineCountNotNullableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v72/MakeFileSourceLineCountNotNullableTest.java
new file mode 100644 (file)
index 0000000..1564b8d
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2018 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.v72;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.sonar.db.CoreDbTester;
+
+import static java.sql.Types.INTEGER;
+
+public class MakeFileSourceLineCountNotNullableTest {
+  private static final String TABLE_NAME = "file_sources";
+
+  @Rule
+  public CoreDbTester dbTester = CoreDbTester.createForSchema(MakeFileSourceLineCountNotNullableTest.class, "file_sources.sql");
+  @Rule
+  public ExpectedException expectedException = ExpectedException.none();
+
+  private MakeFileSourceLineCountNotNullable underTest = new MakeFileSourceLineCountNotNullable(dbTester.database());
+
+  @Test
+  public void column_is_made_not_nullable() throws SQLException {
+    underTest.execute();
+
+    dbTester.assertColumnDefinition(TABLE_NAME, "line_count", INTEGER, null, false);
+  }
+
+  @Test
+  public void migration_does_not_fix_null_values_in_line_count() throws SQLException {
+    dbTester.executeInsert(
+      TABLE_NAME,
+      "PROJECT_UUID", "foo_prj",
+      "FILE_UUID", "foo_file",
+      "CREATED_AT", 123456,
+      "UPDATED_AT", 987654
+    );
+
+    expectedException.expect(IllegalStateException.class);
+
+    underTest.execute();
+  }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v72/PopulateFileSourceLineCountTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v72/PopulateFileSourceLineCountTest.java
new file mode 100644 (file)
index 0000000..e270613
--- /dev/null
@@ -0,0 +1,89 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2018 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.v72;
+
+import java.sql.SQLException;
+import java.util.Random;
+import java.util.stream.IntStream;
+import javax.annotation.Nullable;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.sonar.db.CoreDbTester;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class PopulateFileSourceLineCountTest {
+  private static final String TABLE_NAME = "file_sources";
+
+  @Rule
+  public CoreDbTester dbTester = CoreDbTester.createForSchema(PopulateFileSourceLineCountTest.class, "file_sources.sql");
+  @Rule
+  public ExpectedException expectedException = ExpectedException.none();
+
+  private PopulateFileSourceLineCount underTest = new PopulateFileSourceLineCount(dbTester.database());
+
+  @Test
+  public void execute_does_not_fail_on_empty_table() throws SQLException {
+    underTest.execute();
+  }
+
+  @Test
+  public void execute_set_value_to_minus_1_when_line_count_is_null() throws SQLException {
+    IntStream.range(0, 5 + new Random().nextInt(10)).forEach(i -> insert("prj_" + i, "file_" + i));
+
+    underTest.execute();
+
+    assertThat(dbTester.select("select distinct line_count as \"count\" from " + TABLE_NAME))
+      .extracting(t -> t.get("count"))
+      .containsOnly(-1L);
+  }
+
+  @Test
+  public void execute_keeps_value_when_line_count_is_not_null() throws SQLException {
+    insert("prj_A", "file_1", 12);
+    insert("prj_A", "file_2", 0);
+    insert("prj_B", "file_3", -5);
+    insert("prj_B", "file_4", -5);
+    insert("prj_C", "file_5", null);
+    insert("prj_D", "file_6", null);
+    insert("prj_D", "file_7", 12);
+
+    underTest.execute();
+
+    assertThat(dbTester.select("select line_count as \"count\" from " + TABLE_NAME))
+      .extracting(t -> t.get("count"))
+      .containsOnly(-1L, 12L, 12L, 0L, -5L, -5L);
+  }
+
+  public void insert(String projectUuid, String fileUuid) {
+    insert(projectUuid, fileUuid, null);
+  }
+
+  public void insert(String projectUuid, String fileUuid, @Nullable Integer lineCount) {
+    dbTester.executeInsert(
+      TABLE_NAME,
+      "PROJECT_UUID", projectUuid,
+      "FILE_UUID", fileUuid,
+      "LINE_COUNT", lineCount,
+      "CREATED_AT", 123456,
+      "UPDATED_AT", 987654);
+  }
+}
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v72/AddFileSourceLineCountTest/file_sources.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v72/AddFileSourceLineCountTest/file_sources.sql
new file mode 100644 (file)
index 0000000..4df5eff
--- /dev/null
@@ -0,0 +1,16 @@
+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,
+  "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");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v72/MakeFileSourceLineCountNotNullableTest/file_sources.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v72/MakeFileSourceLineCountNotNullableTest/file_sources.sql
new file mode 100644 (file)
index 0000000..ac8ae8e
--- /dev/null
@@ -0,0 +1,17 @@
+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_COUNT" INTEGER,
+  "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");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v72/PopulateFileSourceLineCountTest/file_sources.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v72/PopulateFileSourceLineCountTest/file_sources.sql
new file mode 100644 (file)
index 0000000..ac8ae8e
--- /dev/null
@@ -0,0 +1,17 @@
+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_COUNT" INTEGER,
+  "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");