Storage - Avoid broken LiteDB API

This commit is contained in:
RobertBeekman committed 2024-02-25 15:32:25 +01:00
1 parent 5203e95141
commit 24f470a480
2 files changed
+22 -11

No files matched your search

@@ -10,28 +10,33 @@ public class M0024NodeProviders : IStorageMigration
public void Apply(LiteRepository repository)
{
List<ProfileCategoryEntity> profileCategories = repository.Query<ProfileCategoryEntity>().ToList();
foreach (ProfileCategoryEntity profileCategory in profileCategories)
ILiteCollection<BsonDocument> categoryCollection = repository.Database.GetCollection("ProfileCategoryEntity");
List<BsonDocument> categoriesToUpdate = new();
foreach (BsonDocument profileCategoryBson in categoryCollection.FindAll())
{
foreach (ProfileConfigurationEntity profileConfigurationEntity in profileCategory.ProfileConfigurations)
BsonArray? profiles = profileCategoryBson["ProfileConfigurations"]?.AsArray;
if (profiles != null)
{
profileConfigurationEntity.Version = 1;
foreach (BsonValue profile in profiles)
profile["Version"] = 1;
categoriesToUpdate.Add(profileCategoryBson);
}
repository.Update(profileCategory);
}
categoryCollection.Update(categoriesToUpdate);
ILiteCollection<BsonDocument> collection = repository.Database.GetCollection("ProfileEntity");
List<BsonDocument> profilesToUpdate = new();
foreach (BsonDocument profileBson in collection.FindAll())
{
BsonArray? folders = profileBson["Folders"]?.AsArray;
BsonArray? layers = profileBson["Layers"]?.AsArray;
if (folders != null)
{
foreach (BsonValue folder in folders)
MigrateProfileElement(folder.AsDocument);
}
if (layers != null)
{
foreach (BsonValue layer in layers)
@@ -42,9 +47,11 @@ public class M0024NodeProviders : IStorageMigration
MigratePropertyGroup(layer.AsDocument["LayerBrush"]?["PropertyGroup"].AsDocument);
}
}
collection.Update(profileBson);
profilesToUpdate.Add(profileBson);
}
collection.Update(profilesToUpdate);
}
private void MigrateProfileElement(BsonDocument profileElement)
@@ -1,4 +1,5 @@
using LiteDB;
using System.Collections.Generic;
using LiteDB;
namespace Artemis.Storage.Migrations.Storage;
@@ -9,6 +10,7 @@ public class M0025NodeProvidersProfileConfig : IStorageMigration
public void Apply(LiteRepository repository)
{
ILiteCollection<BsonDocument> categoryCollection = repository.Database.GetCollection("ProfileCategoryEntity");
List<BsonDocument> toUpdate = new();
foreach (BsonDocument profileCategoryBson in categoryCollection.FindAll())
{
BsonArray? profiles = profileCategoryBson["ProfileConfigurations"]?.AsArray;
@@ -19,9 +21,11 @@ public class M0025NodeProvidersProfileConfig : IStorageMigration
profile["Version"] = 2;
MigrateNodeScript(profile["ActivationCondition"]?.AsDocument);
}
toUpdate.Add(profileCategoryBson);
}
categoryCollection.Update(profileCategoryBson);
}
categoryCollection.Update(toUpdate);
}
private void MigrateNodeScript(BsonDocument? nodeScript)