mirror of
https://github.com/Kareadita/Kavita.git
synced 2025-12-13 16:45:04 -05:00
Co-authored-by: Amelia <77553571+Fesaa@users.noreply.github.com> Co-authored-by: Robbie Davis <robbie@therobbiedavis.com>
44 lines
1.2 KiB
C#
44 lines
1.2 KiB
C#
using System;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using API.Data.Misc;
|
|
using API.Entities.History;
|
|
using Kavita.Common.EnvironmentInfo;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
namespace API.Data.ManualMigrations;
|
|
|
|
/// <summary>
|
|
/// v0.8.9 - Some AppUser rows are missing CreatedUtc date
|
|
/// </summary>
|
|
public class MigrateMissingCreatedUtcDate : ManualMigration
|
|
{
|
|
protected override string MigrationName => nameof(MigrateMissingCreatedUtcDate);
|
|
protected override async Task ExecuteAsync(DataContext context, ILogger<Program> logger)
|
|
{
|
|
try
|
|
{
|
|
//0001-01-01 00:00:00
|
|
var usersWithoutCorrectCreatedUtc = await context.AppUser
|
|
.Where(u => u.CreatedUtc == DateTime.MinValue)
|
|
.ToListAsync();
|
|
|
|
foreach (var user in usersWithoutCorrectCreatedUtc)
|
|
{
|
|
user.CreatedUtc = user.Created.ToUniversalTime();
|
|
}
|
|
|
|
if (context.ChangeTracker.HasChanges())
|
|
{
|
|
await context.SaveChangesAsync();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logger.LogError(ex, "Error during {Name} migration", MigrationName);
|
|
throw;
|
|
}
|
|
}
|
|
}
|