Log EFCore migrations
This commit is contained in:
parent
3d0b1ccae6
commit
c2652d21e1
|
@ -1,8 +1,10 @@
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
using MediaBrowser.Common.Configuration;
|
using MediaBrowser.Common.Configuration;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
namespace Jellyfin.Server.Implementations
|
namespace Jellyfin.Server.Implementations
|
||||||
{
|
{
|
||||||
|
@ -13,19 +15,27 @@ namespace Jellyfin.Server.Implementations
|
||||||
{
|
{
|
||||||
private readonly IServiceProvider _serviceProvider;
|
private readonly IServiceProvider _serviceProvider;
|
||||||
private readonly IApplicationPaths _appPaths;
|
private readonly IApplicationPaths _appPaths;
|
||||||
|
private readonly ILogger<JellyfinDbProvider> _logger;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="JellyfinDbProvider"/> class.
|
/// Initializes a new instance of the <see cref="JellyfinDbProvider"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="serviceProvider">The application's service provider.</param>
|
/// <param name="serviceProvider">The application's service provider.</param>
|
||||||
/// <param name="appPaths">The application paths.</param>
|
/// <param name="appPaths">The application paths.</param>
|
||||||
public JellyfinDbProvider(IServiceProvider serviceProvider, IApplicationPaths appPaths)
|
/// <param name="logger">The logger.</param>
|
||||||
|
public JellyfinDbProvider(IServiceProvider serviceProvider, IApplicationPaths appPaths, ILogger<JellyfinDbProvider> logger)
|
||||||
{
|
{
|
||||||
_serviceProvider = serviceProvider;
|
_serviceProvider = serviceProvider;
|
||||||
_appPaths = appPaths;
|
_appPaths = appPaths;
|
||||||
|
_logger = logger;
|
||||||
|
|
||||||
using var jellyfinDb = CreateContext();
|
using var jellyfinDb = CreateContext();
|
||||||
jellyfinDb.Database.Migrate();
|
if (jellyfinDb.Database.GetPendingMigrations().Any())
|
||||||
|
{
|
||||||
|
_logger.LogInformation("There are pending EFCore migrations in the database. Applying... (This may take a while, do not stop Jellyfin)");
|
||||||
|
jellyfinDb.Database.Migrate();
|
||||||
|
_logger.LogInformation("EFCore migrations applied successfully");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
@ -78,7 +78,8 @@ namespace Jellyfin.Server
|
||||||
}
|
}
|
||||||
|
|
||||||
ServiceCollection.AddDbContextPool<JellyfinDb>(
|
ServiceCollection.AddDbContextPool<JellyfinDb>(
|
||||||
options => options.UseSqlite($"Filename={Path.Combine(ApplicationPaths.DataPath, "jellyfin.db")}"));
|
options => options.UseLoggerFactory(LoggerFactory).
|
||||||
|
UseSqlite($"Filename={Path.Combine(ApplicationPaths.DataPath, "jellyfin.db")}"));
|
||||||
|
|
||||||
ServiceCollection.AddEventServices();
|
ServiceCollection.AddEventServices();
|
||||||
ServiceCollection.AddSingleton<IBaseItemManager, BaseItemManager>();
|
ServiceCollection.AddSingleton<IBaseItemManager, BaseItemManager>();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user