diff --git a/tools/Migrate_01/Rebuilder.cs b/tools/Migrate_01/Rebuilder.cs index a401c39d7..cb17472fe 100644 --- a/tools/Migrate_01/Rebuilder.cs +++ b/tools/Migrate_01/Rebuilder.cs @@ -11,10 +11,14 @@ using System.Threading; using System.Threading.Tasks; using Squidex.Domain.Apps.Core.Schemas; using Squidex.Domain.Apps.Entities.Apps; +using Squidex.Domain.Apps.Entities.Apps.State; using Squidex.Domain.Apps.Entities.Assets; +using Squidex.Domain.Apps.Entities.Assets.State; using Squidex.Domain.Apps.Entities.Contents.State; using Squidex.Domain.Apps.Entities.Rules; +using Squidex.Domain.Apps.Entities.Rules.State; using Squidex.Domain.Apps.Entities.Schemas; +using Squidex.Domain.Apps.Entities.Schemas.State; using Squidex.Domain.Apps.Events; using Squidex.Domain.Apps.Events.Assets; using Squidex.Domain.Apps.Events.Contents; @@ -30,30 +34,44 @@ namespace Migrate_01 private readonly FieldRegistry fieldRegistry; private readonly IEventStore eventStore; private readonly IEventDataFormatter eventDataFormatter; + private readonly ISnapshotStore snapshotAppStore; + private readonly ISnapshotStore snapshotAssetStore; private readonly ISnapshotStore snapshotContentStore; + private readonly ISnapshotStore snapshotRuleStore; + private readonly ISnapshotStore snapshotSchemaStore; private readonly IStateFactory stateFactory; public Rebuilder( FieldRegistry fieldRegistry, IEventDataFormatter eventDataFormatter, IEventStore eventStore, + ISnapshotStore snapshotAppStore, ISnapshotStore snapshotContentStore, + ISnapshotStore snapshotAssetStore, + ISnapshotStore snapshotRuleStore, + ISnapshotStore snapshotSchemaStore, IStateFactory stateFactory) { this.fieldRegistry = fieldRegistry; this.eventDataFormatter = eventDataFormatter; this.eventStore = eventStore; + this.snapshotAppStore = snapshotAppStore; + this.snapshotAssetStore = snapshotAssetStore; this.snapshotContentStore = snapshotContentStore; + this.snapshotRuleStore = snapshotRuleStore; + this.snapshotSchemaStore = snapshotSchemaStore; this.stateFactory = stateFactory; } - public Task RebuildAssetsAsync() + public async Task RebuildAssetsAsync() { + await snapshotAssetStore.ClearAsync(); + const string filter = "^asset\\-"; var handledIds = new HashSet(); - return eventStore.GetEventsAsync(async storedEvent => + await eventStore.GetEventsAsync(async storedEvent => { var @event = ParseKnownEvent(storedEvent); @@ -71,13 +89,17 @@ namespace Migrate_01 }, filter, cancellationToken: CancellationToken.None); } - public Task RebuildConfigAsync() + public async Task RebuildConfigAsync() { + await snapshotAppStore.ClearAsync(); + await snapshotRuleStore.ClearAsync(); + await snapshotSchemaStore.ClearAsync(); + const string filter = "^((app\\-)|(schema\\-)|(rule\\-))"; var handledIds = new HashSet(); - return eventStore.GetEventsAsync(async storedEvent => + await eventStore.GetEventsAsync(async storedEvent => { var @event = ParseKnownEvent(storedEvent); @@ -107,12 +129,12 @@ namespace Migrate_01 public async Task RebuildContentAsync() { + await snapshotContentStore.ClearAsync(); + const string filter = "^((content\\-))"; var handledIds = new HashSet(); - await snapshotContentStore.ClearAsync(); - await eventStore.GetEventsAsync(async storedEvent => { var @event = ParseKnownEvent(storedEvent);