Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertBeekman committed Feb 25, 2024
2 parents 6956f09 + 24f470a commit be92701
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
25 changes: 16 additions & 9 deletions src/Artemis.Storage/Migrations/Storage/M0024NodeProviders.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -42,9 +47,11 @@ public void Apply(LiteRepository repository)
MigratePropertyGroup(layer.AsDocument["LayerBrush"]?["PropertyGroup"].AsDocument);
}
}

collection.Update(profileBson);
profilesToUpdate.Add(profileBson);
}

collection.Update(profilesToUpdate);
}

private void MigrateProfileElement(BsonDocument profileElement)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using LiteDB;
using System.Collections.Generic;
using LiteDB;

namespace Artemis.Storage.Migrations.Storage;

Expand All @@ -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;
Expand All @@ -19,9 +21,11 @@ public void Apply(LiteRepository repository)
profile["Version"] = 2;
MigrateNodeScript(profile["ActivationCondition"]?.AsDocument);
}
toUpdate.Add(profileCategoryBson);
}
categoryCollection.Update(profileCategoryBson);
}

categoryCollection.Update(toUpdate);
}

private void MigrateNodeScript(BsonDocument? nodeScript)
Expand Down

0 comments on commit be92701

Please sign in to comment.