-
-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move migrations to storage, add Storage migration for nodes change
- Loading branch information
1 parent
313b4a0
commit 49ed020
Showing
13 changed files
with
112 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 0 additions & 9 deletions
9
src/Artemis.Core/Services/Storage/Interfaces/IProfileMigration.cs
This file was deleted.
Oops, something went wrong.
90 changes: 0 additions & 90 deletions
90
src/Artemis.Core/Services/Storage/ProfileMigrators/M0001NodeProviders.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,9 @@ | ||
using LiteDB; | ||
using Newtonsoft.Json.Linq; | ||
|
||
namespace Artemis.Storage.Migrations; | ||
|
||
internal interface IProfileMigration | ||
public interface IProfileMigration | ||
{ | ||
int Version { get; } | ||
void Migrate(JObject profileJson); | ||
void Migrate(BsonDocument profileBson); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
src/Artemis.Storage/Migrations/Storage/M0023LayoutProviders.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
src/Artemis.Storage/Migrations/Storage/M0024NodeProviders.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
using System.Collections.Generic; | ||
using Artemis.Storage.Entities.Profile; | ||
using LiteDB; | ||
|
||
namespace Artemis.Storage.Migrations.Storage; | ||
|
||
public class M0024NodeProviders : IStorageMigration | ||
{ | ||
public int UserVersion => 24; | ||
|
||
public void Apply(LiteRepository repository) | ||
{ | ||
List<ProfileCategoryEntity> profileCategories = repository.Query<ProfileCategoryEntity>().ToList(); | ||
foreach (ProfileCategoryEntity profileCategory in profileCategories) | ||
{ | ||
foreach (ProfileConfigurationEntity profileConfigurationEntity in profileCategory.ProfileConfigurations) | ||
{ | ||
profileConfigurationEntity.Version = 1; | ||
} | ||
repository.Update(profileCategory); | ||
} | ||
|
||
ILiteCollection<BsonDocument> collection = repository.Database.GetCollection("ProfileEntity"); | ||
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) | ||
{ | ||
MigrateProfileElement(layer.AsDocument); | ||
MigratePropertyGroup(layer.AsDocument["GeneralPropertyGroup"].AsDocument); | ||
MigratePropertyGroup(layer.AsDocument["TransformPropertyGroup"].AsDocument); | ||
MigratePropertyGroup(layer.AsDocument["LayerBrush"]?["PropertyGroup"].AsDocument); | ||
} | ||
} | ||
|
||
collection.Update(profileBson); | ||
} | ||
} | ||
|
||
private void MigrateProfileElement(BsonDocument profileElement) | ||
{ | ||
BsonArray? layerEffects = profileElement["LayerEffects"]?.AsArray; | ||
if (layerEffects != null) | ||
{ | ||
foreach (BsonValue layerEffect in layerEffects) | ||
MigratePropertyGroup(layerEffect.AsDocument["PropertyGroup"].AsDocument); | ||
} | ||
|
||
BsonValue? displayCondition = profileElement["DisplayCondition"]; | ||
if (displayCondition != null) | ||
MigrateNodeScript(displayCondition.AsDocument["Script"].AsDocument); | ||
} | ||
|
||
private void MigratePropertyGroup(BsonDocument? propertyGroup) | ||
{ | ||
if (propertyGroup == null || propertyGroup.Keys.Count == 0) | ||
return; | ||
|
||
BsonArray? properties = propertyGroup["Properties"]?.AsArray; | ||
BsonArray? propertyGroups = propertyGroup["PropertyGroups"]?.AsArray; | ||
|
||
if (properties != null) | ||
{ | ||
foreach (BsonValue property in properties) | ||
MigrateNodeScript(property.AsDocument["DataBinding"]?["NodeScript"]?.AsDocument); | ||
} | ||
|
||
if (propertyGroups != null) | ||
{ | ||
foreach (BsonValue childPropertyGroup in propertyGroups) | ||
MigratePropertyGroup(childPropertyGroup.AsDocument); | ||
} | ||
} | ||
|
||
private void MigrateNodeScript(BsonDocument? nodeScript) | ||
{ | ||
if (nodeScript == null || nodeScript.Keys.Count == 0) | ||
return; | ||
|
||
BsonArray? nodes = nodeScript["Nodes"]?.AsArray; | ||
if (nodes == null) | ||
return; | ||
|
||
foreach (BsonValue node in nodes) | ||
{ | ||
node.AsDocument["Type"] = node.AsDocument["Type"]?.AsString?.Replace("Artemis.VisualScripting.Nodes", "Artemis.Plugins.Nodes.General.Nodes"); | ||
node.AsDocument["ProviderId"] = "Artemis.Plugins.Nodes.General.GeneralNodesProvider-d9e1ee78"; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters