mirror of
https://github.com/osukey/osukey.git
synced 2025-08-05 07:33:55 +09:00
Add the ability to create migrations on a per-store level
Now stores store versions to the database itself.
This commit is contained in:
@ -17,6 +17,8 @@ namespace osu.Game.Database
|
||||
protected readonly Storage Storage;
|
||||
protected readonly SQLiteConnection Connection;
|
||||
|
||||
protected virtual int StoreVersion => 1;
|
||||
|
||||
protected DatabaseBackedStore(SQLiteConnection connection, Storage storage = null)
|
||||
{
|
||||
Storage = storage;
|
||||
@ -31,6 +33,28 @@ namespace osu.Game.Database
|
||||
Logger.Error(e, $@"Failed to initialise the {GetType()}! Trying again with a clean database...");
|
||||
Prepare(true);
|
||||
}
|
||||
|
||||
checkMigrations();
|
||||
}
|
||||
|
||||
private void checkMigrations()
|
||||
{
|
||||
var storeName = GetType().Name;
|
||||
|
||||
var reportedVersion = Connection.Table<StoreVersion>().FirstOrDefault(s => s.StoreName == storeName) ?? new StoreVersion
|
||||
{
|
||||
StoreName = storeName,
|
||||
Version = 0
|
||||
};
|
||||
|
||||
if (reportedVersion.Version != StoreVersion)
|
||||
PerformMigration(reportedVersion.Version, reportedVersion.Version = StoreVersion);
|
||||
|
||||
Connection.InsertOrReplace(reportedVersion);
|
||||
}
|
||||
|
||||
protected virtual void PerformMigration(int currentVersion, int newVersion)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
15
osu.Game/Database/StoreVersion.cs
Normal file
15
osu.Game/Database/StoreVersion.cs
Normal file
@ -0,0 +1,15 @@
|
||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using SQLite.Net.Attributes;
|
||||
|
||||
namespace osu.Game.Database
|
||||
{
|
||||
public class StoreVersion
|
||||
{
|
||||
[PrimaryKey]
|
||||
public string StoreName { get; set; }
|
||||
|
||||
public int Version { get; set; }
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user