mirror of
https://github.com/ppy/osu.git
synced 2025-01-13 12:53:11 +08:00
Add "migration"
Also simplify initial migration for BeatmapStore by just nuking everything.
This commit is contained in:
parent
c060d32765
commit
c73e139954
@ -21,7 +21,7 @@ namespace osu.Game.Beatmaps
|
||||
/// The current version of this store. Used for migrations (see <see cref="PerformMigration(int, int)"/>).
|
||||
/// The initial version is 1.
|
||||
/// </summary>
|
||||
protected override int StoreVersion => 1;
|
||||
protected override int StoreVersion => 2;
|
||||
|
||||
public BeatmapStore(SQLiteConnection connection)
|
||||
: base(connection)
|
||||
@ -74,14 +74,9 @@ namespace osu.Game.Beatmaps
|
||||
switch (currentVersion)
|
||||
{
|
||||
case 1:
|
||||
// initialising from a version before we had versioning (or a fresh install).
|
||||
|
||||
// force adding of Protected column (not automatically migrated).
|
||||
Connection.MigrateTable<BeatmapSetInfo>();
|
||||
|
||||
// remove all existing beatmaps.
|
||||
foreach (var b in Connection.GetAllWithChildren<BeatmapSetInfo>(null, true))
|
||||
Connection.Delete(b, true);
|
||||
case 2:
|
||||
// cannot migrate; breaking underlying changes.
|
||||
Reset();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -23,6 +23,8 @@ namespace osu.Game.IO
|
||||
|
||||
public readonly ResourceStore<byte[]> Store;
|
||||
|
||||
protected override int StoreVersion => 2;
|
||||
|
||||
public FileStore(SQLiteConnection connection, Storage storage) : base(connection, storage)
|
||||
{
|
||||
Store = new NamespacedResourceStore<byte[]>(new StorageBackedResourceStore(storage), prefix);
|
||||
@ -35,7 +37,19 @@ namespace osu.Game.IO
|
||||
protected override void Prepare(bool reset = false)
|
||||
{
|
||||
if (reset)
|
||||
{
|
||||
try
|
||||
{
|
||||
foreach (var f in Query<FileInfo>())
|
||||
Storage.Delete(Path.Combine(prefix, f.Hash));
|
||||
}
|
||||
catch
|
||||
{
|
||||
// we don't want to ever crash as a result of a reset operation.
|
||||
}
|
||||
|
||||
Connection.DropTable<FileInfo>();
|
||||
}
|
||||
|
||||
Connection.CreateTable<FileInfo>();
|
||||
}
|
||||
@ -46,6 +60,28 @@ namespace osu.Game.IO
|
||||
deletePending();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Perform migrations between two store versions.
|
||||
/// </summary>
|
||||
/// <param name="currentVersion">The current store version. This will be zero on a fresh database initialisation.</param>
|
||||
/// <param name="targetVersion">The target version which we are migrating to (equal to the current <see cref="StoreVersion"/>).</param>
|
||||
protected override void PerformMigration(int currentVersion, int targetVersion)
|
||||
{
|
||||
base.PerformMigration(currentVersion, targetVersion);
|
||||
|
||||
while (currentVersion++ < targetVersion)
|
||||
{
|
||||
switch (currentVersion)
|
||||
{
|
||||
case 1:
|
||||
case 2:
|
||||
// cannot migrate; breaking underlying changes.
|
||||
Reset();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public FileInfo Add(Stream data)
|
||||
{
|
||||
string hash = data.ComputeSHA2Hash();
|
||||
|
Loading…
Reference in New Issue
Block a user