diff options
Diffstat (limited to 'BackEnd/Timeline/Services/DatabaseManagement')
-rw-r--r-- | BackEnd/Timeline/Services/DatabaseManagement/DatabaseManagementService.cs | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/BackEnd/Timeline/Services/DatabaseManagement/DatabaseManagementService.cs b/BackEnd/Timeline/Services/DatabaseManagement/DatabaseManagementService.cs index c3d9ac4e..1ae13724 100644 --- a/BackEnd/Timeline/Services/DatabaseManagement/DatabaseManagementService.cs +++ b/BackEnd/Timeline/Services/DatabaseManagement/DatabaseManagementService.cs @@ -1,20 +1,27 @@ using Microsoft.EntityFrameworkCore;
+using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
+using Microsoft.Extensions.Logging;
using System;
using System.Threading;
using System.Threading.Tasks;
+using Timeline.Configs;
using Timeline.Entities;
namespace Timeline.Services.DatabaseManagement
{
public class DatabaseManagementService : IHostedService
{
+ private readonly ILogger<DatabaseManagementService> _logger;
private readonly IServiceProvider _serviceProvider;
+ private readonly bool _disableAutoBackup;
- public DatabaseManagementService(IServiceProvider serviceProvider)
+ public DatabaseManagementService(IServiceProvider serviceProvider, IConfiguration configuration, ILogger<DatabaseManagementService> logger)
{
_serviceProvider = serviceProvider;
+ _disableAutoBackup = ApplicationConfiguration.GetBoolConfig(configuration, ApplicationConfiguration.DisableAutoBackupKey, false);
+ _logger = logger;
}
public async Task StartAsync(CancellationToken cancellationToken = default)
@@ -27,7 +34,14 @@ namespace Timeline.Services.DatabaseManagement var customMigrator = provider.GetRequiredService<IDatabaseCustomMigrator>();
- await backupService.BackupAsync(cancellationToken);
+ if (!_disableAutoBackup)
+ {
+ await backupService.BackupAsync(cancellationToken);
+ }
+ else
+ {
+ _logger.LogWarning("Auto backup is disabled. Please backup your database manually.");
+ }
await database.Database.MigrateAsync(cancellationToken);
await customMigrator.MigrateAsync(cancellationToken);
}
|