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);
}
}
+ /**
+ * 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.
*/