mirror of
https://github.com/ppy/osu.git
synced 2024-11-06 09:07:25 +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 readonly GameHost host;
|
||||||
|
|
||||||
|
private const string database_name = @"client";
|
||||||
|
|
||||||
public DatabaseContextFactory(GameHost host)
|
public DatabaseContextFactory(GameHost host)
|
||||||
{
|
{
|
||||||
this.host = 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.
|
// 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.
|
// todo: we probably want a better (non-destructive) migrations/recovery process at a later point than this.
|
||||||
int retries = 20;
|
contextFactory.ResetDatabase();
|
||||||
while (retries-- > 0)
|
Logger.Log("Database purged successfully.", LoggingTarget.Database, LogLevel.Important);
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
using (var context = contextFactory.GetContext())
|
|
||||||
{
|
|
||||||
context.Database.EnsureDeleted();
|
|
||||||
Logger.Log("Database purged successfully.", LoggingTarget.Database, LogLevel.Important);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
using (var context = contextFactory.GetContext())
|
using (var context = contextFactory.GetContext())
|
||||||
context.Migrate();
|
context.Migrate();
|
||||||
|
Loading…
Reference in New Issue
Block a user