From b01c5b16fc4c179cbe86df7648bedeb8f3a955c2 Mon Sep 17 00:00:00 2001 From: Robert Date: Sun, 14 Jan 2024 22:48:33 +0100 Subject: [PATCH] Storage - Added layout migration --- .../Migrations/M0023LayoutProviders.cs | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/Artemis.Storage/Migrations/M0023LayoutProviders.cs diff --git a/src/Artemis.Storage/Migrations/M0023LayoutProviders.cs b/src/Artemis.Storage/Migrations/M0023LayoutProviders.cs new file mode 100644 index 000000000..5914b01c2 --- /dev/null +++ b/src/Artemis.Storage/Migrations/M0023LayoutProviders.cs @@ -0,0 +1,35 @@ +using System.Collections.Generic; +using Artemis.Storage.Migrations.Interfaces; +using LiteDB; + +namespace Artemis.Storage.Migrations; + +public class M0023LayoutProviders : IStorageMigration +{ + public int UserVersion => 23; + + public void Apply(LiteRepository repository) + { + ILiteCollection deviceEntities = repository.Database.GetCollection("DeviceEntity"); + List toUpdate = new(); + + foreach (BsonDocument bsonDocument in deviceEntities.FindAll()) + { + if (bsonDocument.TryGetValue("CustomLayoutPath", out BsonValue customLayoutPath) && customLayoutPath.IsString && !string.IsNullOrEmpty(customLayoutPath.AsString)) + { + bsonDocument.Add("LayoutType", new BsonValue("CustomPath")); + bsonDocument.Add("LayoutParameter", new BsonValue(customLayoutPath.AsString)); + } + else if (bsonDocument.TryGetValue("DisableDefaultLayout", out BsonValue disableDefaultLayout) && disableDefaultLayout.AsBoolean) + bsonDocument.Add("LayoutType", new BsonValue("None")); + else + bsonDocument.Add("LayoutType", new BsonValue("Default")); + + bsonDocument.Remove("CustomLayoutPath"); + bsonDocument.Remove("DisableDefaultLayout"); + toUpdate.Add(bsonDocument); + } + + deviceEntities.Update(toUpdate); + } +} \ No newline at end of file