Add migration to cleans DB of 7.10.1 hack
This commit is contained in:
parent
5bc76a3160
commit
30e6deeeaa
@ -59,6 +59,7 @@ namespace AppScaffolding
|
|||||||
//
|
//
|
||||||
|
|
||||||
Migrations.migrate_to_v6_6_9(config);
|
Migrations.migrate_to_v6_6_9(config);
|
||||||
|
Migrations.migrate_from_7_10_1(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void PopulateMissingConfigValues(Configuration config)
|
public static void PopulateMissingConfigValues(Configuration config)
|
||||||
@ -401,5 +402,28 @@ namespace AppScaffolding
|
|||||||
UNSAFE_MigrationHelper.Settings_AddUniqueToArray("Serilog.Enrich", "WithExceptionDetails");
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -200,7 +200,7 @@ namespace ApplicationServices
|
|||||||
var libraryBookImporter = new LibraryBookImporter(context);
|
var libraryBookImporter = new LibraryBookImporter(context);
|
||||||
var newCount = await Task.Run(() => libraryBookImporter.Import(importItems));
|
var newCount = await Task.Run(() => libraryBookImporter.Import(importItems));
|
||||||
logTime("importIntoDbAsync -- post Import()");
|
logTime("importIntoDbAsync -- post Import()");
|
||||||
int qtyChanges = saveChanges(context);
|
int qtyChanges = SaveContext(context);
|
||||||
logTime("importIntoDbAsync -- post SaveChanges");
|
logTime("importIntoDbAsync -- post SaveChanges");
|
||||||
|
|
||||||
// this is any changes at all to the database, not just new books
|
// this is any changes at all to the database, not just new books
|
||||||
@ -211,7 +211,7 @@ namespace ApplicationServices
|
|||||||
return newCount;
|
return newCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int saveChanges(LibationContext context)
|
public static int SaveContext(LibationContext context)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user