diff --git a/osu.Game/Database/OsuDbContext.cs b/osu.Game/Database/OsuDbContext.cs index 1e3d76789d..bfa3c0a81b 100644 --- a/osu.Game/Database/OsuDbContext.cs +++ b/osu.Game/Database/OsuDbContext.cs @@ -160,13 +160,14 @@ public bool IsEnabled(LogLevel logLevel) public void Migrate() { migrateFromSqliteNet(); + try { Database.Migrate(); } - catch + catch (Exception e) { - throw new MigrationFailedException(); + throw new MigrationFailedException(e); } } @@ -186,6 +187,8 @@ private void migrateFromSqliteNet() try { + Logger.Log("Performing migration from sqlite-net to EF...", LoggingTarget.Database, Framework.Logging.LogLevel.Important); + // we are good to perform messy migration of data!. Database.ExecuteSqlCommand("ALTER TABLE BeatmapDifficulty RENAME TO BeatmapDifficulty_Old"); Database.ExecuteSqlCommand("ALTER TABLE BeatmapMetadata RENAME TO BeatmapMetadata_Old"); @@ -228,11 +231,12 @@ private void migrateFromSqliteNet() Database.ExecuteSqlCommand( "INSERT INTO BeatmapInfo SELECT ID, AudioLeadIn, BaseDifficultyID, BeatDivisor, BeatmapSetInfoID, Countdown, DistanceSpacing, GridSize, Hash, IFNULL(Hidden, 0), LetterboxInBreaks, MD5Hash, NULLIF(BeatmapMetadataID, 0), OnlineBeatmapID, Path, RulesetID, SpecialStyle, StackLeniency, StarDifficulty, StoredBookmarks, TimelineZoom, Version, WidescreenStoryboard FROM BeatmapInfo_Old"); Database.ExecuteSqlCommand("DROP TABLE BeatmapInfo_Old"); + + Logger.Log("Migration complete!", LoggingTarget.Database, Framework.Logging.LogLevel.Important); } - catch + catch (Exception e) { - // if anything went wrong during migration just nuke the database. - throw new MigrationFailedException(); + throw new MigrationFailedException(e); } } catch (MigrationFailedException e) @@ -248,5 +252,9 @@ private void migrateFromSqliteNet() public class MigrationFailedException : Exception { + public MigrationFailedException(Exception exception) + : base("sqlite-net migration failed", exception) + { + } } } diff --git a/osu.Game/OsuGameBase.cs b/osu.Game/OsuGameBase.cs index de9ed70ac9..0d575c52d0 100644 --- a/osu.Game/OsuGameBase.cs +++ b/osu.Game/OsuGameBase.cs @@ -17,6 +17,7 @@ using osu.Game.Graphics.Cursor; using osu.Game.Online.API; using osu.Framework.Graphics.Performance; +using osu.Framework.Logging; using osu.Game.Database; using osu.Game.Input; using osu.Game.Input.Bindings; @@ -169,8 +170,11 @@ private void runMigrations() using (var context = contextFactory.GetContext()) context.Migrate(); } - catch (MigrationFailedException) + catch (MigrationFailedException e) { + Logger.Log(e.ToString(), LoggingTarget.Database, LogLevel.Error); + Logger.Log("Migration failed! We'll be starting with a fresh database.", LoggingTarget.Database, LogLevel.Error); + // 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; @@ -181,6 +185,7 @@ private void runMigrations() using (var context = contextFactory.GetContext()) { context.Database.EnsureDeleted(); + Logger.Log("Database purged successfully.", LoggingTarget.Database, LogLevel.Important); break; } }