1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-31 09:43:46 +00:00

41 lines
1.3 KiB
C#

using LiteDB;
namespace Artemis.Storage.Legacy.Migrations.Storage;
internal class M0027Namespace : IStorageMigration
{
public int UserVersion => 27;
public void Apply(LiteRepository repository)
{
ILiteCollection<BsonDocument> collection = repository.Database.GetCollection("ProfileEntity");
List<BsonDocument> profilesToUpdate = new();
foreach (BsonDocument profileBson in collection.FindAll())
{
MigrateDocument(profileBson);
profilesToUpdate.Add(profileBson);
}
collection.Update(profilesToUpdate);
}
private void MigrateDocument(BsonDocument document)
{
foreach ((string? key, BsonValue? value) in document)
{
if (key == "_type")
document[key] = document[key].AsString
.Replace("Artemis.Storage.Entities", "Artemis.Storage.Legacy.Entities")
.Replace(", Artemis.Storage", ", Artemis.Storage.Legacy");
else if (value.IsDocument)
MigrateDocument(value.AsDocument);
else if (value.IsArray)
foreach (BsonValue bsonValue in value.AsArray)
{
if (bsonValue.IsDocument)
MigrateDocument(bsonValue.AsDocument);
}
}
}
}