From 0e1328a30eb0ef949abec7f90a8422073607d36b Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 20 Oct 2017 08:01:38 +0900 Subject: [PATCH] Add maximum try count before bailing --- osu.Game/OsuGameBase.cs | 55 ++++++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 22 deletions(-) diff --git a/osu.Game/OsuGameBase.cs b/osu.Game/OsuGameBase.cs index 4a80a0fa06..de9ed70ac9 100644 --- a/osu.Game/OsuGameBase.cs +++ b/osu.Game/OsuGameBase.cs @@ -90,28 +90,7 @@ namespace osu.Game dependencies.Cache(this); dependencies.Cache(LocalConfig); - try - { - using (var context = contextFactory.GetContext()) - context.Migrate(); - } - catch (MigrationFailedException) - { - while (true) - { - try - { - using (var context = contextFactory.GetContext()) - { - context.Database.EnsureDeleted(); - break; - } - } - catch { } - } - using (var context = contextFactory.GetContext()) - context.Migrate(); - } + runMigrations(); dependencies.Cache(API = new APIAccess { @@ -183,6 +162,38 @@ namespace osu.Game FileStore.Cleanup(); } + private void runMigrations() + { + try + { + using (var context = contextFactory.GetContext()) + context.Migrate(); + } + catch (MigrationFailedException) + { + // if we failed, let's delete the database and start fresh. + // todo: we probably want a better (non-destructive) migrations/recovery process at a later point than this. + int retries = 20; + while (retries-- > 0) + { + try + { + using (var context = contextFactory.GetContext()) + { + context.Database.EnsureDeleted(); + break; + } + } + catch + { + } + } + + using (var context = contextFactory.GetContext()) + context.Migrate(); + } + } + private WorkingBeatmap lastBeatmap; public void APIStateChanged(APIAccess api, APIState state)