mirror of
https://github.com/ppy/osu.git
synced 2024-11-06 06:57:39 +08:00
Rely on storage.DeleteDatabase for guaranteed database deletion
Relies on https://github.com/ppy/osu-framework/pull/1100 being merged for most effectiveness.
This commit is contained in:
parent
b805174143
commit
47213d2498
@ -9,11 +9,19 @@ namespace osu.Game.Database
|
||||
{
|
||||
private readonly GameHost host;
|
||||
|
||||
private const string database_name = @"client";
|
||||
|
||||
public DatabaseContextFactory(GameHost host)
|
||||
{
|
||||
this.host = host;
|
||||
}
|
||||
|
||||
public OsuDbContext GetContext() => new OsuDbContext(host.Storage.GetDatabaseConnectionString(@"client"));
|
||||
public OsuDbContext GetContext() => new OsuDbContext(host.Storage.GetDatabaseConnectionString(database_name));
|
||||
|
||||
public void ResetDatabase()
|
||||
{
|
||||
// todo: we probably want to make sure there are no active contexts before performing this operation.
|
||||
host.Storage.DeleteDatabase(database_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -177,22 +177,8 @@ namespace osu.Game
|
||||
|
||||
// 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();
|
||||
Logger.Log("Database purged successfully.", LoggingTarget.Database, LogLevel.Important);
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
contextFactory.ResetDatabase();
|
||||
Logger.Log("Database purged successfully.", LoggingTarget.Database, LogLevel.Important);
|
||||
|
||||
using (var context = contextFactory.GetContext())
|
||||
context.Migrate();
|
||||
|
Loading…
Reference in New Issue
Block a user