Last issue before release (#2681)

This commit is contained in:
Joe Milazzo 2024-02-02 09:04:56 -06:00 committed by GitHub
parent 149c30b138
commit 355ea24db6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 72 additions and 35 deletions

View file

@ -0,0 +1,42 @@
using System;
using System.Threading.Tasks;
using API.Entities;
using Kavita.Common.EnvironmentInfo;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
namespace API.Data.ManualMigrations;
/// <summary>
/// For the v0.7.14 release, one of the nightlies had bad data that would cause issues. This drops those records
/// </summary>
public static class MigrateClearNightlyExternalSeriesRecords
{
public static async Task Migrate(DataContext dataContext, ILogger<Program> logger)
{
if (await dataContext.ManualMigrationHistory.AnyAsync(m => m.Name == "MigrateClearNightlyExternalSeriesRecords"))
{
return;
}
logger.LogCritical(
"Running MigrateClearNightlyExternalSeriesRecords migration - Please be patient, this may take some time. This is not an error");
dataContext.ExternalSeriesMetadata.RemoveRange(dataContext.ExternalSeriesMetadata);
dataContext.ExternalRating.RemoveRange(dataContext.ExternalRating);
dataContext.ExternalRecommendation.RemoveRange(dataContext.ExternalRecommendation);
dataContext.ExternalReview.RemoveRange(dataContext.ExternalReview);
dataContext.ManualMigrationHistory.Add(new ManualMigrationHistory()
{
Name = "MigrateClearNightlyExternalSeriesRecords",
ProductVersion = BuildInfo.Version.ToString(),
RanAt = DateTime.UtcNow
});
await dataContext.SaveChangesAsync();
logger.LogCritical(
"Running MigrateClearNightlyExternalSeriesRecords migration - Completed. This is not an error");
}
}

View file

@ -21,37 +21,19 @@ public static class MigrateWantToReadExport
logger.LogCritical(
"Running MigrateWantToReadExport migration - Please be patient, this may take some time. This is not an error");
var columnExists = false;
await using var command = dataContext.Database.GetDbConnection().CreateCommand();
command.CommandText = "PRAGMA table_info('Series')";
await dataContext.Database.OpenConnectionAsync();
await using var result = await command.ExecuteReaderAsync();
while (await result.ReadAsync())
{
var columnName = result["name"].ToString();
if (columnName != "AppUserId") continue;
logger.LogInformation("Column 'AppUserId' exists in the 'Series' table. Running migration...");
// Your migration logic here
columnExists = true;
break;
}
await result.CloseAsync();
if (!columnExists)
var importFile = Path.Join(directoryService.ConfigDirectory, "want-to-read-migration.csv");
if (File.Exists(importFile))
{
logger.LogCritical(
"Running MigrateWantToReadExport migration - Completed. This is not an error");
return;
}
await using var command2 = dataContext.Database.GetDbConnection().CreateCommand();
await using var command = dataContext.Database.GetDbConnection().CreateCommand();
command.CommandText = "Select AppUserId, Id from Series WHERE AppUserId IS NOT NULL ORDER BY AppUserId;";
await dataContext.Database.OpenConnectionAsync();
await using var result2 = await command.ExecuteReaderAsync();
await using var result = await command.ExecuteReaderAsync();
await using var writer = new StreamWriter(Path.Join(directoryService.ConfigDirectory, "want-to-read-migration.csv"));
await using var csvWriter = new CsvWriter(writer, CultureInfo.InvariantCulture);
@ -62,10 +44,10 @@ public static class MigrateWantToReadExport
await csvWriter.NextRecordAsync();
// Write data
while (await result2.ReadAsync())
while (await result.ReadAsync())
{
var appUserId = result2["AppUserId"].ToString();
var id = result2["Id"].ToString();
var appUserId = result["AppUserId"].ToString();
var id = result["Id"].ToString();
csvWriter.WriteField(appUserId);
csvWriter.WriteField(id);
@ -75,7 +57,7 @@ public static class MigrateWantToReadExport
try
{
await result2.CloseAsync();
await dataContext.Database.CloseConnectionAsync();
writer.Close();
} catch (Exception) {/* Swallow */}

View file

@ -241,7 +241,9 @@ public class VolumeRepository : IVolumeRepository
c.LastReadingProgress = progresses.Max(p => p.LastModified);
}
v.PagesRead = userProgress.Where(p => p.VolumeId == v.Id).Sum(p => p.PagesRead);
v.PagesRead = userProgress
.Where(p => p.VolumeId == v.Id)
.Sum(p => p.PagesRead);
}
}
}