Skip to content

Commit 3de0267

Browse files
SLCORE-1802 Migrate protobuf-based storage to the new database
1 parent 109ad93 commit 3de0267

File tree

100 files changed

+4315
-1037
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+4315
-1037
lines changed

backend/commons/src/main/java/org/sonarsource/sonarlint/core/commons/storage/SonarLintDatabase.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,16 @@
3232
import org.jooq.impl.DSL;
3333
import org.sonarsource.sonarlint.core.commons.log.SonarLintLogger;
3434

35+
import static org.sonarsource.sonarlint.core.commons.storage.model.Tables.ACTIVE_RULESETS;
3536
import static org.sonarsource.sonarlint.core.commons.storage.model.Tables.AI_CODEFIX_SETTINGS;
37+
import static org.sonarsource.sonarlint.core.commons.storage.model.Tables.NEW_CODE_DEFINITIONS;
38+
import static org.sonarsource.sonarlint.core.commons.storage.model.Tables.ORGANIZATIONS;
39+
import static org.sonarsource.sonarlint.core.commons.storage.model.Tables.PLUGINS;
40+
import static org.sonarsource.sonarlint.core.commons.storage.model.Tables.PROJECTS;
41+
import static org.sonarsource.sonarlint.core.commons.storage.model.Tables.PROJECT_BRANCHES;
42+
import static org.sonarsource.sonarlint.core.commons.storage.model.Tables.SERVERS;
43+
import static org.sonarsource.sonarlint.core.commons.storage.model.Tables.SERVER_FEATURES;
44+
import static org.sonarsource.sonarlint.core.commons.storage.model.Tables.USERS;
3645

3746
public final class SonarLintDatabase {
3847
private static final SonarLintLogger LOG = SonarLintLogger.get();
@@ -109,6 +118,33 @@ public void cleanupNonExistingConnections(Set<String> existingConnectionIds) {
109118
dsl.deleteFrom(AI_CODEFIX_SETTINGS)
110119
.where(AI_CODEFIX_SETTINGS.CONNECTION_ID.notIn(existingConnectionIds))
111120
.execute();
121+
dsl.deleteFrom(ACTIVE_RULESETS)
122+
.where(ACTIVE_RULESETS.CONNECTION_ID.notIn(existingConnectionIds))
123+
.execute();
124+
dsl.deleteFrom(PROJECTS)
125+
.where(PROJECTS.CONNECTION_ID.notIn(existingConnectionIds))
126+
.execute();
127+
dsl.deleteFrom(SERVERS)
128+
.where(SERVERS.CONNECTION_ID.notIn(existingConnectionIds))
129+
.execute();
130+
dsl.deleteFrom(PROJECT_BRANCHES)
131+
.where(PROJECT_BRANCHES.CONNECTION_ID.notIn(existingConnectionIds))
132+
.execute();
133+
dsl.deleteFrom(PLUGINS)
134+
.where(PLUGINS.CONNECTION_ID.notIn(existingConnectionIds))
135+
.execute();
136+
dsl.deleteFrom(SERVER_FEATURES)
137+
.where(SERVER_FEATURES.CONNECTION_ID.notIn(existingConnectionIds))
138+
.execute();
139+
dsl.deleteFrom(ORGANIZATIONS)
140+
.where(ORGANIZATIONS.CONNECTION_ID.notIn(existingConnectionIds))
141+
.execute();
142+
dsl.deleteFrom(USERS)
143+
.where(USERS.CONNECTION_ID.notIn(existingConnectionIds))
144+
.execute();
145+
dsl.deleteFrom(NEW_CODE_DEFINITIONS)
146+
.where(NEW_CODE_DEFINITIONS.CONNECTION_ID.notIn(existingConnectionIds))
147+
.execute();
112148
}
113149
}
114150

backend/commons/src/main/java/org/sonarsource/sonarlint/core/commons/storage/repository/AiCodeFixRepository.java

