1
0
mirror of https://github.com/bitwarden/server.git synced 2025-06-30 15:42:48 -05:00

Bitwarden Unified Self-Host project (#2410)

This commit is contained in:
Vince Grassia
2022-11-18 14:39:01 -05:00
committed by GitHub
parent 3481fd76c1
commit 194dfe7e14
57 changed files with 1929 additions and 323 deletions

View File

@ -0,0 +1,41 @@
using Bit.Core;
using Bit.Core.Utilities;
using Bit.Infrastructure.EntityFramework.Repositories;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
namespace Bit.MySqlMigrations;
public class MySqlDbMigrator : IDbMigrator
{
private readonly IServiceScopeFactory _serviceScopeFactory;
private readonly ILogger<MySqlDbMigrator> _logger;
public MySqlDbMigrator(IServiceScopeFactory serviceScopeFactory, ILogger<MySqlDbMigrator> logger)
{
_serviceScopeFactory = serviceScopeFactory;
_logger = logger;
}
public bool MigrateDatabase(bool enableLogging = true,
CancellationToken cancellationToken = default(CancellationToken))
{
if (enableLogging && _logger != null)
{
_logger.LogInformation(Constants.BypassFiltersEventId, "Migrating database.");
}
using var scope = _serviceScopeFactory.CreateScope();
var databaseContext = scope.ServiceProvider.GetRequiredService<DatabaseContext>();
databaseContext.Database.Migrate();
if (enableLogging && _logger != null)
{
_logger.LogInformation(Constants.BypassFiltersEventId, "Migration successful.");
}
cancellationToken.ThrowIfCancellationRequested();
return true;
}
}