Files
SPT-Server-Build/Libraries/SPTarkov.Server.Core/Migration/AbstractProfileMigration.cs
T
Jesse 533a7356fd Add new service to handle profile migrations (#468)
* Add new service to handle profile migrations

* Handle various null checks

* Remove unecessary assignments

* Further works on this:

- Loads profiles as JObject's initally, so migration can take place on profiles that don't have proper compatability
- Adds prerequisite migrations, and sorts them after one another

* Throw exception if profile can't be deserialized after migration

* Cleanup & use profile version

* Further migrations work, support 3.10 & 3.11 profiles upgrading to 4.0

* Update parameter name
2025-07-11 13:11:02 +01:00

42 lines
1.2 KiB
C#

using System.Text.Json.Nodes;
using SPTarkov.Server.Core.Models.Eft.Profile;
namespace SPTarkov.Server.Core.Migration
{
public abstract class AbstractProfileMigration : IProfileMigration
{
public abstract string FromVersion { get; }
public abstract string ToVersion { get; }
public abstract string MigrationName { get; }
public abstract IEnumerable<Type> PrerequisiteMigrations { get; }
public abstract bool CanMigrate(
JsonObject profile,
IEnumerable<IProfileMigration> previouslyRanMigrations
);
public abstract JsonObject? Migrate(JsonObject profile);
public virtual bool PostMigrate(SptProfile profile)
{
return true;
}
protected SemanticVersioning.Version? GetProfileVersion(JsonObject profile)
{
var versionString = profile["spt"]?["version"]?.GetValue<string>();
if (versionString is null)
{
return null;
}
var versionNumber = versionString.Split(' ')[0];
return SemanticVersioning.Version.TryParse(versionNumber, out var version)
? version
: null;
}
}
}