mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-12 21:38:38 +00:00
Storage - Added layout migration
This commit is contained in:
parent
8b4b5d8810
commit
b01c5b16fc
35
src/Artemis.Storage/Migrations/M0023LayoutProviders.cs
Normal file
35
src/Artemis.Storage/Migrations/M0023LayoutProviders.cs
Normal file
@ -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<BsonDocument> deviceEntities = repository.Database.GetCollection("DeviceEntity");
|
||||
List<BsonDocument> 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);
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user