Lines changed: 0 additions & 89 deletions
This file was deleted.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* SonarLint Core - Commons
3+
* Copyright (C) 2016-2025 SonarSource SA
4+
* mailto:info AT sonarsource DOT com
5+
*
6+
* This program is free software; you can redistribute it and/or
7+
* modify it under the terms of the GNU Lesser General Public
8+
* License as published by the Free Software Foundation; either
9+
* version 3 of the License, or (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
* Lesser General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Lesser General Public License
17+
* along with this program; if not, write to the Free Software Foundation,
18+
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19+
*/
20+
@ParametersAreNonnullByDefault
21+
package org.sonarsource.sonarlint.core.commons.storage.repository;
22+
23+
import javax.annotation.ParametersAreNonnullByDefault;
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
-- Flyway migration: create server storage tables for H2
2+
-- These tables migrate protobuf-based storage to H2 database
3+
-- Used only in dogfood environment
4+
5+
CREATE TABLE IF NOT EXISTS PROJECTS (
6+
connection_id VARCHAR(255) NOT NULL,
7+
project_key VARCHAR(255) NOT NULL,
8+
last_smart_notification_poll_date TIMESTAMP,
9+
CONSTRAINT pk_projects PRIMARY KEY (connection_id, project_key)
10+
);
11+
12+
CREATE TABLE IF NOT EXISTS ACTIVE_RULESETS (
13+
connection_id VARCHAR(255) NOT NULL,
14+
project_key VARCHAR(255) NOT NULL,
15+
language_key VARCHAR(50) NOT NULL,
16+
last_modified TIMESTAMP NOT NULL,
17+
rules JSON NOT NULL,
18+
CONSTRAINT pk_active_rulesets PRIMARY KEY (connection_id, project_key, language_key)
19+
);
20+
21+
CREATE TABLE IF NOT EXISTS PROJECT_BRANCHES (
22+
connection_id VARCHAR(255) NOT NULL,
23+
project_key VARCHAR(255) NOT NULL,
24+
name VARCHAR(255) NOT NULL,
25+
is_default BOOLEAN NOT NULL,
26+
CONSTRAINT pk_project_branches PRIMARY KEY (connection_id, project_key, name)
27+
);
28+
29+
CREATE TABLE IF NOT EXISTS PLUGINS (
30+
connection_id VARCHAR(255) NOT NULL,
31+
"key" VARCHAR(255) NOT NULL,
32+
hash VARCHAR(255) NOT NULL,
33+
filename VARCHAR(255) NOT NULL,
34+
CONSTRAINT pk_plugins PRIMARY KEY (connection_id, "key")
35+
);
36+
37+
CREATE TABLE IF NOT EXISTS SERVERS (
38+
connection_id VARCHAR(255) NOT NULL PRIMARY KEY,
39+
version VARCHAR(50),
40+
id VARCHAR(255),
41+
global_settings JSON NOT NULL
42+
);
43+
44+
CREATE TABLE IF NOT EXISTS SERVER_FEATURES (
45+
connection_id VARCHAR(255) NOT NULL PRIMARY KEY,
46+
features VARCHAR(200) ARRAY NOT NULL
47+
);
48+
49+
CREATE TABLE IF NOT EXISTS ORGANIZATIONS (
50+
connection_id VARCHAR(255) NOT NULL PRIMARY KEY,
51+
id VARCHAR(255) NOT NULL,
52+
uuidv4 VARCHAR(36) NOT NULL
53+
);
54+
55+
CREATE TABLE IF NOT EXISTS "USERS" (
56+
connection_id VARCHAR(255) NOT NULL PRIMARY KEY,
57+
id VARCHAR(255) NOT NULL
58+
);
59+
60+
CREATE TABLE IF NOT EXISTS NEW_CODE_DEFINITIONS (
61+
connection_id VARCHAR(255) NOT NULL,
62+
project_key VARCHAR(255) NOT NULL,
63+
mode VARCHAR(50) NOT NULL,
64+
days INT,
65+
threshold_date DATE,
66+
version VARCHAR(50),
67+
reference_branch VARCHAR(255),
68+
CONSTRAINT pk_new_code_definitions PRIMARY KEY (connection_id, project_key)
69+
);
70+

backend/commons/src/test/java/org/sonarsource/sonarlint/core/commons/storage/repository/AiCodeFixRepositoryTest.java

Lines changed: 0 additions & 85 deletions
This file was deleted.

backend/core/src/main/java/org/sonarsource/sonarlint/core/active/rules/ActiveRulesService.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,9 @@
6565
import org.sonarsource.sonarlint.core.serverapi.rules.ServerRule;
6666
import org.sonarsource.sonarlint.core.serverconnection.AnalyzerConfiguration;
6767
import org.sonarsource.sonarlint.core.serverconnection.RuleSet;
68+
import org.sonarsource.sonarlint.core.serverconnection.repository.AnalyzerConfigurationRepository;
69+
import org.sonarsource.sonarlint.core.serverconnection.repository.ServerInfoRepository;
6870
import org.sonarsource.sonarlint.core.serverconnection.storage.StorageException;
69-
import org.sonarsource.sonarlint.core.storage.StorageService;
7071
import org.sonarsource.sonarlint.core.sync.AnalyzerConfigurationSynchronized;
7172
import org.springframework.context.ApplicationEventPublisher;
7273
import org.springframework.context.event.EventListener;
@@ -88,7 +89,8 @@ public class ActiveRulesService {
8889
private final LanguageSupportRepository languageSupportRepository;
8990
private final SonarQubeClientManager sonarQubeClientManager;
9091
private final SeverityModeService severityModeService;
91-
private final StorageService storageService;
92+
private final AnalyzerConfigurationRepository analyzerConfigurationRepository;
93+
private final ServerInfoRepository serverInfoRepository;
9294
private final RulesRepository rulesRepository;
9395
private final ConnectionConfigurationRepository connectionConfigurationRepository;
9496
private final boolean hotspotEnabled;
@@ -99,13 +101,14 @@ public class ActiveRulesService {
99101
private final Map<Binding, List<ActiveRuleDetails>> activeRulesPerBinding = new ConcurrentHashMap<>();
100102

101103
public ActiveRulesService(ConfigurationRepository configurationRepository, LanguageSupportRepository languageSupportRepository, SonarQubeClientManager sonarQubeClientManager,
102-
SeverityModeService severityModeService, StorageService storageService, RulesRepository rulesRepository, ConnectionConfigurationRepository connectionConfigurationRepository,
104+
SeverityModeService severityModeService, AnalyzerConfigurationRepository analyzerConfigurationRepository, ServerInfoRepository serverInfoRepository, RulesRepository rulesRepository, ConnectionConfigurationRepository connectionConfigurationRepository,
103105
InitializeParams initializeParams, ApplicationEventPublisher eventPublisher) {
104106
this.configurationRepository = configurationRepository;
105107
this.languageSupportRepository = languageSupportRepository;
106108
this.sonarQubeClientManager = sonarQubeClientManager;
107109
this.severityModeService = severityModeService;
108-
this.storageService = storageService;
110+
this.analyzerConfigurationRepository = analyzerConfigurationRepository;
111+
this.serverInfoRepository = serverInfoRepository;
109112
this.rulesRepository = rulesRepository;
110113
this.connectionConfigurationRepository = connectionConfigurationRepository;
111114
this.hotspotEnabled = initializeParams.getBackendCapabilities().contains(SECURITY_HOTSPOTS);
@@ -184,7 +187,7 @@ public List<ActiveRuleDetails> getConnectedActiveRules(Binding binding) {
184187
}
185188

186189
private List<ActiveRuleDetails> buildConnectedActiveRules(Binding binding) {
187-
var analyzerConfig = storageService.binding(binding).analyzerConfiguration().read();
190+
var analyzerConfig = analyzerConfigurationRepository.read(binding.connectionId(), binding.sonarProjectKey());
188191
var ruleSetByLanguageKey = analyzerConfig.getRuleSetByLanguageKey();
189192
var result = new ArrayList<ActiveRuleDetails>();
190193
ruleSetByLanguageKey.entrySet()
@@ -264,7 +267,7 @@ private boolean isHotspotTrackingPossible(String connectionId) {
264267
return false;
265268
}
266269
// when storage is not present, consider hotspots should not be detected
267-
return storageService.connection(connectionId).serverInfo().read().isPresent();
270+
return serverInfoRepository.read(connectionId).isPresent();
268271
}
269272

270273
private static Predicate<? super SonarLintRuleDefinition> isExcludedByConfiguration(Set<String> excludedRules) {
@@ -341,7 +344,7 @@ public void onServerEventReceived(SonarServerEventReceivedEvent eventReceived) {
341344
}
342345

343346
private void updateStorage(String connectionId, RuleSetChangedEvent event) {
344-
event.getProjectKeys().forEach(projectKey -> storageService.connection(connectionId).project(projectKey).analyzerConfiguration().update(currentConfiguration -> {
347+
event.getProjectKeys().forEach(projectKey -> analyzerConfigurationRepository.update(connectionId, projectKey, currentConfiguration -> {
345348
var newRuleSetByLanguageKey = incorporate(event, currentConfiguration.getRuleSetByLanguageKey());
346349
return new AnalyzerConfiguration(currentConfiguration.getSettings(), newRuleSetByLanguageKey, currentConfiguration.getSchemaVersion());
347350
}));
@@ -421,7 +424,7 @@ private RuleDetails getActiveRuleForBinding(String ruleKey, Binding binding, Son
421424
private Optional<ServerActiveRule> findServerActiveRuleInStorage(Binding binding, String ruleKey) {
422425
AnalyzerConfiguration analyzerConfiguration;
423426
try {
424-
analyzerConfiguration = storageService.binding(binding).analyzerConfiguration().read();
427+
analyzerConfiguration = analyzerConfigurationRepository.read(binding.connectionId(), binding.sonarProjectKey());
425428
} catch (StorageException e) {
426429
// XXX we should make sure this situation can not happen (sync should be enforced at least once)
427430
return Optional.empty();

0 commit comments

Comments
 (0)