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(DeleteSendsJob), everyFiveMinutesTrigger),
|
||||||
new Tuple<Type, ITrigger>(typeof(DatabaseExpiredGrantsJob), everyFridayAt10pmTrigger),
|
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(DeleteCiphersJob), everyDayAtMidnightUtc),
|
||||||
new Tuple<Type, ITrigger>(typeof(DatabaseExpiredSponsorshipsJob), everyMondayAtMidnightTrigger),
|
new Tuple<Type, ITrigger>(typeof(DatabaseExpiredSponsorshipsJob), everyMondayAtMidnightTrigger),
|
||||||
new Tuple<Type, ITrigger>(typeof(DeleteAuthRequestsJob), everyFifteenMinutesTrigger),
|
new Tuple<Type, ITrigger>(typeof(DeleteAuthRequestsJob), everyFifteenMinutesTrigger),
|
||||||
new Tuple<Type, ITrigger>(typeof(DeleteUnverifiedOrganizationDomainsJob), everyDayAtTwoAmUtcTrigger),
|
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)
|
if (!_globalSettings.SelfHosted)
|
||||||
{
|
{
|
||||||
jobs.Add(new Tuple<Type, ITrigger>(typeof(AliveJob), everyTopOfTheHourTrigger));
|
jobs.Add(new Tuple<Type, ITrigger>(typeof(AliveJob), everyTopOfTheHourTrigger));
|
||||||
|
@ -221,6 +221,8 @@ public class GlobalSettings : IGlobalSettings
|
|||||||
private string _connectionString;
|
private string _connectionString;
|
||||||
private string _readOnlyConnectionString;
|
private string _readOnlyConnectionString;
|
||||||
private string _jobSchedulerConnectionString;
|
private string _jobSchedulerConnectionString;
|
||||||
|
public bool SkipDatabasePreparation { get; set; }
|
||||||
|
public bool DisableDatabaseMaintenanceJobs { get; set; }
|
||||||
|
|
||||||
public string ConnectionString
|
public string ConnectionString
|
||||||
{
|
{
|
||||||
|
@ -13,11 +13,14 @@ public class DbMigrator
|
|||||||
{
|
{
|
||||||
private readonly string _connectionString;
|
private readonly string _connectionString;
|
||||||
private readonly ILogger<DbMigrator> _logger;
|
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;
|
_connectionString = connectionString;
|
||||||
_logger = logger ?? CreateLogger();
|
_logger = logger ?? CreateLogger();
|
||||||
|
_skipDatabasePreparation = skipDatabasePreparation;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool MigrateMsSqlDatabaseWithRetries(bool enableLogging = true,
|
public bool MigrateMsSqlDatabaseWithRetries(bool enableLogging = true,
|
||||||
@ -30,8 +33,11 @@ public class DbMigrator
|
|||||||
while (attempt < 10)
|
while (attempt < 10)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
{
|
||||||
|
if (!_skipDatabasePreparation)
|
||||||
{
|
{
|
||||||
PrepareDatabase(cancellationToken);
|
PrepareDatabase(cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
var success = MigrateDatabase(enableLogging, repeatable, folderName, dryRun, cancellationToken);
|
var success = MigrateDatabase(enableLogging, repeatable, folderName, dryRun, cancellationToken);
|
||||||
return success;
|
return success;
|
||||||
|
@ -10,7 +10,8 @@ public class SqlServerDbMigrator : IDbMigrator
|
|||||||
|
|
||||||
public SqlServerDbMigrator(GlobalSettings globalSettings, ILogger<DbMigrator> logger)
|
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,
|
public bool MigrateDatabase(bool enableLogging = true,
|
||||||
|
Loading…
Reference in New Issue
Block a user