mirror of
https://github.com/Kareadita/Kavita.git
synced 2025-05-24 00:52:23 -04:00
Migration to fix the People mess up I made (#3303)
This commit is contained in:
parent
5abcb2dca6
commit
1d5ba8992c
48
API/Data/ManualMigrations/ManualMigrateRemovePeople.cs
Normal file
48
API/Data/ManualMigrations/ManualMigrateRemovePeople.cs
Normal file
@ -0,0 +1,48 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using API.Entities;
|
||||
using Kavita.Common.EnvironmentInfo;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace API.Data.ManualMigrations;
|
||||
|
||||
/// <summary>
|
||||
/// Due to a bug in the initial merge of People/Scanner rework, people got messed up bad. This migration will clear out the table only for nightly users: 0.8.3.15/0.8.3.16
|
||||
/// </summary>
|
||||
public static class ManualMigrateRemovePeople
|
||||
{
|
||||
public static async Task Migrate(DataContext context, ILogger<Program> logger)
|
||||
{
|
||||
if (await context.ManualMigrationHistory.AnyAsync(m => m.Name == "ManualMigrateRemovePeople"))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var version = BuildInfo.Version.ToString();
|
||||
if (version != "0.8.3.15" && version != "0.8.3.16")
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
logger.LogCritical("Running ManualMigrateRemovePeople migration - Please be patient, this may take some time. This is not an error");
|
||||
|
||||
context.Person.RemoveRange(context.Person);
|
||||
|
||||
if (context.ChangeTracker.HasChanges())
|
||||
{
|
||||
await context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
await context.ManualMigrationHistory.AddAsync(new ManualMigrationHistory()
|
||||
{
|
||||
Name = "ManualMigrateRemovePeople",
|
||||
ProductVersion = BuildInfo.Version.ToString(),
|
||||
RanAt = DateTime.UtcNow
|
||||
});
|
||||
await context.SaveChangesAsync();
|
||||
|
||||
logger.LogCritical("Running ManualMigrateRemovePeople migration - Completed. This is not an error");
|
||||
}
|
||||
}
|
@ -273,6 +273,7 @@ public class Startup
|
||||
|
||||
// v0.8.4
|
||||
await MigrateLowestSeriesFolderPath2.Migrate(dataContext, unitOfWork, logger);
|
||||
await ManualMigrateRemovePeople.Migrate(dataContext, logger);
|
||||
|
||||
// Update the version in the DB after all migrations are run
|
||||
var installVersion = await unitOfWork.SettingsRepository.GetSettingAsync(ServerSettingKey.InstallVersion);
|
||||
|
Loading…
x
Reference in New Issue
Block a user