diff --git a/src/Admin/Jobs/JobsHostedService.cs b/src/Admin/Jobs/JobsHostedService.cs index adba27970..89cf5512c 100644 --- a/src/Admin/Jobs/JobsHostedService.cs +++ b/src/Admin/Jobs/JobsHostedService.cs @@ -76,14 +76,18 @@ public class JobsHostedService : BaseJobsHostedService { new Tuple(typeof(DeleteSendsJob), everyFiveMinutesTrigger), new Tuple(typeof(DatabaseExpiredGrantsJob), everyFridayAt10pmTrigger), - new Tuple(typeof(DatabaseUpdateStatisticsJob), everySaturdayAtMidnightTrigger), - new Tuple(typeof(DatabaseRebuildlIndexesJob), everySundayAtMidnightTrigger), new Tuple(typeof(DeleteCiphersJob), everyDayAtMidnightUtc), new Tuple(typeof(DatabaseExpiredSponsorshipsJob), everyMondayAtMidnightTrigger), new Tuple(typeof(DeleteAuthRequestsJob), everyFifteenMinutesTrigger), new Tuple(typeof(DeleteUnverifiedOrganizationDomainsJob), everyDayAtTwoAmUtcTrigger), }; + if (!(_globalSettings.SqlServer?.DisableDatabaseMaintenanceJobs ?? false)) + { + jobs.Add(new Tuple(typeof(DatabaseUpdateStatisticsJob), everySaturdayAtMidnightTrigger)); + jobs.Add(new Tuple(typeof(DatabaseRebuildlIndexesJob), everySundayAtMidnightTrigger)); + } + if (!_globalSettings.SelfHosted) { jobs.Add(new Tuple(typeof(AliveJob), everyTopOfTheHourTrigger)); diff --git a/src/Core/Settings/GlobalSettings.cs b/src/Core/Settings/GlobalSettings.cs index 84037a0a1..50b4efe6f 100644 --- a/src/Core/Settings/GlobalSettings.cs +++ b/src/Core/Settings/GlobalSettings.cs @@ -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 { diff --git a/util/Migrator/DbMigrator.cs b/util/Migrator/DbMigrator.cs index a6ca53abd..11b80fac7 100644 --- a/util/Migrator/DbMigrator.cs +++ b/util/Migrator/DbMigrator.cs @@ -13,11 +13,14 @@ public class DbMigrator { private readonly string _connectionString; private readonly ILogger _logger; + private readonly bool _skipDatabasePreparation; - public DbMigrator(string connectionString, ILogger logger = null) + public DbMigrator(string connectionString, ILogger 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; diff --git a/util/Migrator/SqlServerDbMigrator.cs b/util/Migrator/SqlServerDbMigrator.cs index b44326082..d76b26cfb 100644 --- a/util/Migrator/SqlServerDbMigrator.cs +++ b/util/Migrator/SqlServerDbMigrator.cs @@ -10,7 +10,8 @@ public class SqlServerDbMigrator : IDbMigrator public SqlServerDbMigrator(GlobalSettings globalSettings, ILogger logger) { - _migrator = new DbMigrator(globalSettings.SqlServer.ConnectionString, logger); + _migrator = new DbMigrator(globalSettings.SqlServer.ConnectionString, logger, + globalSettings.SqlServer.SkipDatabasePreparation); } public bool MigrateDatabase(bool enableLogging = true,