mirror of
https://github.com/ppy/osu.git
synced 2025-01-28 08:02:55 +08:00
Centralise backup code and also run on skin/settings migrations
This commit is contained in:
parent
2475a62f2d
commit
aa93042aa3
@ -73,15 +73,7 @@ namespace osu.Game.Database
|
|||||||
{
|
{
|
||||||
Logger.Log($"Found {count} beatmaps in EF", LoggingTarget.Database);
|
Logger.Log($"Found {count} beatmaps in EF", LoggingTarget.Database);
|
||||||
|
|
||||||
if (!hasTakenBackup)
|
ensureBackup();
|
||||||
{
|
|
||||||
string migration = $"before_beatmap_migration_{DateTimeOffset.UtcNow.ToUnixTimeSeconds()}";
|
|
||||||
|
|
||||||
efContextFactory.CreateBackup($"client.{migration}.db");
|
|
||||||
realmContextFactory.CreateBackup($"client.{migration}.realm");
|
|
||||||
|
|
||||||
hasTakenBackup = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// only migrate data if the realm database is empty.
|
// only migrate data if the realm database is empty.
|
||||||
// note that this cannot be written as: `realm.All<BeatmapSetInfo>().All(s => s.Protected)`, because realm does not support `.All()`.
|
// note that this cannot be written as: `realm.All<BeatmapSetInfo>().All(s => s.Protected)`, because realm does not support `.All()`.
|
||||||
@ -201,15 +193,7 @@ namespace osu.Game.Database
|
|||||||
{
|
{
|
||||||
Logger.Log($"Found {count} scores in EF", LoggingTarget.Database);
|
Logger.Log($"Found {count} scores in EF", LoggingTarget.Database);
|
||||||
|
|
||||||
if (!hasTakenBackup)
|
ensureBackup();
|
||||||
{
|
|
||||||
string migration = $"before_score_migration_{DateTimeOffset.UtcNow.ToUnixTimeSeconds()}";
|
|
||||||
|
|
||||||
efContextFactory.CreateBackup($"client.{migration}.db");
|
|
||||||
realmContextFactory.CreateBackup($"client.{migration}.realm");
|
|
||||||
|
|
||||||
hasTakenBackup = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// only migrate data if the realm database is empty.
|
// only migrate data if the realm database is empty.
|
||||||
if (realm.All<ScoreInfo>().Any())
|
if (realm.All<ScoreInfo>().Any())
|
||||||
@ -272,6 +256,8 @@ namespace osu.Game.Database
|
|||||||
if (!existingSkins.Any())
|
if (!existingSkins.Any())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
ensureBackup();
|
||||||
|
|
||||||
var userSkinChoice = config.GetBindable<string>(OsuSetting.Skin);
|
var userSkinChoice = config.GetBindable<string>(OsuSetting.Skin);
|
||||||
int.TryParse(userSkinChoice.Value, out int userSkinInt);
|
int.TryParse(userSkinChoice.Value, out int userSkinInt);
|
||||||
|
|
||||||
@ -342,6 +328,7 @@ namespace osu.Game.Database
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
Logger.Log("Beginning settings migration to realm", LoggingTarget.Database);
|
Logger.Log("Beginning settings migration to realm", LoggingTarget.Database);
|
||||||
|
ensureBackup();
|
||||||
|
|
||||||
using (var realm = realmContextFactory.CreateContext())
|
using (var realm = realmContextFactory.CreateContext())
|
||||||
using (var transaction = realm.BeginWrite())
|
using (var transaction = realm.BeginWrite())
|
||||||
@ -377,5 +364,18 @@ 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;
|
||||||
|
|
||||||
|
private void ensureBackup()
|
||||||
|
{
|
||||||
|
if (!hasTakenBackup)
|
||||||
|
{
|
||||||
|
string migration = $"before_final_migration_{DateTimeOffset.UtcNow.ToUnixTimeSeconds()}";
|
||||||
|
|
||||||
|
efContextFactory.CreateBackup($"client.{migration}.db");
|
||||||
|
realmContextFactory.CreateBackup($"client.{migration}.realm");
|
||||||
|
|
||||||
|
hasTakenBackup = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user