]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-10116 disable clean-up migration on SonarCloud
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Wed, 6 Dec 2017 13:22:26 +0000 (14:22 +0100)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Fri, 8 Dec 2017 08:22:14 +0000 (09:22 +0100)
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v70/DeletePersonAndFileMeasures.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v70/DeletePersonAndFileMeasuresTest.java

index 92ba449f7cd29095752edded0fba8ebda182bb74..69ee2bb488186a3274f22963fa663e4d2b815fcb 100644 (file)
@@ -20,6 +20,7 @@
 package org.sonar.server.platform.db.migration.version.v70;
 
 import java.sql.SQLException;
+import org.sonar.api.config.Configuration;
 import org.sonar.db.Database;
 import org.sonar.db.dialect.H2;
 import org.sonar.db.dialect.MsSql;
@@ -30,12 +31,21 @@ import org.sonar.server.platform.db.migration.step.DataChange;
 import org.sonar.server.platform.db.migration.step.MassUpdate;
 
 public class DeletePersonAndFileMeasures extends DataChange {
-  public DeletePersonAndFileMeasures(Database db) {
+
+  private final Configuration configuration;
+
+  public DeletePersonAndFileMeasures(Database db, Configuration configuration) {
     super(db);
+    this.configuration = configuration;
   }
 
   @Override
   protected void execute(Context context) throws SQLException {
+    if (configuration.getBoolean("sonar.sonarcloud.enabled").orElse(false)) {
+      // clean-up will be done in background so that interruption of service
+      // is reduced during upgrade
+      return;
+    }
     MassUpdate massUpdate = context.prepareMassUpdate();
     massUpdate.select("select uuid from snapshots");
     massUpdate.rowPluralName("snapshots");
index 2019003f8e0682fc3d1511f7789e545f94f08507..0908bd3aa243e9d822b785bd9dee606cef22b4e5 100644 (file)
@@ -24,6 +24,7 @@ import java.util.concurrent.atomic.AtomicInteger;
 import org.apache.commons.lang.math.RandomUtils;
 import org.junit.Rule;
 import org.junit.Test;
+import org.sonar.api.config.internal.MapSettings;
 import org.sonar.db.CoreDbTester;
 import org.sonar.server.platform.db.migration.step.DataChange;
 
@@ -34,8 +35,6 @@ public class DeletePersonAndFileMeasuresTest {
   @Rule
   public CoreDbTester db = CoreDbTester.createForSchema(DeletePersonAndFileMeasuresTest.class, "initial.sql");
 
-  private DataChange underTest = new DeletePersonAndFileMeasures(db.database());
-
   @Test
   public void delete_file_and_person_measures() throws SQLException {
     insertComponent("P1", "PRJ", "TRK");
@@ -59,19 +58,42 @@ public class DeletePersonAndFileMeasuresTest {
     long m11 = insertPersonMeasure("P1", "S2");
     long m12 = insertPersonMeasure("F1", "S2");
 
-    underTest.execute();
+    run(false);
 
     assertThat(db.countRowsOfTable("PROJECTS")).isEqualTo(4);
     assertThat(db.countRowsOfTable("SNAPSHOTS")).isEqualTo(2);
     assertThatMeasuresAreExactly(m1, m2, m7, m8);
 
     // migration is re-entrant
-    underTest.execute();
+    run(false);
     assertThat(db.countRowsOfTable("PROJECTS")).isEqualTo(4);
     assertThat(db.countRowsOfTable("SNAPSHOTS")).isEqualTo(2);
     assertThatMeasuresAreExactly(m1, m2, m7, m8);
   }
 
+  @Test
+  public void migration_is_disabled_on_sonarcloud() throws SQLException {
+    insertComponent("F1", "FIL", "FIL");
+    insertSnapshot("S1", "P1", false);
+    insertMeasure("F1", "S1");
+    insertPersonMeasure("F1", "S1");
+
+    run(true);
+
+    assertThat(db.countRowsOfTable("PROJECTS")).isEqualTo(1);
+    assertThat(db.countRowsOfTable("SNAPSHOTS")).isEqualTo(1);
+    assertThat(db.countRowsOfTable("PROJECT_MEASURES")).isEqualTo(2);
+  }
+
+  private void run(boolean sonarCloud) throws SQLException {
+    MapSettings settings = new MapSettings();
+    if (sonarCloud) {
+      settings.setProperty("sonar.sonarcloud.enabled", true);
+    }
+    DataChange underTest = new DeletePersonAndFileMeasures(db.database(), settings.asConfig());
+    underTest.execute();
+  }
+
   private void assertThatMeasuresAreExactly(long... expectedMeasureIds) {
     long[] ids = db.select("select id as \"id\" from project_measures")
       .stream()