mirror of
https://github.com/ppy/osu.git
synced 2025-03-28 09:37:23 +08:00
Create backups before deleting scores and beatmaps from EF database
This commit is contained in:
parent
b1a75ce480
commit
798482c941
@ -1,6 +1,7 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using Microsoft.EntityFrameworkCore.Storage;
|
using Microsoft.EntityFrameworkCore.Storage;
|
||||||
@ -144,6 +145,13 @@ namespace osu.Game.Database
|
|||||||
Database = { AutoTransactionsEnabled = false }
|
Database = { AutoTransactionsEnabled = false }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public void CreateBackup(string filename)
|
||||||
|
{
|
||||||
|
using (var source = storage.GetStream(DATABASE_NAME))
|
||||||
|
using (var destination = storage.GetStream(filename, FileAccess.Write, FileMode.CreateNew))
|
||||||
|
source.CopyTo(destination);
|
||||||
|
}
|
||||||
|
|
||||||
public void ResetDatabase()
|
public void ResetDatabase()
|
||||||
{
|
{
|
||||||
lock (writeLock)
|
lock (writeLock)
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
@ -31,13 +33,16 @@ namespace osu.Game.Database
|
|||||||
public void Run()
|
public void Run()
|
||||||
{
|
{
|
||||||
using (var ef = efContextFactory.GetForWrite())
|
using (var ef = efContextFactory.GetForWrite())
|
||||||
{
|
|
||||||
migrateSettings(ef);
|
migrateSettings(ef);
|
||||||
|
|
||||||
|
using (var ef = efContextFactory.GetForWrite())
|
||||||
migrateSkins(ef);
|
migrateSkins(ef);
|
||||||
|
|
||||||
|
using (var ef = efContextFactory.GetForWrite())
|
||||||
migrateBeatmaps(ef);
|
migrateBeatmaps(ef);
|
||||||
|
|
||||||
|
using (var ef = efContextFactory.GetForWrite())
|
||||||
migrateScores(ef);
|
migrateScores(ef);
|
||||||
}
|
|
||||||
|
|
||||||
// Delete the database permanently.
|
// Delete the database permanently.
|
||||||
// Will cause future startups to not attempt migration.
|
// Will cause future startups to not attempt migration.
|
||||||
@ -47,13 +52,13 @@ namespace osu.Game.Database
|
|||||||
private void migrateBeatmaps(DatabaseWriteUsage ef)
|
private void migrateBeatmaps(DatabaseWriteUsage ef)
|
||||||
{
|
{
|
||||||
// can be removed 20220730.
|
// can be removed 20220730.
|
||||||
var existingBeatmapSets = ef.Context.EFBeatmapSetInfo
|
List<EFBeatmapSetInfo> existingBeatmapSets = ef.Context.EFBeatmapSetInfo
|
||||||
.Include(s => s.Beatmaps).ThenInclude(b => b.RulesetInfo)
|
.Include(s => s.Beatmaps).ThenInclude(b => b.RulesetInfo)
|
||||||
.Include(s => s.Beatmaps).ThenInclude(b => b.Metadata)
|
.Include(s => s.Beatmaps).ThenInclude(b => b.Metadata)
|
||||||
.Include(s => s.Beatmaps).ThenInclude(b => b.BaseDifficulty)
|
.Include(s => s.Beatmaps).ThenInclude(b => b.BaseDifficulty)
|
||||||
.Include(s => s.Files).ThenInclude(f => f.FileInfo)
|
.Include(s => s.Files).ThenInclude(f => f.FileInfo)
|
||||||
.Include(s => s.Metadata)
|
.Include(s => s.Metadata)
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
// previous entries in EF are removed post migration.
|
// previous entries in EF are removed post migration.
|
||||||
if (!existingBeatmapSets.Any())
|
if (!existingBeatmapSets.Any())
|
||||||
@ -121,6 +126,7 @@ namespace osu.Game.Database
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
efContextFactory.CreateBackup($"client.before_beatmap_migration_{DateTimeOffset.UtcNow.ToUnixTimeSeconds()}.db");
|
||||||
ef.Context.RemoveRange(existingBeatmapSets);
|
ef.Context.RemoveRange(existingBeatmapSets);
|
||||||
// Intentionally don't clean up the files, so they don't get purged by EF.
|
// Intentionally don't clean up the files, so they don't get purged by EF.
|
||||||
|
|
||||||
@ -207,6 +213,7 @@ namespace osu.Game.Database
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
efContextFactory.CreateBackup($"client.before_scores_migration_{DateTimeOffset.UtcNow.ToUnixTimeSeconds()}.db");
|
||||||
db.Context.RemoveRange(existingScores);
|
db.Context.RemoveRange(existingScores);
|
||||||
// Intentionally don't clean up the files, so they don't get purged by EF.
|
// Intentionally don't clean up the files, so they don't get purged by EF.
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user