Change:
<ins> diff --git a/API/Data/ManualMigrations/MigrateDisableScrobblingOnComicLibraries.cs b/API/Data/ManualMigrations/MigrateDisableScrobblingOnComicLibraries.cs new file mode 100644 index 00000000..0de7bf5d --- /dev/null +++ b/API/Data/ManualMigrations/MigrateDisableScrobblingOnComicLibraries.cs @@ -0,0 +1,38 @@ +using System.Linq; +using System.Threading.Tasks; +using API.Entities.Enums; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Logging; + +namespace API.Data.ManualMigrations; + +/// <summary> +/// v0.7.4 introduced Scrobbling with Kavita+. By default, it is on, but Comic libraries have no scrobble providers, so disable +/// </summary> +public static class MigrateDisableScrobblingOnComicLibraries +{ +    public static async Task Migrate(IUnitOfWork unitOfWork, DataContext dataContext, ILogger<Program> logger) +    { +        if (!await dataContext.Library.Where(s => s.Type == LibraryType.Comic).Where(l => l.AllowScrobbling).AnyAsync()) +        { +            return; +        } +        logger.LogInformation("Running MigrateDisableScrobblingOnComicLibraries migration. Please be patient, this may take some time"); + + +        foreach (var lib in await dataContext.Library.Where(s => s.Type == LibraryType.Comic).Where(l => l.AllowScrobbling).ToListAsync()) +        { +            lib.AllowScrobbling = false; +            unitOfWork.LibraryRepository.Update(lib); +        } + +        if (unitOfWork.HasChanges()) +        { +            await unitOfWork.CommitAsync(); +        } + +        logger.LogInformation("MigrateDisableScrobblingOnComicLibraries migration finished"); + +    } + +} diff --git a/API/Data/ManualMigrations/MigrateLoginRoles.cs b/API/Data/ManualMigrations/MigrateLoginRoles.cs new file mode 100644 index 00000000..f649908a --- /dev/null +++ b/API/Data/ManualMigrations/MigrateLoginRoles.cs @@ -0,0 +1,36 @@ +using System.Threading.Tasks; +using API.Constants; +using API.Entities; +using Microsoft.AspNetCore.Identity; +using Microsoft.Extensions.Logging; + +namespace API.Data.ManualMigrations; + +/// <summary> +/// Added in v0.7.1.18 +/// </summary> +public static class MigrateLoginRoles +{ +    /// <summary> +    /// Will not run if any users have the <see cref="PolicyConstants.LoginRole"/> role already +    /// </summary> +    /// <param name="unitOfWork"></param> +    /// <param name="userManager"></param> +    /// <param name="logger"></param> +    public static async Task Migrate(IUnitOfWork unitOfWork, UserManager<AppUser> userManager, ILogger<Program> logger) +    { +        var usersWithRole = await userManager.GetUsersInRoleAsync(PolicyConstants.LoginRole); +        if (usersWithRole.Count != 0) return; + +        logger.LogCritical("Running MigrateLoginRoles migration"); + +        var allUsers = await unitOfWork.UserRepository.GetAllUsersAsync(); +        foreach (var user in allUsers) +        { +            await userManager.RemoveFromRoleAsync(user, PolicyConstants.LoginRole); +            await userManager.AddToRoleAsync(user, PolicyConstants.LoginRole); +        } + +        logger.LogInformation("MigrateLoginRoles migration complete"); +    } +} diff --git a/API/Data/ManualMigrations/MigrateRemoveWebPSettingRows.cs b/API/Data/ManualMigrations/MigrateRemoveWebPSettingRows.cs new file mode 100644 index 00000000..07e98ef6 --- /dev/null +++ b/API/Data/ManualMigrations/MigrateRemoveWebPSettingRows.cs @@ -0,0 +1,31 @@ +using System.Threading.Tasks; +using API.Entities.Enums; +using Microsoft.Extensions.Logging; + +namespace API.Data.ManualMigrations; + +/// <summary> +/// Added in v0.7.2.7/v0.7.3 in which the ConvertXToWebP Setting keys were removed. This migration will remove them. +/// </summary> +public static class MigrateRemoveWebPSettingRows +{ +    public static async Task Migrate(IUnitOfWork unitOfWork, ILogger<Program> logger) +    { +        logger.LogCritical("Running MigrateRemoveWebPSettingRows migration - Please be patient, this may take some time. This is not an error"); + +        var key = await unitOfWork.SettingsRepository.GetSettingAsync(ServerSettingKey.ConvertBookmarkToWebP); +        var key2 = await unitOfWork.SettingsRepository.GetSettingAsync(ServerSettingKey.ConvertCoverToWebP); +        if (key == null && key2 == null) +        { +            logger.LogCritical("Running MigrateRemoveWebPSettingRows migration - complete. Nothing to do"); +            return; +        } + +        unitOfWork.SettingsRepository.Remove(key); +        unitOfWork.SettingsRepository.Remove(key2); + +        await unitOfWork.CommitAsync(); + +        logger.LogCritical("Running MigrateRemoveWebPSettingRows migration - Completed. This is not an error"); +    } +} diff --git a/API/Startup.cs b/API/Startup.cs index 21c4fa45..04f4a077 100644 --- a/API/Startup.cs +++ b/API/Startup.cs @@ -232,11 +232,19 @@ public class Startup Task.Run(async () => { // Apply all migrations on startup +                    var userManager = serviceProvider.GetRequiredService<UserManager<AppUser>>(); var dataContext = serviceProvider.GetRequiredService<DataContext>(); logger.LogInformation("Running Migrations"); +                    // v0.7.2 +                    await MigrateLoginRoles.Migrate(unitOfWork, userManager, logger); +                    // v0.7.3 +                    await MigrateRemoveWebPSettingRows.Migrate(unitOfWork, logger); +                    // v0.7.4 +                    await MigrateDisableScrobblingOnComicLibraries.Migrate(unitOfWork, dataContext, logger); + // v0.7.9 await MigrateUserLibrarySideNavStream.Migrate(unitOfWork, dataContext, logger); </ins>

Discussion:
After updating from kavita v0.7.1.4 to v0.7.13 via , I got a message that my user was disabled. updating at most two versions at a time because database migrations . Steps to reproduce the behavior: up older kavita version, e.g., v0.7.1.4 to v0.7.13 All migrations are handled on update. If applicable, add screenshots to help explain your problem. Add any other context about the problem here. <!-- Please @ people who are in the list of the offending package or module. If in doubt, check for whoever last touched something. -- Please run and paste the result. Add a :+1: [reaction] to [issues you find important]. [reaction]: [issues you find important]:
Oof, did not realize migrations didn't work. A bit confused as to how we would go around solving this in nixpkgs. No matter what we do, it seems like it would require manual intervention by the user when choosing the correct upgrade path.