diff options
author | Alain Kermis <alain.kermis@sonarsource.com> | 2024-12-27 18:37:10 +0100 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2025-01-03 20:03:01 +0000 |
commit | 203cbfef99e3c3dc91eb6f802739b924c364fdf6 (patch) | |
tree | 5910e4b600ffb04f1a7b78c6c91ef8923e965b7c /server/sonar-db-dao | |
parent | 164ac517fdcb1d56598a30a62478f353d9f76f6e (diff) | |
download | sonarqube-203cbfef99e3c3dc91eb6f802739b924c364fdf6.tar.gz sonarqube-203cbfef99e3c3dc91eb6f802739b924c364fdf6.zip |
SONAR-23119 Implement database migration logging mechanism
Diffstat (limited to 'server/sonar-db-dao')
-rw-r--r-- | server/sonar-db-dao/src/testFixtures/java/org/sonar/db/DbTester.java | 7 | ||||
-rw-r--r-- | server/sonar-db-dao/src/testFixtures/java/org/sonar/db/migrationlog/MigrationLogDbTester.java | 49 |
2 files changed, 56 insertions, 0 deletions
diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/DbTester.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/DbTester.java index 9e6a46fecd5..faa1d141871 100644 --- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/DbTester.java +++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/DbTester.java @@ -47,6 +47,7 @@ import org.sonar.db.event.EventDbTester; import org.sonar.db.favorite.FavoriteDbTester; import org.sonar.db.issue.IssueDbTester; import org.sonar.db.measure.MeasureDbTester; +import org.sonar.db.migrationlog.MigrationLogDbTester; import org.sonar.db.newcodeperiod.NewCodePeriodDbTester; import org.sonar.db.notification.NotificationDbTester; import org.sonar.db.permission.template.PermissionTemplateDbTester; @@ -86,6 +87,7 @@ public class DbTester extends AbstractDbTester<TestDbImpl> implements BeforeEach private final NotificationDbTester notificationDbTester; private final QualityProfileDbTester qualityProfileDbTester; private final MeasureDbTester measureDbTester; + private final MigrationLogDbTester migrationLogTester; private final FileSourceTester fileSourceTester; private final PluginDbTester pluginDbTester; private final WebhookDbTester webhookDbTester; @@ -117,6 +119,7 @@ public class DbTester extends AbstractDbTester<TestDbImpl> implements BeforeEach this.notificationDbTester = new NotificationDbTester(this); this.qualityProfileDbTester = new QualityProfileDbTester(this); this.measureDbTester = new MeasureDbTester(this); + this.migrationLogTester = new MigrationLogDbTester(this); this.fileSourceTester = new FileSourceTester(this); this.pluginDbTester = new PluginDbTester(this); this.webhookDbTester = new WebhookDbTester(this); @@ -235,6 +238,10 @@ public class DbTester extends AbstractDbTester<TestDbImpl> implements BeforeEach return measureDbTester; } + public MigrationLogDbTester migrationLogs() { + return migrationLogTester; + } + public FileSourceTester fileSources() { return fileSourceTester; } diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/migrationlog/MigrationLogDbTester.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/migrationlog/MigrationLogDbTester.java new file mode 100644 index 00000000000..3d9b42b3f13 --- /dev/null +++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/migrationlog/MigrationLogDbTester.java @@ -0,0 +1,49 @@ +/* + * SonarQube + * Copyright (C) 2009-2024 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.db.migrationlog; + +import java.util.Arrays; +import java.util.List; +import java.util.function.Consumer; +import org.sonar.db.DbClient; +import org.sonar.db.DbTester; + +public class MigrationLogDbTester { + private final DbClient dbClient; + private final DbTester db; + + public MigrationLogDbTester(DbTester db) { + this.dbClient = db.getDbClient(); + this.db = db; + } + + @SafeVarargs + public final MigrationLogDto insert(Consumer<MigrationLogDto>... consumers) { + MigrationLogDto migrationLogDto = new MigrationLogDto(); + Arrays.stream(consumers).forEach(c -> c.accept(migrationLogDto)); + dbClient.migrationLogDao().insert(db.getSession(), migrationLogDto); + db.commit(); + return migrationLogDto; + } + + public final List<MigrationLogDto> selectAll() { + return dbClient.migrationLogDao().selectAll(db.getSession()); + } +} |