mirror of https://github.com/Squidex/squidex.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
71 lines
2.4 KiB
71 lines
2.4 KiB
// ==========================================================================
|
|
// Migration02_AddPatterns.cs
|
|
// Squidex Headless CMS
|
|
// ==========================================================================
|
|
// Copyright (c) Squidex Group
|
|
// All rights reserved.
|
|
// ==========================================================================
|
|
|
|
using System;
|
|
using System.Threading.Tasks;
|
|
using Squidex.Domain.Apps.Entities.Apps;
|
|
using Squidex.Domain.Apps.Entities.Apps.Commands;
|
|
using Squidex.Domain.Apps.Entities.Apps.Repositories;
|
|
using Squidex.Infrastructure;
|
|
using Squidex.Infrastructure.Migrations;
|
|
using Squidex.Infrastructure.States;
|
|
|
|
namespace Migrate_01
|
|
{
|
|
public sealed class Migration02_AddPatterns : IMigration
|
|
{
|
|
private readonly InitialPatterns initialPatterns;
|
|
private readonly IStateFactory stateFactory;
|
|
private readonly IAppRepository appRepository;
|
|
|
|
public int FromVersion { get; } = 1;
|
|
|
|
public int ToVersion { get; } = 2;
|
|
|
|
public Migration02_AddPatterns(
|
|
InitialPatterns initialPatterns,
|
|
IStateFactory stateFactory,
|
|
IAppRepository appRepository)
|
|
{
|
|
this.initialPatterns = initialPatterns;
|
|
this.appRepository = appRepository;
|
|
this.stateFactory = stateFactory;
|
|
}
|
|
|
|
public async Task UpdateAsync()
|
|
{
|
|
var ids = await appRepository.QueryAppIdsAsync();
|
|
|
|
foreach (var id in ids)
|
|
{
|
|
var app = await stateFactory.CreateAsync<AppDomainObject>(id);
|
|
|
|
if (app.State.Patterns.Count == 0)
|
|
{
|
|
foreach (var pattern in initialPatterns.Values)
|
|
{
|
|
var command =
|
|
new AddPattern
|
|
{
|
|
Actor = app.State.CreatedBy,
|
|
AppId = new NamedId<Guid>(app.State.Id, app.State.Name),
|
|
Name = pattern.Name,
|
|
PatternId = Guid.NewGuid(),
|
|
Pattern = pattern.Pattern,
|
|
Message = pattern.Message
|
|
};
|
|
|
|
app.AddPattern(command);
|
|
}
|
|
|
|
await app.WriteStateAsync(app.Version + initialPatterns.Count);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|