]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-14792 Add 9.0 nop migration to not enforce DB downgrade
authorJacek <jacek.poreda@sonarsource.com>
Wed, 16 Jun 2021 14:29:18 +0000 (16:29 +0200)
committersonartech <sonartech@sonarsource.com>
Wed, 16 Jun 2021 20:03:05 +0000 (20:03 +0000)
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/MigrationConfigurationModule.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/DatabaseVersion.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v90/DbVersion90.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v90/InitialMigration.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v90/package-info.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v90/DbVersion90Test.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v90/InitialMigrationTest.java [new file with mode: 0644]

index d2d6988d15ca9bed78e4831e36a09a7746504cf3..effbfc73be93a35f4ba8922e8cdcf8ad2d955062 100644 (file)
@@ -27,6 +27,7 @@ import org.sonar.server.platform.db.migration.sql.DropPrimaryKeySqlGenerator;
 import org.sonar.server.platform.db.migration.step.MigrationStepRegistryImpl;
 import org.sonar.server.platform.db.migration.step.MigrationStepsProvider;
 import org.sonar.server.platform.db.migration.version.v00.DbVersion00;
+import org.sonar.server.platform.db.migration.version.v90.DbVersion90;
 
 public class MigrationConfigurationModule extends Module {
   @Override
@@ -34,6 +35,7 @@ public class MigrationConfigurationModule extends Module {
     add(
       // DbVersion implementations
       DbVersion00.class,
+      DbVersion90.class,
 
       // migration steps
       MigrationStepRegistryImpl.class,
index 529b9a378b94cae757cf178392a9dac851aacef3..c0db1d8c24ecde9a29a0d7ace8c05fb7ac7292d1 100644 (file)
@@ -30,7 +30,7 @@ public class DatabaseVersion {
    * versions must be previously upgraded to LTS version.
    * Note that the value can't be less than current LTS version.
    */
-  public static final long MIN_UPGRADE_VERSION = 4_400;
+  public static final long MIN_UPGRADE_VERSION = 4_405;
 
   private final MigrationSteps migrationSteps;
   private final MigrationHistory migrationHistory;
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v90/DbVersion90.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v90/DbVersion90.java
new file mode 100644 (file)
index 0000000..6521c15
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2021 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.v90;
+
+import org.sonar.server.platform.db.migration.step.MigrationStepRegistry;
+import org.sonar.server.platform.db.migration.version.DbVersion;
+
+public class DbVersion90 implements DbVersion {
+  @Override
+  public void addSteps(MigrationStepRegistry registry) {
+    registry
+      .add(5000, "Initial migration", InitialMigration.class);
+  }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v90/InitialMigration.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v90/InitialMigration.java
new file mode 100644 (file)
index 0000000..dedfd09
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2021 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.v90;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.step.DataChange;
+
+/**
+ * Just a nop migration to put new migrations numbering in place,
+ * and let current DB version algorithm to not determine 9.0 as required to be downgraded
+ */
+public class InitialMigration extends DataChange {
+
+  public InitialMigration(Database db) {
+    super(db);
+  }
+
+  @Override
+  protected void execute(Context context) throws SQLException {
+    // nothing to do
+  }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v90/package-info.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v90/package-info.java
new file mode 100644 (file)
index 0000000..4b73f8d
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2021 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.
+ */
+@ParametersAreNonnullByDefault
+package org.sonar.server.platform.db.migration.version.v90;
+
+import javax.annotation.ParametersAreNonnullByDefault;
+
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v90/DbVersion90Test.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v90/DbVersion90Test.java
new file mode 100644 (file)
index 0000000..0746d99
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2021 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.v90;
+
+import org.junit.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.sonar.server.platform.db.migration.version.DbVersionTestUtils.verifyMigrationCount;
+import static org.sonar.server.platform.db.migration.version.DbVersionTestUtils.verifyMinimumMigrationNumber;
+
+public class DbVersion90Test {
+
+  private DbVersion90 underTest = new DbVersion90();
+
+  @Test
+  public void verify_no_support_component() {
+    assertThat(underTest.getSupportComponents()).isEmpty();
+  }
+
+  @Test
+  public void migrationNumber_starts_at_5000() {
+    verifyMinimumMigrationNumber(underTest, 5000);
+  }
+
+  @Test
+  public void verify_migration_count() {
+    verifyMigrationCount(underTest, 1);
+  }
+
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v90/InitialMigrationTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v90/InitialMigrationTest.java
new file mode 100644 (file)
index 0000000..b9777f6
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2021 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.v90;
+
+import java.sql.SQLException;
+import org.junit.Test;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.step.DataChange.Context;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verifyNoInteractions;
+
+public class InitialMigrationTest {
+
+  private final InitialMigration underTest = new InitialMigration(mock(Database.class));
+
+  @Test
+  public void migration_should_do_nothing() throws SQLException {
+    Context mockContext = mock(Context.class);
+    underTest.execute(mockContext);
+
+    verifyNoInteractions(mockContext);
+  }
+}