diff options
| author | JPVenson <github@jpb.email> | 2025-06-05 17:46:50 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-06-05 08:46:50 -0600 |
| commit | a3578caa8c71c84b278e18a07ebc157bcf04c687 (patch) | |
| tree | 7c185c3c14827c444ae0644fd3714581f3b2bbf3 | |
| parent | b45e5463c16b8ef9668c8b6ad289e30c2bd3a1c2 (diff) | |
Migrate all known old migrations even when not applied in migration.xml (#14217)
| -rw-r--r-- | Jellyfin.Server/Migrations/JellyfinMigrationService.cs | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/Jellyfin.Server/Migrations/JellyfinMigrationService.cs b/Jellyfin.Server/Migrations/JellyfinMigrationService.cs index fc4045da0..5c5c64ec3 100644 --- a/Jellyfin.Server/Migrations/JellyfinMigrationService.cs +++ b/Jellyfin.Server/Migrations/JellyfinMigrationService.cs @@ -135,11 +135,22 @@ internal class JellyfinMigrationService { var historyRepository = dbContext.GetService<IHistoryRepository>(); var appliedMigrations = await dbContext.Database.GetAppliedMigrationsAsync().ConfigureAwait(false); - var oldMigrations = Migrations + var lastOldAppliedMigration = Migrations .SelectMany(e => e.Where(e => e.Metadata.Key is not null)) // only consider migrations that have the key set as its the reference marker for legacy migrations. .Where(e => migrationOptions.Applied.Any(f => f.Id.Equals(e.Metadata.Key!.Value))) .Where(e => !appliedMigrations.Contains(e.BuildCodeMigrationId())) - .ToArray(); + .OrderBy(e => e.BuildCodeMigrationId()) + .Last(); // this is the latest migration applied in the old migration.xml + + IReadOnlyList<CodeMigration> oldMigrations = [ + .. Migrations + .SelectMany(e => e) + .OrderBy(e => e.BuildCodeMigrationId()) + .TakeWhile(e => e.BuildCodeMigrationId() != lastOldAppliedMigration.BuildCodeMigrationId()), + lastOldAppliedMigration + ]; + // those are all migrations that had to run in the old migration system, even if not noted in the migration.xml file. + var startupScripts = oldMigrations.Select(e => (Migration: e.Metadata, Script: historyRepository.GetInsertScript(new HistoryRow(e.BuildCodeMigrationId(), GetJellyfinVersion())))); foreach (var item in startupScripts) { |
