From c2652d21e1da0c39e91b8a5dea21c4de1fea3f9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fernando=20Fern=C3=A1ndez?= Date: Mon, 6 Sep 2021 20:41:37 +0200 Subject: [PATCH] Log EFCore migrations --- .../JellyfinDbProvider.cs | 14 ++++++++++++-- Jellyfin.Server/CoreAppHost.cs | 3 ++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/Jellyfin.Server.Implementations/JellyfinDbProvider.cs b/Jellyfin.Server.Implementations/JellyfinDbProvider.cs index 486be60537..c2c5198d14 100644 --- a/Jellyfin.Server.Implementations/JellyfinDbProvider.cs +++ b/Jellyfin.Server.Implementations/JellyfinDbProvider.cs @@ -1,8 +1,10 @@ using System; using System.IO; +using System.Linq; using MediaBrowser.Common.Configuration; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; namespace Jellyfin.Server.Implementations { @@ -13,19 +15,27 @@ namespace Jellyfin.Server.Implementations { private readonly IServiceProvider _serviceProvider; private readonly IApplicationPaths _appPaths; + private readonly ILogger _logger; /// /// Initializes a new instance of the class. /// /// The application's service provider. /// The application paths. - public JellyfinDbProvider(IServiceProvider serviceProvider, IApplicationPaths appPaths) + /// The logger. + public JellyfinDbProvider(IServiceProvider serviceProvider, IApplicationPaths appPaths, ILogger logger) { _serviceProvider = serviceProvider; _appPaths = appPaths; + _logger = logger; 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"); + } } /// diff --git a/Jellyfin.Server/CoreAppHost.cs b/Jellyfin.Server/CoreAppHost.cs index d41b5f74ec..60275c9189 100644 --- a/Jellyfin.Server/CoreAppHost.cs +++ b/Jellyfin.Server/CoreAppHost.cs @@ -78,7 +78,8 @@ namespace Jellyfin.Server } ServiceCollection.AddDbContextPool( - 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.AddSingleton();