| | | 1 | | using Jellyfin.Database.Implementations; |
| | | 2 | | using Microsoft.EntityFrameworkCore; |
| | | 3 | | using Microsoft.Extensions.Logging; |
| | | 4 | | |
| | | 5 | | namespace Jellyfin.Server.Migrations.Routines; |
| | | 6 | | |
| | | 7 | | /// <summary> |
| | | 8 | | /// Drops keys that no current property reads or writes from the serialized <c>BaseItems.Data</c> blob. |
| | | 9 | | /// </summary> |
| | | 10 | | [JellyfinMigration("2026-09-11T12:00:00", nameof(StripEmbeddedLinkedChildren))] |
| | | 11 | | internal class StripEmbeddedLinkedChildren : IDatabaseMigrationRoutine |
| | | 12 | | { |
| | | 13 | | private readonly ILogger<StripEmbeddedLinkedChildren> _logger; |
| | | 14 | | private readonly IDbContextFactory<JellyfinDbContext> _dbProvider; |
| | | 15 | | |
| | | 16 | | public StripEmbeddedLinkedChildren( |
| | | 17 | | ILoggerFactory loggerFactory, |
| | | 18 | | IDbContextFactory<JellyfinDbContext> dbProvider) |
| | | 19 | | { |
| | 0 | 20 | | _logger = loggerFactory.CreateLogger<StripEmbeddedLinkedChildren>(); |
| | 0 | 21 | | _dbProvider = dbProvider; |
| | 0 | 22 | | } |
| | | 23 | | |
| | | 24 | | /// <inheritdoc/> |
| | | 25 | | public void Perform() |
| | | 26 | | { |
| | 0 | 27 | | using var context = _dbProvider.CreateDbContext(); |
| | | 28 | | |
| | | 29 | | // json_valid guards the rare malformed blob: json_remove would abort the statement on it, |
| | | 30 | | // and one bad row must not cost every other row the fix. |
| | 0 | 31 | | var updated = context.Database.ExecuteSqlRaw( |
| | 0 | 32 | | """ |
| | 0 | 33 | | UPDATE "BaseItems" |
| | 0 | 34 | | SET "Data" = json_remove("Data", '$.LinkedChildren', '$.ExtraIds', '$.SupportsExternalTransfer') |
| | 0 | 35 | | WHERE "Data" IS NOT NULL |
| | 0 | 36 | | AND json_valid("Data") = 1 |
| | 0 | 37 | | AND ("Data" LIKE '%"LinkedChildren"%' |
| | 0 | 38 | | OR "Data" LIKE '%"ExtraIds"%' |
| | 0 | 39 | | OR "Data" LIKE '%"SupportsExternalTransfer"%') |
| | 0 | 40 | | """); |
| | | 41 | | |
| | 0 | 42 | | _logger.LogInformation("Dropped dead keys from the serialized data of {Count} items", updated); |
| | 0 | 43 | | } |
| | | 44 | | } |