Change migration process to always delete old EF database

It is already backed up, so this is probably fine.
This commit is contained in:
Dean Herbert 2022-01-27 14:33:44 +09:00
parent de5ac7ad83
commit deb5d75b5f
1 changed files with 36 additions and 8 deletions

View File

@ -15,6 +15,8 @@
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using osu.Game.Models;
using osu.Game.Overlays;
using osu.Game.Overlays.Notifications;
using osu.Game.Rulesets;
using osu.Game.Scoring;
using osu.Game.Skinning;
@ -40,6 +42,12 @@ internal class EFToRealmMigrator : CompositeDrawable
[Resolved]
private OsuConfigManager config { get; set; } = null!;
[Resolved]
private NotificationOverlay notificationOverlay { get; set; } = null!;
[Resolved]
private OsuGame game { get; set; } = null!;
private readonly OsuSpriteText currentOperationText;
public EFToRealmMigrator()
@ -96,7 +104,11 @@ public EFToRealmMigrator()
protected override void LoadComplete()
{
base.LoadComplete();
beginMigration();
}
private void beginMigration()
{
Task.Factory.StartNew(() =>
{
using (var ef = efContextFactory.Get())
@ -117,21 +129,37 @@ protected override void LoadComplete()
migrateBeatmaps(ef);
migrateScores(ef);
}
// Delete the database permanently.
// Will cause future startups to not attempt migration.
log("Migration successful, deleting EF database");
efContextFactory.ResetDatabase();
if (DebugUtils.IsDebugBuild)
Logger.Log("Your development database has been fully migrated to realm. If you switch back to a pre-realm branch and need your previous database, rename the backup file back to \"client.db\".\n\nNote that doing this can potentially leave your file store in a bad state.", level: LogLevel.Important);
}, TaskCreationOptions.LongRunning).ContinueWith(t =>
{
if (t.Exception == null)
{
log("Migration successful!");
if (DebugUtils.IsDebugBuild)
Logger.Log("Your development database has been fully migrated to realm. If you switch back to a pre-realm branch and need your previous database, rename the backup file back to \"client.db\".\n\nNote that doing this can potentially leave your file store in a bad state.", level: LogLevel.Important);
}
else
{
log("Migration failed!");
Logger.Log(t.Exception.ToString(), LoggingTarget.Database);
}
// Regardless of success, since the game is going to continue with startup let's move the ef database out of the way.
// If we were to not do this, the migration would run another time the next time the user starts the game.
deletePreRealmData();
migrationCompleted.SetResult(true);
efContextFactory.SetMigrationCompletion();
});
}
private void deletePreRealmData()
{
// Delete the database permanently.
// Will cause future startups to not attempt migration.
efContextFactory.ResetDatabase();
}
private void log(string message)
{
Logger.Log(message, LoggingTarget.Database);