More migrations (#499)

* Make abstract virtual

* Handle nullability on List

* Move migrations into their own folders, add new migration for minor 3.10 versions
This commit is contained in:
Jesse
2025-07-21 21:03:06 +02:00
committed by GitHub
parent 8c58b0a8fa
commit 41756041d4
7 changed files with 79 additions and 9 deletions
@@ -15,7 +15,11 @@ namespace SPTarkov.Server.Core.Migration
JsonObject profile,
IEnumerable<IProfileMigration> previouslyRanMigrations
);
public abstract JsonObject? Migrate(JsonObject profile);
public virtual JsonObject? Migrate(JsonObject profile)
{
return profile;
}
public virtual bool PostMigrate(SptProfile profile)
{
@@ -38,14 +38,15 @@ namespace SPTarkov.Server.Core.Migration.Migrations
{
var profileVersion = GetProfileVersion(profile);
var fromRange = Range.Parse(FromVersion);
var versionMatches = fromRange.IsSatisfied(profileVersion);
var profileVersionMatches = fromRange.IsSatisfied(profileVersion);
var seedNode = profile["characters"]?["pmc"]?["Hideout"]?["Seed"];
// Check if the seed still has it's numeric value, this is not valid anymore
var seedIsNumeric =
seedNode is JsonValue seedValue && seedValue.TryGetValue<long>(out _);
return versionMatches && seedIsNumeric;
return profileVersionMatches && seedIsNumeric;
}
public override JsonObject? Migrate(JsonObject profile)
@@ -54,7 +55,7 @@ namespace SPTarkov.Server.Core.Migration.Migrations
RandomNumberGenerator.GetBytes(16)
);
return profile;
return base.Migrate(profile);
}
}
}
@@ -0,0 +1,62 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json.Nodes;
using System.Threading.Tasks;
using SPTarkov.DI.Annotations;
using SPTarkov.Server.Core.Models.Eft.Profile;
namespace SPTarkov.Server.Core.Migration.Migrations
{
/// <summary>
/// In the minor versions of 3.10 or somewhere in between these properties were added, it's possible that a profile has not updated
/// To these thus never having received them, re-add them here.
/// </summary>
[Injectable]
public class ThreeTenMinorFixes : AbstractProfileMigration
{
public override string FromVersion
{
get { return "~3.10"; }
}
public override string ToVersion
{
get { return "3.11"; }
}
public override string MigrationName
{
get { return "ThreeTenMinorFixes-SPTSharp"; }
}
public override IEnumerable<Type> PrerequisiteMigrations
{
get { return [typeof(HideoutSeed)]; }
}
public override bool CanMigrate(
JsonObject profile,
IEnumerable<IProfileMigration> previouslyRanMigrations
)
{
var cultistRewardsMissing = profile["spt"]?["cultistRewards"] == null;
var friendProfileIdsMissing = profile["friends"] == null;
return cultistRewardsMissing || friendProfileIdsMissing;
}
public override bool PostMigrate(SptProfile profile)
{
if (profile.SptData!.CultistRewards == null)
{
profile.SptData.CultistRewards = [];
}
profile.FriendProfileIds ??= [];
return base.PostMigrate(profile);
}
}
}
@@ -30,7 +30,7 @@ namespace SPTarkov.Server.Core.Migration.Migrations
public override IEnumerable<Type> PrerequisiteMigrations
{
// Requires ThreeTenToThreeEleven on legacy profiles, due to that changing customization for the first time
// Requires ThreeTenToThreeEleven on legacy profiles, due to that adding the customization object for the first time
get { return [typeof(ThreeTenToThreeEleven)]; }
}
@@ -59,7 +59,7 @@ namespace SPTarkov.Server.Core.Migration.Migrations
HandleScavVoice(profile);
}
return profile;
return base.Migrate(profile);
}
private void HandlePmcVoice(JsonObject profileObject)
@@ -65,9 +65,7 @@ namespace SPTarkov.Server.Core.Migration.Migrations
}
}
//Todo: TaskConditionCounters CounterCrafting?
return profile;
return base.Migrate(profile);
}
public override bool PostMigrate(SptProfile profile)
@@ -77,6 +77,11 @@ namespace SPTarkov.Server.Core.Services
$"{profileId} successfully ran profile migration: {ranMigration.MigrationName}"
);
if (sptReadyProfile.SptData!.Migrations is null)
{
sptReadyProfile.SptData.Migrations = [];
}
sptReadyProfile.SptData.Migrations.Add(
ranMigration.MigrationName,
timeUtil.GetTimeStamp()