Updated translation service and finished splitting out responsibilities for now
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace FictionArchive.Service.Shared.Services.Database;
|
||||
|
||||
/// <summary>
|
||||
/// Abstract DbContext handling boilerplate shared between our contexts. Should not share actual data.
|
||||
/// </summary>
|
||||
public abstract class FictionArchiveDbContext : DbContext
|
||||
{
|
||||
protected readonly ILogger _logger;
|
||||
|
||||
protected FictionArchiveDbContext(DbContextOptions options, ILogger logger) : base(options)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
optionsBuilder.AddInterceptors(new AuditInterceptor());
|
||||
base.OnConfiguring(optionsBuilder);
|
||||
}
|
||||
|
||||
public void UpdateDatabase()
|
||||
{
|
||||
IEnumerable<string> pendingMigrations = Database.GetPendingMigrations();
|
||||
if (!pendingMigrations.Any())
|
||||
{
|
||||
_logger.LogDebug("No pending migrations found, continuing.");
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (string migration in pendingMigrations)
|
||||
{
|
||||
_logger.LogInformation("Found pending migration with name {migrationName}.", migration);
|
||||
}
|
||||
_logger.LogInformation("Attempting to apply pending migrations...");
|
||||
Database.Migrate();
|
||||
_logger.LogInformation("Migrations applied.");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user