mirror of
https://github.com/ppy/osu.git
synced 2025-02-12 21:02:59 +08:00
Also backup the realm database before migration
This commit is contained in:
parent
2b1c15b6cc
commit
bf50a9b8f8
@ -75,6 +75,9 @@ namespace osu.Game.Database
|
||||
if (!realm.All<BeatmapSetInfo>().Any(s => !s.Protected))
|
||||
{
|
||||
Logger.Log($"Migrating {existingBeatmapSets.Count} beatmaps", LoggingTarget.Database);
|
||||
string migration = $"before_beatmap_migration_{DateTimeOffset.UtcNow.ToUnixTimeSeconds()}";
|
||||
realmContextFactory.CreateBackup($"client.{migration}.realm");
|
||||
efContextFactory.CreateBackup($"client.{migration}.db");
|
||||
|
||||
foreach (var beatmapSet in existingBeatmapSets)
|
||||
{
|
||||
@ -131,7 +134,6 @@ namespace osu.Game.Database
|
||||
}
|
||||
}
|
||||
|
||||
efContextFactory.CreateBackup($"client.before_beatmap_migration_{DateTimeOffset.UtcNow.ToUnixTimeSeconds()}.db");
|
||||
ef.Context.RemoveRange(existingBeatmapSets);
|
||||
// Intentionally don't clean up the files, so they don't get purged by EF.
|
||||
|
||||
@ -187,6 +189,9 @@ namespace osu.Game.Database
|
||||
if (!realm.All<ScoreInfo>().Any())
|
||||
{
|
||||
Logger.Log($"Migrating {existingScores.Count} scores", LoggingTarget.Database);
|
||||
string migration = $"before_score_migration_{DateTimeOffset.UtcNow.ToUnixTimeSeconds()}";
|
||||
realmContextFactory.CreateBackup($"client.{migration}.realm");
|
||||
efContextFactory.CreateBackup($"client.{migration}.db");
|
||||
|
||||
foreach (var score in existingScores)
|
||||
{
|
||||
@ -222,7 +227,6 @@ namespace osu.Game.Database
|
||||
}
|
||||
}
|
||||
|
||||
efContextFactory.CreateBackup($"client.before_scores_migration_{DateTimeOffset.UtcNow.ToUnixTimeSeconds()}.db");
|
||||
db.Context.RemoveRange(existingScores);
|
||||
// Intentionally don't clean up the files, so they don't get purged by EF.
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
@ -353,6 +354,16 @@ namespace osu.Game.Database
|
||||
private string? getRulesetShortNameFromLegacyID(long rulesetId) =>
|
||||
efContextFactory?.Get().RulesetInfo.FirstOrDefault(r => r.ID == rulesetId)?.ShortName;
|
||||
|
||||
public void CreateBackup(string filename)
|
||||
{
|
||||
using (BlockAllOperations())
|
||||
{
|
||||
using (var source = storage.GetStream(Filename))
|
||||
using (var destination = storage.GetStream(filename, FileAccess.Write, FileMode.CreateNew))
|
||||
source.CopyTo(destination);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Flush any active contexts and block any further writes.
|
||||
/// </summary>
|
||||
|
Loading…
Reference in New Issue
Block a user