mirror of
https://github.com/osukey/osukey.git
synced 2025-05-21 21:47:31 +09: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))
|
if (!realm.All<BeatmapSetInfo>().Any(s => !s.Protected))
|
||||||
{
|
{
|
||||||
Logger.Log($"Migrating {existingBeatmapSets.Count} beatmaps", LoggingTarget.Database);
|
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)
|
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);
|
ef.Context.RemoveRange(existingBeatmapSets);
|
||||||
// Intentionally don't clean up the files, so they don't get purged by EF.
|
// 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())
|
if (!realm.All<ScoreInfo>().Any())
|
||||||
{
|
{
|
||||||
Logger.Log($"Migrating {existingScores.Count} scores", LoggingTarget.Database);
|
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)
|
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);
|
db.Context.RemoveRange(existingScores);
|
||||||
// Intentionally don't clean up the files, so they don't get purged by EF.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
@ -353,6 +354,16 @@ namespace osu.Game.Database
|
|||||||
private string? getRulesetShortNameFromLegacyID(long rulesetId) =>
|
private string? getRulesetShortNameFromLegacyID(long rulesetId) =>
|
||||||
efContextFactory?.Get().RulesetInfo.FirstOrDefault(r => r.ID == rulesetId)?.ShortName;
|
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>
|
/// <summary>
|
||||||
/// Flush any active contexts and block any further writes.
|
/// Flush any active contexts and block any further writes.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user