1
0
mirror of https://github.com/bitwarden/server.git synced 2024-12-25 17:27:45 +01:00

[PM-6938] Allow certain database operations to be skipped (#3914)

* Centralize database migration logic

* Clean up unused usings

* Prizatize

* Remove verbose flag from Docker invocation

* Allow certain database operations to be skipped

* Readonly
This commit is contained in:
Matt Bishop 2024-03-27 11:20:54 -04:00 committed by GitHub
parent 5355b2b969
commit 2790687dc2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 18 additions and 5 deletions

View File

@ -76,14 +76,18 @@ public class JobsHostedService : BaseJobsHostedService
{
new Tuple<Type, ITrigger>(typeof(DeleteSendsJob), everyFiveMinutesTrigger),
new Tuple<Type, ITrigger>(typeof(DatabaseExpiredGrantsJob), everyFridayAt10pmTrigger),
new Tuple<Type, ITrigger>(typeof(DatabaseUpdateStatisticsJob), everySaturdayAtMidnightTrigger),
new Tuple<Type, ITrigger>(typeof(DatabaseRebuildlIndexesJob), everySundayAtMidnightTrigger),
new Tuple<Type, ITrigger>(typeof(DeleteCiphersJob), everyDayAtMidnightUtc),
new Tuple<Type, ITrigger>(typeof(DatabaseExpiredSponsorshipsJob), everyMondayAtMidnightTrigger),
new Tuple<Type, ITrigger>(typeof(DeleteAuthRequestsJob), everyFifteenMinutesTrigger),
new Tuple<Type, ITrigger>(typeof(DeleteUnverifiedOrganizationDomainsJob), everyDayAtTwoAmUtcTrigger),
};
if (!(_globalSettings.SqlServer?.DisableDatabaseMaintenanceJobs ?? false))
{
jobs.Add(new Tuple<Type, ITrigger>(typeof(DatabaseUpdateStatisticsJob), everySaturdayAtMidnightTrigger));
jobs.Add(new Tuple<Type, ITrigger>(typeof(DatabaseRebuildlIndexesJob), everySundayAtMidnightTrigger));
}
if (!_globalSettings.SelfHosted)
{
jobs.Add(new Tuple<Type, ITrigger>(typeof(AliveJob), everyTopOfTheHourTrigger));

View File

@ -221,6 +221,8 @@ public class GlobalSettings : IGlobalSettings
private string _connectionString;
private string _readOnlyConnectionString;
private string _jobSchedulerConnectionString;
public bool SkipDatabasePreparation { get; set; }
public bool DisableDatabaseMaintenanceJobs { get; set; }
public string ConnectionString
{

View File

@ -13,11 +13,14 @@ public class DbMigrator
{
private readonly string _connectionString;
private readonly ILogger<DbMigrator> _logger;
private readonly bool _skipDatabasePreparation;
public DbMigrator(string connectionString, ILogger<DbMigrator> logger = null)
public DbMigrator(string connectionString, ILogger<DbMigrator> logger = null,
bool skipDatabasePreparation = false)
{
_connectionString = connectionString;
_logger = logger ?? CreateLogger();
_skipDatabasePreparation = skipDatabasePreparation;
}
public bool MigrateMsSqlDatabaseWithRetries(bool enableLogging = true,
@ -31,7 +34,10 @@ public class DbMigrator
{
try
{
PrepareDatabase(cancellationToken);
if (!_skipDatabasePreparation)
{
PrepareDatabase(cancellationToken);
}
var success = MigrateDatabase(enableLogging, repeatable, folderName, dryRun, cancellationToken);
return success;

View File

@ -10,7 +10,8 @@ public class SqlServerDbMigrator : IDbMigrator
public SqlServerDbMigrator(GlobalSettings globalSettings, ILogger<DbMigrator> logger)
{
_migrator = new DbMigrator(globalSettings.SqlServer.ConnectionString, logger);
_migrator = new DbMigrator(globalSettings.SqlServer.ConnectionString, logger,
globalSettings.SqlServer.SkipDatabasePreparation);
}
public bool MigrateDatabase(bool enableLogging = true,