LANCommander/LANCommander.SDK/Migrations/FileSystemMigration.cs
Aaron Powell 8600bae9ec Overhauling the migrations to be a bit more explicit in the steps that they go through.
Changed the IMigration interface to have a series of steps, first a method to indicate that the migration should run, next some pre-checks (like is it in a container), and lastly the actual execution.

Next, the settings and folder migrations are broken into individual migrations, which means that it's a lot more obvious which ones run and which ones are skipped.
2025-12-18 10:57:26 +11:00

31 lines
No EOL
1,022 B
C#

using LANCommander.SDK.Helpers;
using Microsoft.Extensions.Logging;
using Semver;
using System.Threading.Tasks;
namespace LANCommander.SDK.Migrations;
public abstract class FileSystemMigration(ILogger logger) : IMigration
{
public abstract SemVersion Version { get; }
protected ILogger Logger => logger;
public Task<bool> PerformPreChecksAsync()
{
logger.LogInformation("Starting file system migration: {MigrationType}", GetType().Name);
if (EnvironmentHelper.IsRunningInContainer() && !AppPaths.ConfigDirectoryIsMounted())
{
Logger.LogError("Aborting migration to avoid data loss. Application is running in a container but config directory is not mounted.");
return Task.FromResult(false);
}
Logger.LogInformation("File system migration pre-move checks passed.");
return Task.FromResult(true);
}
public abstract Task ExecuteAsync();
public abstract Task<bool> ShouldExecuteAsync();
}