1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-06 06:57:39 +08:00

Version realm files for debug executions

To make it easier for developers to test out pull requests which bump
the realm schema version, realm files are now stored with the schema
version in the filename.

Note that this means any changes made to a newer version will not be
applied to previous ones.
This commit is contained in:
Dean Herbert 2022-08-05 17:36:48 +09:00
parent a81a2517b2
commit 84a3fbd25c

View File

@ -172,6 +172,10 @@ namespace osu.Game.Database
if (!Filename.EndsWith(realm_extension, StringComparison.Ordinal))
Filename += realm_extension;
#if DEBUG
Filename = applyFilenameSchemaSuffix(Filename);
#endif
string newerVersionFilename = $"{Filename.Replace(realm_extension, string.Empty)}_newer_version{realm_extension}";
// Attempt to recover a newer database version if available.
@ -211,6 +215,50 @@ namespace osu.Game.Database
}
}
/// <summary>
/// Some developers may be annoyed if a newer version migration (ie. caused by testing a pull request)
/// cause their test database to be unusable with previous versions.
/// To get around this, store development databases against their realm version.
/// Note that this means changes made on newer realm versions will disappear.
/// </summary>
private string applyFilenameSchemaSuffix(string filename)
{
string proposedFilename = getVersionedFilename(schema_version);
// First check if the current realm version already exists...
if (storage.Exists(proposedFilename))
return proposedFilename;
// If a non-versioned file exists (aka before this method was added), move it to the new versioned
// format.
if (storage.Exists(filename))
{
Logger.Log(@$"Moving non-versioned realm file {filename} to {proposedFilename}");
storage.Move(filename, proposedFilename);
return proposedFilename;
}
// If it doesn't, check for a previous version we can use as a base database to migrate from...
for (int i = schema_version - 1; i >= 0; i--)
{
string iFilename = getVersionedFilename(i);
if (storage.Exists(iFilename))
{
using (var previous = storage.GetStream(iFilename))
using (var current = storage.CreateFileSafely(proposedFilename))
{
Logger.Log(@$"Using previous realm database {iFilename} to migrate new schema version {schema_version}");
previous.CopyTo(current);
}
}
}
return proposedFilename;
string getVersionedFilename(int version) => filename.Replace(realm_extension, $"_{version}{realm_extension}");
}
private void attemptRecoverFromFile(string recoveryFilename)
{
Logger.Log($@"Performing recovery from {recoveryFilename}", LoggingTarget.Database);