2025-12-18 10:57:26 +11:00
|
|
|
using LANCommander.SDK.Helpers;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using Semver;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
2025-12-17 17:09:36 +11:00
|
|
|
namespace LANCommander.SDK.Migrations;
|
|
|
|
|
|
2025-12-18 10:57:26 +11:00
|
|
|
public abstract class FileSystemMigration(ILogger logger) : IMigration
|
2025-12-17 17:09:36 +11:00
|
|
|
{
|
|
|
|
|
public abstract SemVersion Version { get; }
|
|
|
|
|
|
2025-12-18 10:57:26 +11:00
|
|
|
protected ILogger Logger => logger;
|
|
|
|
|
|
|
|
|
|
public Task<bool> PerformPreChecksAsync()
|
2025-12-17 17:09:36 +11:00
|
|
|
{
|
|
|
|
|
logger.LogInformation("Starting file system migration: {MigrationType}", GetType().Name);
|
|
|
|
|
|
2025-12-18 10:57:26 +11:00
|
|
|
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);
|
|
|
|
|
}
|
2025-12-17 17:09:36 +11:00
|
|
|
|
2025-12-18 10:57:26 +11:00
|
|
|
Logger.LogInformation("File system migration pre-move checks passed.");
|
|
|
|
|
return Task.FromResult(true);
|
2025-12-17 17:09:36 +11:00
|
|
|
}
|
|
|
|
|
|
2025-12-18 10:57:26 +11:00
|
|
|
public abstract Task ExecuteAsync();
|
|
|
|
|
|
|
|
|
|
public abstract Task<bool> ShouldExecuteAsync();
|
2025-12-17 17:09:36 +11:00
|
|
|
}
|