mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 14:17:26 +08:00
Backup collections alongside main databases when migrating to realm
This commit is contained in:
parent
aa93042aa3
commit
fad66d7682
@ -2,9 +2,11 @@
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using osu.Framework.Logging;
|
||||
using osu.Framework.Platform;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Configuration;
|
||||
using osu.Game.Models;
|
||||
@ -22,14 +24,16 @@ namespace osu.Game.Database
|
||||
private readonly DatabaseContextFactory efContextFactory;
|
||||
private readonly RealmContextFactory realmContextFactory;
|
||||
private readonly OsuConfigManager config;
|
||||
private readonly Storage storage;
|
||||
|
||||
private bool hasTakenBackup;
|
||||
|
||||
public EFToRealmMigrator(DatabaseContextFactory efContextFactory, RealmContextFactory realmContextFactory, OsuConfigManager config)
|
||||
public EFToRealmMigrator(DatabaseContextFactory efContextFactory, RealmContextFactory realmContextFactory, OsuConfigManager config, Storage storage)
|
||||
{
|
||||
this.efContextFactory = efContextFactory;
|
||||
this.realmContextFactory = realmContextFactory;
|
||||
this.config = config;
|
||||
this.storage = storage;
|
||||
}
|
||||
|
||||
public void Run()
|
||||
@ -374,6 +378,10 @@ namespace osu.Game.Database
|
||||
efContextFactory.CreateBackup($"client.{migration}.db");
|
||||
realmContextFactory.CreateBackup($"client.{migration}.realm");
|
||||
|
||||
using (var source = storage.GetStream("collection.db"))
|
||||
using (var destination = storage.GetStream($"collection.{migration}.db", FileAccess.Write, FileMode.CreateNew))
|
||||
source.CopyTo(destination);
|
||||
|
||||
hasTakenBackup = true;
|
||||
}
|
||||
}
|
||||
|
@ -195,7 +195,7 @@ namespace osu.Game
|
||||
|
||||
// A non-null context factory means there's still content to migrate.
|
||||
if (efContextFactory != null)
|
||||
new EFToRealmMigrator(efContextFactory, realmFactory, LocalConfig).Run();
|
||||
new EFToRealmMigrator(efContextFactory, realmFactory, LocalConfig, Storage).Run();
|
||||
|
||||
dependencies.CacheAs(Storage);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user