Add migration to cleans DB of 7.10.1 hack

This commit is contained in:
Michael Bucari-Tovo 2022-06-07 15:25:52 -06:00
parent 5bc76a3160
commit 30e6deeeaa
2 changed files with 26 additions and 2 deletions

View File

@ -59,6 +59,7 @@ namespace AppScaffolding
//
Migrations.migrate_to_v6_6_9(config);
Migrations.migrate_from_7_10_1(config);
}
public static void PopulateMissingConfigValues(Configuration config)
@ -401,5 +402,28 @@ namespace AppScaffolding
UNSAFE_MigrationHelper.Settings_AddUniqueToArray("Serilog.Enrich", "WithExceptionDetails");
}
}
public static void migrate_from_7_10_1(Configuration config)
{
//This migration removes books and series with SERIES_ prefix that were created
//as a hack workaround in 7.10.1. Said workaround was removed in 7.10.2
var migrated = config.GetNonString<bool>(nameof(migrate_from_7_10_1));
if (migrated) return;
using var context = DbContexts.GetContext();
var booksToRemove = context.Books.Where(b => b.AudibleProductId.StartsWith("SERIES_")).ToArray();
var seriesToRemove = context.Series.Where(s => s.AudibleSeriesId.StartsWith("SERIES_")).ToArray();
var lbToRemove = context.LibraryBooks.Where(lb => booksToRemove.Any(b => b == lb.Book)).ToArray();
context.LibraryBooks.RemoveRange(lbToRemove);
context.Books.RemoveRange(booksToRemove);
context.Series.RemoveRange(seriesToRemove);
LibraryCommands.SaveContext(context);
config.SetObject(nameof(migrate_from_7_10_1), true);
}
}
}

View File

@ -200,7 +200,7 @@ namespace ApplicationServices
var libraryBookImporter = new LibraryBookImporter(context);
var newCount = await Task.Run(() => libraryBookImporter.Import(importItems));
logTime("importIntoDbAsync -- post Import()");
int qtyChanges = saveChanges(context);
int qtyChanges = SaveContext(context);
logTime("importIntoDbAsync -- post SaveChanges");
// this is any changes at all to the database, not just new books
@ -211,7 +211,7 @@ namespace ApplicationServices
return newCount;
}
private static int saveChanges(LibationContext context)
public static int SaveContext(LibationContext context)
{
try
{