mirror of
https://github.com/bitwarden/server.git
synced 2024-11-24 12:35:25 +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:
parent
5355b2b969
commit
2790687dc2
@ -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));
|
||||
|
@ -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
|
||||
{
|
||||
|
@ -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;
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user