]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9136 do no delete default group of default organization
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Mon, 24 Apr 2017 14:26:46 +0000 (16:26 +0200)
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Thu, 27 Apr 2017 12:42:50 +0000 (14:42 +0200)
server/sonar-server/src/main/java/org/sonar/server/platform/BackendCleanup.java

index 74ddce5df938d914863a3809492479bf8c35982e..4ef857a3176a5e8d79872e46b5346c1218449fc2 100644 (file)
@@ -56,6 +56,7 @@ public class BackendCleanup {
   private static final Map<String, TableCleaner> TABLE_CLEANERS = ImmutableMap.of(
     "organizations", BackendCleanup::truncateOrganizations,
     "users", BackendCleanup::truncateUsers,
+    "groups", BackendCleanup::truncateGroups,
     "internal_properties", BackendCleanup::truncateInternalProperties,
     "schema_migrations", BackendCleanup::truncateSchemaMigrations);
 
@@ -196,6 +197,18 @@ public class BackendCleanup {
     }
   }
 
+  /**
+   * Groups sonar-users is referenced by the default organization as its default group.
+   */
+  private static void truncateGroups(String tableName, Statement ddlStatement, Connection connection) throws SQLException {
+    try (PreparedStatement preparedStatement = connection.prepareStatement("delete from groups where name <> ?")) {
+      preparedStatement.setString(1, "sonar-users");
+      preparedStatement.execute();
+      // commit is useless on some databases
+      connection.commit();
+    }
+  }
+
   /**
    * Internal property {@link InternalProperties#DEFAULT_ORGANIZATION} must never be deleted.
    */