Storage - Added migration for DB v5 to v6

Conditions - Fixed a conversion issue in operators
This commit is contained in:
SpoinkyNL committed 2020-11-05 20:25:29 +01:00
1 parent 26daa8e1dd
commit bdcca6b4be
2 files changed
+54 -33

No files matched your search

@@ -1,34 +1,49 @@
using Artemis.Storage.Migrations.Interfaces;
using System;
using Artemis.Storage.Migrations.Interfaces;
using LiteDB;
namespace Artemis.Storage.Migrations
{
public class M6PredicateAbstraction : IStorageMigration
{
public int UserVersion => 7;
public int UserVersion => 6;
public void Apply(LiteRepository repository)
{
ILiteCollection<BsonDocument> collection = repository.Database.GetCollection("ProfileEntity");
foreach (BsonDocument bsonDocument in collection.FindAll())
{
foreach (BsonValue bsonLayer in bsonDocument["Layers"].AsArray)
{
bsonLayer["DisplayCondition"] = null;
foreach (BsonValue bsonPropertyEntity in bsonLayer["PropertyEntities"].AsArray)
bsonPropertyEntity["DataBindingEntities"].AsArray.Clear();
}
foreach (BsonValue bsonLayer in bsonDocument["Layers"].AsArray)
Migrate(bsonLayer);
foreach (BsonValue bsonLayer in bsonDocument["Folders"].AsArray)
{
bsonLayer["DisplayCondition"] = null;
foreach (BsonValue bsonPropertyEntity in bsonLayer["PropertyEntities"].AsArray)
bsonPropertyEntity["DataBindingEntities"].AsArray.Clear();
}
Migrate(bsonLayer);
collection.Update(bsonDocument);
}
}
private void Migrate(BsonValue bsonValue)
{
if (bsonValue.IsArray)
{
foreach (BsonValue child in bsonValue.AsArray)
Migrate(child);
return;
}
if (bsonValue.IsDocument)
{
// See if the document has a type
if (bsonValue.AsDocument.TryGetValue("_type", out BsonValue typeValue))
{
if (typeValue.AsString == "Artemis.Storage.Entities.Profile.Conditions.DataModelConditionPredicateEntity, Artemis.Storage")
bsonValue.AsDocument["_type"] = "Artemis.Storage.Entities.Profile.Conditions.DataModelConditionGeneralPredicateEntity, Artemis.Storage";
}
foreach (BsonValue documentValue in bsonValue.AsDocument.Values)
Migrate(documentValue);
}
}
}
}