From c1a817fec607aa2577fab9ebf7223b352020d33e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Fri, 1 Sep 2023 07:47:07 +0200 Subject: [PATCH] Add `LegacyOnlineID` with backwards migration --- osu.Game/Database/RealmAccess.cs | 21 ++++++++++++++++++++- osu.Game/Scoring/ScoreInfo.cs | 16 ++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/osu.Game/Database/RealmAccess.cs b/osu.Game/Database/RealmAccess.cs index cd97bb6430..12d1753b9b 100644 --- a/osu.Game/Database/RealmAccess.cs +++ b/osu.Game/Database/RealmAccess.cs @@ -84,8 +84,9 @@ public class RealmAccess : IDisposable /// 32 2023-07-09 Populate legacy scores with the ScoreV2 mod (and restore TotalScore to the legacy total for such scores) using replay files. /// 33 2023-08-16 Reset default chat toggle key binding to avoid conflict with newly added leaderboard toggle key binding. /// 34 2023-08-21 Add BackgroundReprocessingFailed flag to ScoreInfo to track upgrade failures. + /// 35 2023-09-01 Add LegacyOnlineID to ScoreInfo. Move osu_scores_*_high IDs stored in OnlineID to LegacyOnlineID. Reset anomalous OnlineIDs. /// - private const int schema_version = 34; + private const int schema_version = 35; /// /// Lock object which is held during sections, blocking realm retrieval during blocking periods. @@ -1031,6 +1032,24 @@ void convertOnlineIDs() where T : RealmObject break; } + + case 35: + { + foreach (var score in migration.NewRealm.All()) + { + if (score.OnlineID > 0) + { + score.LegacyOnlineID = score.OnlineID; + score.OnlineID = -1; + } + else + { + score.LegacyOnlineID = score.OnlineID = -1; + } + } + + break; + } } Logger.Log($"Migration completed in {stopwatch.ElapsedMilliseconds}ms"); diff --git a/osu.Game/Scoring/ScoreInfo.cs b/osu.Game/Scoring/ScoreInfo.cs index 8531408555..992271d072 100644 --- a/osu.Game/Scoring/ScoreInfo.cs +++ b/osu.Game/Scoring/ScoreInfo.cs @@ -100,9 +100,25 @@ public class ScoreInfo : RealmObject, IHasGuidPrimaryKey, IHasRealmFiles, ISoftD public double? PP { get; set; } + /// + /// The online ID of this score. + /// + /// + /// In the osu-web database, this ID (if present) comes from the new solo_scores table. + /// [Indexed] public long OnlineID { get; set; } = -1; + /// + /// The legacy online ID of this score. + /// + /// + /// In the osu-web database, this ID (if present) comes from the legacy osu_scores_*_high tables. + /// This ID is also stored to replays set on osu!stable. + /// + [Indexed] + public long LegacyOnlineID { get; set; } = -1; + [MapTo("User")] public RealmUser RealmUser { get; set; } = null!;