mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-12-18 23:13:06 +03:00
Unified migration handling (#13950)
This commit is contained in:
@@ -16,10 +16,19 @@ using Jellyfin.Database.Implementations.Entities;
|
||||
using Jellyfin.Extensions;
|
||||
using Jellyfin.Server.Implementations.Item;
|
||||
using MediaBrowser.Controller;
|
||||
using MediaBrowser.Controller.Channels;
|
||||
using MediaBrowser.Controller.Chapters;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Library;
|
||||
using MediaBrowser.Controller.LiveTv;
|
||||
using MediaBrowser.Controller.Persistence;
|
||||
using MediaBrowser.Controller.Providers;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.Globalization;
|
||||
using MediaBrowser.Model.IO;
|
||||
using Microsoft.Data.Sqlite;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using BaseItemEntity = Jellyfin.Database.Implementations.Entities.BaseItemEntity;
|
||||
using Chapter = Jellyfin.Database.Implementations.Entities.Chapter;
|
||||
@@ -29,6 +38,7 @@ namespace Jellyfin.Server.Migrations.Routines;
|
||||
/// <summary>
|
||||
/// The migration routine for migrating the userdata database to EF Core.
|
||||
/// </summary>
|
||||
[JellyfinMigration("2025-04-20T20:00:00", nameof(MigrateLibraryDb), "36445464-849f-429f-9ad0-bb130efa0664")]
|
||||
internal class MigrateLibraryDb : IDatabaseMigrationRoutine
|
||||
{
|
||||
private const string DbFilename = "library.db";
|
||||
@@ -45,11 +55,13 @@ internal class MigrateLibraryDb : IDatabaseMigrationRoutine
|
||||
/// <param name="provider">The database provider.</param>
|
||||
/// <param name="paths">The server application paths.</param>
|
||||
/// <param name="jellyfinDatabaseProvider">The database provider for special access.</param>
|
||||
/// <param name="serviceProvider">The Service provider.</param>
|
||||
public MigrateLibraryDb(
|
||||
ILogger<MigrateLibraryDb> logger,
|
||||
IDbContextFactory<JellyfinDbContext> provider,
|
||||
IServerApplicationPaths paths,
|
||||
IJellyfinDatabaseProvider jellyfinDatabaseProvider)
|
||||
IJellyfinDatabaseProvider jellyfinDatabaseProvider,
|
||||
IServiceProvider serviceProvider)
|
||||
{
|
||||
_logger = logger;
|
||||
_provider = provider;
|
||||
@@ -57,15 +69,6 @@ internal class MigrateLibraryDb : IDatabaseMigrationRoutine
|
||||
_jellyfinDatabaseProvider = jellyfinDatabaseProvider;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Guid Id => Guid.Parse("36445464-849f-429f-9ad0-bb130efa0664");
|
||||
|
||||
/// <inheritdoc/>
|
||||
public string Name => "MigrateLibraryDbData";
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool PerformOnNewInstall => false; // TODO Change back after testing
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Perform()
|
||||
{
|
||||
@@ -73,6 +76,12 @@ internal class MigrateLibraryDb : IDatabaseMigrationRoutine
|
||||
|
||||
var dataPath = _paths.DataPath;
|
||||
var libraryDbPath = Path.Combine(dataPath, DbFilename);
|
||||
if (!File.Exists(libraryDbPath))
|
||||
{
|
||||
_logger.LogError("Cannot migrate {LibraryDb} as it does not exist..", libraryDbPath);
|
||||
return;
|
||||
}
|
||||
|
||||
using var connection = new SqliteConnection($"Filename={libraryDbPath};Mode=ReadOnly");
|
||||
|
||||
var fullOperationTimer = new Stopwatch();
|
||||
@@ -395,8 +404,6 @@ internal class MigrateLibraryDb : IDatabaseMigrationRoutine
|
||||
|
||||
_logger.LogInformation("Move {0} to {1}.", libraryDbPath, libraryDbPath + ".old");
|
||||
File.Move(libraryDbPath, libraryDbPath + ".old", true);
|
||||
|
||||
_jellyfinDatabaseProvider.RunScheduledOptimisation(CancellationToken.None).ConfigureAwait(false).GetAwaiter().GetResult();
|
||||
}
|
||||
|
||||
private DatabaseMigrationStep GetPreparedDbContext(string operationName)
|
||||
|
||||
Reference in New Issue
Block a user