mirror of
https://github.com/ppy/osu.git
synced 2025-02-19 14:42:56 +08:00
Avoid taking more than one backup per migration run
This commit is contained in:
parent
6b0bf38c93
commit
64a023665e
@ -24,6 +24,8 @@ namespace osu.Game.Database
|
|||||||
private readonly RealmContextFactory realmContextFactory;
|
private readonly RealmContextFactory realmContextFactory;
|
||||||
private readonly OsuConfigManager config;
|
private readonly OsuConfigManager config;
|
||||||
|
|
||||||
|
private bool hasTakenBackup;
|
||||||
|
|
||||||
public EFToRealmMigrator(DatabaseContextFactory efContextFactory, RealmContextFactory realmContextFactory, OsuConfigManager config)
|
public EFToRealmMigrator(DatabaseContextFactory efContextFactory, RealmContextFactory realmContextFactory, OsuConfigManager config)
|
||||||
{
|
{
|
||||||
this.efContextFactory = efContextFactory;
|
this.efContextFactory = efContextFactory;
|
||||||
@ -70,8 +72,16 @@ namespace osu.Game.Database
|
|||||||
using (var realm = realmContextFactory.CreateContext())
|
using (var realm = realmContextFactory.CreateContext())
|
||||||
{
|
{
|
||||||
Logger.Log($"Found {existingBeatmapSets.Count} beatmaps in EF", LoggingTarget.Database);
|
Logger.Log($"Found {existingBeatmapSets.Count} beatmaps in EF", LoggingTarget.Database);
|
||||||
|
|
||||||
|
if (!hasTakenBackup)
|
||||||
|
{
|
||||||
string migration = $"before_beatmap_migration_{DateTimeOffset.UtcNow.ToUnixTimeSeconds()}";
|
string migration = $"before_beatmap_migration_{DateTimeOffset.UtcNow.ToUnixTimeSeconds()}";
|
||||||
|
|
||||||
efContextFactory.CreateBackup($"client.{migration}.db");
|
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<BeatmapInfo>().All(s => s.Protected)`, because realm does not support `.All()`.
|
// note that this cannot be written as: `realm.All<BeatmapInfo>().All(s => s.Protected)`, because realm does not support `.All()`.
|
||||||
@ -81,8 +91,6 @@ namespace osu.Game.Database
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
realmContextFactory.CreateBackup($"client.{migration}.realm");
|
|
||||||
|
|
||||||
using (var transaction = realm.BeginWrite())
|
using (var transaction = realm.BeginWrite())
|
||||||
{
|
{
|
||||||
foreach (var beatmapSet in existingBeatmapSets)
|
foreach (var beatmapSet in existingBeatmapSets)
|
||||||
@ -195,8 +203,16 @@ namespace osu.Game.Database
|
|||||||
using (var realm = realmContextFactory.CreateContext())
|
using (var realm = realmContextFactory.CreateContext())
|
||||||
{
|
{
|
||||||
Logger.Log($"Found {existingScores.Count} scores in EF", LoggingTarget.Database);
|
Logger.Log($"Found {existingScores.Count} scores in EF", LoggingTarget.Database);
|
||||||
|
|
||||||
|
if (!hasTakenBackup)
|
||||||
|
{
|
||||||
string migration = $"before_score_migration_{DateTimeOffset.UtcNow.ToUnixTimeSeconds()}";
|
string migration = $"before_score_migration_{DateTimeOffset.UtcNow.ToUnixTimeSeconds()}";
|
||||||
|
|
||||||
efContextFactory.CreateBackup($"client.{migration}.db");
|
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<ScoreInfo>().All(s => s.Protected)`, because realm does not support `.All()`.
|
// note that this cannot be written as: `realm.All<ScoreInfo>().All(s => s.Protected)`, because realm does not support `.All()`.
|
||||||
@ -206,8 +222,6 @@ namespace osu.Game.Database
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
realmContextFactory.CreateBackup($"client.{migration}.realm");
|
|
||||||
|
|
||||||
using (var transaction = realm.BeginWrite())
|
using (var transaction = realm.BeginWrite())
|
||||||
{
|
{
|
||||||
foreach (var score in existingScores)
|
foreach (var score in existingScores)
|
||||||
|
Loading…
Reference in New Issue
Block a user