mirror of https://github.com/Squidex/squidex.git
committed by
GitHub
649 changed files with 4161 additions and 3915 deletions
@ -1,60 +0,0 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschränkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
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.Indexes; |
|||
using Squidex.Infrastructure.Commands; |
|||
using Squidex.Infrastructure.Migrations; |
|||
|
|||
namespace Migrations.Migrations |
|||
{ |
|||
public sealed class AddPatterns : IMigration |
|||
{ |
|||
private readonly InitialPatterns initialPatterns; |
|||
private readonly ICommandBus commandBus; |
|||
private readonly IAppsIndex indexForApps; |
|||
|
|||
public AddPatterns(InitialPatterns initialPatterns, ICommandBus commandBus, IAppsIndex indexForApps) |
|||
{ |
|||
this.indexForApps = indexForApps; |
|||
this.initialPatterns = initialPatterns; |
|||
this.commandBus = commandBus; |
|||
} |
|||
|
|||
public async Task UpdateAsync() |
|||
{ |
|||
var ids = await indexForApps.GetIdsAsync(); |
|||
|
|||
foreach (var id in ids) |
|||
{ |
|||
var app = await indexForApps.GetAppAsync(id); |
|||
|
|||
if (app != null && app.Patterns.Count == 0) |
|||
{ |
|||
foreach (var pattern in initialPatterns.Values) |
|||
{ |
|||
var command = |
|||
new AddPattern |
|||
{ |
|||
Actor = app.CreatedBy, |
|||
AppId = id, |
|||
Name = pattern.Name, |
|||
PatternId = Guid.NewGuid(), |
|||
Pattern = pattern.Pattern, |
|||
Message = pattern.Message |
|||
}; |
|||
|
|||
await commandBus.PublishAsync(command); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,30 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using System; |
|||
using System.Threading.Tasks; |
|||
using Squidex.Domain.Apps.Entities.Rules.State; |
|||
using Squidex.Infrastructure.Migrations; |
|||
using Squidex.Infrastructure.States; |
|||
|
|||
namespace Migrations.Migrations |
|||
{ |
|||
public sealed class ClearRules : IMigration |
|||
{ |
|||
private readonly IStore<Guid> store; |
|||
|
|||
public ClearRules(IStore<Guid> store) |
|||
{ |
|||
this.store = store; |
|||
} |
|||
|
|||
public Task UpdateAsync() |
|||
{ |
|||
return store.ClearSnapshotsAsync<Guid, RuleState>(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,118 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Threading.Tasks; |
|||
using System.Threading.Tasks.Dataflow; |
|||
using MongoDB.Bson; |
|||
using MongoDB.Driver; |
|||
using Squidex.Infrastructure.Migrations; |
|||
|
|||
namespace Migrations.Migrations.MongoDb |
|||
{ |
|||
public sealed class AddAppIdToEventStream : IMigration |
|||
{ |
|||
private readonly IMongoDatabase database; |
|||
|
|||
public AddAppIdToEventStream(IMongoDatabase database) |
|||
{ |
|||
this.database = database; |
|||
} |
|||
|
|||
public async Task UpdateAsync() |
|||
{ |
|||
var collection = database.GetCollection<BsonDocument>("Events"); |
|||
|
|||
const int SizeOfBatch = 200; |
|||
const int SizeOfQueue = 20; |
|||
|
|||
var batchBlock = new BatchBlock<BsonDocument>(SizeOfBatch, new GroupingDataflowBlockOptions |
|||
{ |
|||
BoundedCapacity = SizeOfQueue * SizeOfBatch |
|||
}); |
|||
|
|||
var actionBlock = new ActionBlock<BsonDocument[]>(async batch => |
|||
{ |
|||
var updates = new List<WriteModel<BsonDocument>>(); |
|||
|
|||
foreach (var commit in batch) |
|||
{ |
|||
var eventStream = commit["EventStream"].AsString; |
|||
|
|||
string? appId = null; |
|||
|
|||
foreach (var @event in commit["Events"].AsBsonArray) |
|||
{ |
|||
var metadata = @event["Metadata"].AsBsonDocument; |
|||
|
|||
if (metadata.TryGetValue("AppId", out var value)) |
|||
{ |
|||
appId = value.AsString; |
|||
} |
|||
} |
|||
|
|||
if (appId != null) |
|||
{ |
|||
var parts = eventStream.Split("-"); |
|||
|
|||
var domainType = parts[0]; |
|||
var domainId = string.Join("-", parts.Skip(1)); |
|||
|
|||
var newStreamName = $"{domainType}-{appId}--{domainId}"; |
|||
|
|||
var update = Builders<BsonDocument>.Update.Set("EventStream", newStreamName); |
|||
|
|||
var i = 0; |
|||
|
|||
foreach (var @event in commit["Events"].AsBsonArray) |
|||
{ |
|||
update = update.Set($"Events.{i}.Metadata.AggregateId", $"{appId}--{domainId}"); |
|||
update = update.Unset($"Events.{i}.Metadata.AppId"); |
|||
|
|||
i++; |
|||
} |
|||
|
|||
var filter = Builders<BsonDocument>.Filter.Eq("_id", commit["_id"].AsString); |
|||
|
|||
updates.Add(new UpdateOneModel<BsonDocument>(filter, update)); |
|||
} |
|||
} |
|||
|
|||
if (updates.Count > 0) |
|||
{ |
|||
await collection.BulkWriteAsync(updates); |
|||
} |
|||
}, new ExecutionDataflowBlockOptions |
|||
{ |
|||
MaxDegreeOfParallelism = 4, |
|||
MaxMessagesPerTask = 1, |
|||
BoundedCapacity = SizeOfQueue |
|||
}); |
|||
|
|||
batchBlock.LinkTo(actionBlock, new DataflowLinkOptions |
|||
{ |
|||
PropagateCompletion = true |
|||
}); |
|||
|
|||
await collection.Find(new BsonDocument()).ForEachAsync(async commit => |
|||
{ |
|||
var eventStream = commit["EventStream"].AsString; |
|||
|
|||
if (!eventStream.Contains("--") && !eventStream.StartsWith("app-", StringComparison.OrdinalIgnoreCase)) |
|||
{ |
|||
await batchBlock.SendAsync(commit); |
|||
} |
|||
}); |
|||
|
|||
batchBlock.Complete(); |
|||
|
|||
await actionBlock.Completion; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,28 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschränkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using System.Threading.Tasks; |
|||
using Squidex.Infrastructure.Commands; |
|||
using Squidex.Infrastructure.Migrations; |
|||
|
|||
namespace Migrations.Migrations |
|||
{ |
|||
public sealed class RebuildAssetFolders : IMigration |
|||
{ |
|||
private readonly Rebuilder rebuilder; |
|||
|
|||
public RebuildAssetFolders(Rebuilder rebuilder) |
|||
{ |
|||
this.rebuilder = rebuilder; |
|||
} |
|||
|
|||
public Task UpdateAsync() |
|||
{ |
|||
return rebuilder.RebuildAssetFoldersAsync(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,61 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using MongoDB.Bson.Serialization.Attributes; |
|||
using Squidex.Domain.Apps.Entities.Contents.Text.State; |
|||
using Squidex.Infrastructure; |
|||
|
|||
namespace Squidex.Domain.Apps.Entities.MongoDb.FullText |
|||
{ |
|||
public sealed class MongoTextIndexState |
|||
{ |
|||
[BsonId] |
|||
[BsonElement] |
|||
public DomainId DocumentId { get; set; } |
|||
|
|||
[BsonRequired] |
|||
[BsonElement] |
|||
public DomainId ContentId { get; set; } |
|||
|
|||
[BsonRequired] |
|||
[BsonElement("c")] |
|||
public string DocIdCurrent { get; set; } |
|||
|
|||
[BsonRequired] |
|||
[BsonElement("n")] |
|||
public string? DocIdNew { get; set; } |
|||
|
|||
[BsonRequired] |
|||
[BsonElement("p")] |
|||
public string? DocIdForPublished { get; set; } |
|||
|
|||
public MongoTextIndexState() |
|||
{ |
|||
} |
|||
|
|||
public MongoTextIndexState(DomainId documentId, TextContentState state) |
|||
{ |
|||
DocumentId = documentId; |
|||
|
|||
ContentId = state.ContentId; |
|||
DocIdNew = state.DocIdNew; |
|||
DocIdCurrent = state.DocIdCurrent; |
|||
DocIdForPublished = state.DocIdForPublished; |
|||
} |
|||
|
|||
public TextContentState ToState() |
|||
{ |
|||
return new TextContentState |
|||
{ |
|||
ContentId = ContentId, |
|||
DocIdNew = DocIdNew, |
|||
DocIdCurrent = DocIdCurrent, |
|||
DocIdForPublished = DocIdForPublished |
|||
}; |
|||
} |
|||
} |
|||
} |
|||
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue