33 lines
1.1 KiB
C#
33 lines
1.1 KiB
C#
using FictionArchive.Service.NovelService.Models.Novels;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace FictionArchive.Service.NovelService.Services;
|
|
|
|
public class NovelServiceDbContext(DbContextOptions options, ILogger<NovelServiceDbContext> logger)
|
|
: DbContext(options)
|
|
{
|
|
public DbSet<Novel> Novels { get; set; }
|
|
public DbSet<Source> Sources { get; set; }
|
|
public DbSet<TranslationEngine> TranslationEngines { get; set; }
|
|
public DbSet<NovelTag> Tags { get; set; }
|
|
|
|
private readonly ILogger _logger = logger;
|
|
|
|
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.");
|
|
}
|
|
} |