Add more logging output

This commit is contained in:
Dean Herbert 2017-10-20 08:01:45 +09:00
parent 0e1328a30e
commit ca78078436
2 changed files with 19 additions and 6 deletions

View File

@ -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)
{
}
}
}

View File

@ -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;
}
}