mirror of
https://github.com/ppy/osu.git
synced 2025-01-28 05:22:54 +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 current version of this store. Used for migrations (see <see cref="PerformMigration(int, int)"/>).
|
||||||
/// The initial version is 1.
|
/// The initial version is 1.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected override int StoreVersion => 1;
|
protected override int StoreVersion => 2;
|
||||||
|
|
||||||
public BeatmapStore(SQLiteConnection connection)
|
public BeatmapStore(SQLiteConnection connection)
|
||||||
: base(connection)
|
: base(connection)
|
||||||
@ -74,14 +74,9 @@ namespace osu.Game.Beatmaps
|
|||||||
switch (currentVersion)
|
switch (currentVersion)
|
||||||
{
|
{
|
||||||
case 1:
|
case 1:
|
||||||
// initialising from a version before we had versioning (or a fresh install).
|
case 2:
|
||||||
|
// cannot migrate; breaking underlying changes.
|
||||||
// force adding of Protected column (not automatically migrated).
|
Reset();
|
||||||
Connection.MigrateTable<BeatmapSetInfo>();
|
|
||||||
|
|
||||||
// remove all existing beatmaps.
|
|
||||||
foreach (var b in Connection.GetAllWithChildren<BeatmapSetInfo>(null, true))
|
|
||||||
Connection.Delete(b, true);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,8 @@ namespace osu.Game.IO
|
|||||||
|
|
||||||
public readonly ResourceStore<byte[]> Store;
|
public readonly ResourceStore<byte[]> Store;
|
||||||
|
|
||||||
|
protected override int StoreVersion => 2;
|
||||||
|
|
||||||
public FileStore(SQLiteConnection connection, Storage storage) : base(connection, storage)
|
public FileStore(SQLiteConnection connection, Storage storage) : base(connection, storage)
|
||||||
{
|
{
|
||||||
Store = new NamespacedResourceStore<byte[]>(new StorageBackedResourceStore(storage), prefix);
|
Store = new NamespacedResourceStore<byte[]>(new StorageBackedResourceStore(storage), prefix);
|
||||||
@ -35,7 +37,19 @@ namespace osu.Game.IO
|
|||||||
protected override void Prepare(bool reset = false)
|
protected override void Prepare(bool reset = false)
|
||||||
{
|
{
|
||||||
if (reset)
|
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.DropTable<FileInfo>();
|
||||||
|
}
|
||||||
|
|
||||||
Connection.CreateTable<FileInfo>();
|
Connection.CreateTable<FileInfo>();
|
||||||
}
|
}
|
||||||
@ -46,6 +60,28 @@ namespace osu.Game.IO
|
|||||||
deletePending();
|
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)
|
public FileInfo Add(Stream data)
|
||||||
{
|
{
|
||||||
string hash = data.ComputeSHA2Hash();
|
string hash = data.ComputeSHA2Hash();
|
||||||
|
Loading…
Reference in New Issue
Block a user