Browse Source

Migrations fixed.

pull/247/head
Sebastian Stehle 8 years ago
parent
commit
66f74fcfc8
  1. 4
      src/Squidex.Domain.Apps.Entities.MongoDb/Contents/MongoContentRepository_SnapshotStore.cs
  2. 4
      src/Squidex.Domain.Apps.Entities/AppProvider.cs
  3. 2
      src/Squidex.Domain.Apps.Entities/IAppProvider.cs
  4. 4
      src/Squidex/Config/Domain/SerializationServices.cs
  5. 3
      src/Squidex/Config/Domain/WriteServices.cs
  6. 10
      tests/Squidex.Domain.Apps.Entities.Tests/Contents/ContentQueryServiceTests.cs
  7. 2
      tests/Squidex.Domain.Apps.Entities.Tests/Rules/Guards/GuardRuleTests.cs
  8. 4
      tests/Squidex.Domain.Apps.Entities.Tests/Rules/Guards/Triggers/ContentChangedTriggerTests.cs
  9. 2
      tests/Squidex.Domain.Apps.Entities.Tests/Rules/RuleCommandMiddlewareTests.cs
  10. 38
      tools/Migrate_01/Migration05_RebuildForNewCommands.cs
  11. 13
      tools/Migrate_01/SquidexMigrations.cs

4
src/Squidex.Domain.Apps.Entities.MongoDb/Contents/MongoContentRepository_SnapshotStore.cs

@ -45,7 +45,7 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents
return;
}
var schema = await GetSchemaAsync(value.SchemaId.Id, value.SchemaId.Id);
var schema = await GetSchemaAsync(value.AppId.Id, value.SchemaId.Id);
var idData = value.Data?.ToIdModel(schema.SchemaDef, true);
@ -94,7 +94,7 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents
private async Task<ISchemaEntity> GetSchemaAsync(Guid appId, Guid schemaId)
{
var schema = await appProvider.GetSchemaAsync(appId, schemaId);
var schema = await appProvider.GetSchemaAsync(appId, schemaId, true);
if (schema == null)
{

4
src/Squidex.Domain.Apps.Entities/AppProvider.cs

@ -88,11 +88,11 @@ namespace Squidex.Domain.Apps.Entities
return (await stateFactory.GetSingleAsync<SchemaDomainObject>(schemaId)).Snapshot;
}
public async Task<ISchemaEntity> GetSchemaAsync(Guid appId, Guid id)
public async Task<ISchemaEntity> GetSchemaAsync(Guid appId, Guid id, bool allowDeleted = false)
{
var schema = await stateFactory.GetSingleAsync<SchemaDomainObject>(id);
if (!IsFound(schema) || schema.Snapshot.IsDeleted || schema.Snapshot.AppId.Id != appId)
if (!IsFound(schema) || (schema.Snapshot.IsDeleted && !allowDeleted) || schema.Snapshot.AppId.Id != appId)
{
return null;
}

2
src/Squidex.Domain.Apps.Entities/IAppProvider.cs

@ -20,7 +20,7 @@ namespace Squidex.Domain.Apps.Entities
Task<IAppEntity> GetAppAsync(string appName);
Task<ISchemaEntity> GetSchemaAsync(Guid appId, Guid id);
Task<ISchemaEntity> GetSchemaAsync(Guid appId, Guid id, bool allowDeleted = false);
Task<ISchemaEntity> GetSchemaAsync(Guid appId, string name);

4
src/Squidex/Config/Domain/SerializationServices.cs

@ -28,10 +28,10 @@ namespace Squidex.Config.Domain
{
private static readonly TypeNameRegistry TypeNameRegistry =
new TypeNameRegistry()
.MapUnmapped(typeof(Migration01_FromCqrs).Assembly)
.MapUnmapped(typeof(SquidexCoreModel).Assembly)
.MapUnmapped(typeof(SquidexEvents).Assembly)
.MapUnmapped(typeof(SquidexInfrastructure).Assembly);
.MapUnmapped(typeof(SquidexInfrastructure).Assembly)
.MapUnmapped(typeof(SquidexMigrations).Assembly);
private static readonly FieldRegistry FieldRegistry = new FieldRegistry(TypeNameRegistry);

3
src/Squidex/Config/Domain/WriteServices.cs

@ -79,6 +79,9 @@ namespace Squidex.Config.Domain
services.AddTransientAs<Migration04_FlattenAssetEntity>()
.As<IMigration>();
services.AddTransientAs<Migration05_RebuildForNewCommands>()
.As<IMigration>();
services.AddTransientAs<Rebuilder>()
.AsSelf();

10
tests/Squidex.Domain.Apps.Entities.Tests/Contents/ContentQueryServiceTests.cs

@ -60,7 +60,7 @@ namespace Squidex.Domain.Apps.Entities.Contents
[Fact]
public async Task Should_return_schema_from_id_if_string_is_guid()
{
A.CallTo(() => appProvider.GetSchemaAsync(appId, schemaId))
A.CallTo(() => appProvider.GetSchemaAsync(appId, schemaId, false))
.Returns(schema);
var result = await sut.FindSchemaAsync(app, schemaId.ToString());
@ -91,7 +91,7 @@ namespace Squidex.Domain.Apps.Entities.Contents
[Fact]
public async Task Should_return_content_from_repository_and_transform()
{
A.CallTo(() => appProvider.GetSchemaAsync(appId, schemaId))
A.CallTo(() => appProvider.GetSchemaAsync(appId, schemaId, false))
.Returns(schema);
A.CallTo(() => contentRepository.FindContentAsync(app, schema, contentId))
.Returns(content);
@ -113,7 +113,7 @@ namespace Squidex.Domain.Apps.Entities.Contents
[Fact]
public async Task Should_throw_if_content_to_find_does_not_exist()
{
A.CallTo(() => appProvider.GetSchemaAsync(appId, schemaId))
A.CallTo(() => appProvider.GetSchemaAsync(appId, schemaId, false))
.Returns(schema);
A.CallTo(() => contentRepository.FindContentAsync(app, schema, contentId))
@ -196,7 +196,7 @@ namespace Squidex.Domain.Apps.Entities.Contents
private void SetupFakeWithIdQuery(Status[] status, HashSet<Guid> ids)
{
A.CallTo(() => appProvider.GetSchemaAsync(appId, schemaId))
A.CallTo(() => appProvider.GetSchemaAsync(appId, schemaId, false))
.Returns(schema);
A.CallTo(() => contentRepository.QueryAsync(app, schema, A<Status[]>.That.IsSameSequenceAs(status), ids))
@ -205,7 +205,7 @@ namespace Squidex.Domain.Apps.Entities.Contents
private void SetupFakeWithOdataQuery(Status[] status)
{
A.CallTo(() => appProvider.GetSchemaAsync(appId, schemaId))
A.CallTo(() => appProvider.GetSchemaAsync(appId, schemaId, false))
.Returns(schema);
A.CallTo(() => contentRepository.QueryAsync(app, schema, A<Status[]>.That.IsSameSequenceAs(status), A<ODataUriParser>.Ignored))

2
tests/Squidex.Domain.Apps.Entities.Tests/Rules/Guards/GuardRuleTests.cs

@ -30,7 +30,7 @@ namespace Squidex.Domain.Apps.Entities.Rules.Guards
public GuardRuleTests()
{
A.CallTo(() => appProvider.GetSchemaAsync(appId.Id, A<Guid>.Ignored))
A.CallTo(() => appProvider.GetSchemaAsync(appId.Id, A<Guid>.Ignored, false))
.Returns(A.Fake<ISchemaEntity>());
}

4
tests/Squidex.Domain.Apps.Entities.Tests/Rules/Guards/Triggers/ContentChangedTriggerTests.cs

@ -23,7 +23,7 @@ namespace Squidex.Domain.Apps.Entities.Rules.Guards.Triggers
[Fact]
public async Task Should_add_error_if_schemas_ids_are_not_valid()
{
A.CallTo(() => appProvider.GetSchemaAsync(appId, A<Guid>.Ignored))
A.CallTo(() => appProvider.GetSchemaAsync(appId, A<Guid>.Ignored, false))
.Returns(Task.FromResult<ISchemaEntity>(null));
var trigger = new ContentChangedTrigger
@ -64,7 +64,7 @@ namespace Squidex.Domain.Apps.Entities.Rules.Guards.Triggers
[Fact]
public async Task Should_not_add_error_if_schemas_ids_are_valid()
{
A.CallTo(() => appProvider.GetSchemaAsync(appId, A<Guid>.Ignored))
A.CallTo(() => appProvider.GetSchemaAsync(appId, A<Guid>.Ignored, false))
.Returns(A.Fake<ISchemaEntity>());
var trigger = new ContentChangedTrigger

2
tests/Squidex.Domain.Apps.Entities.Tests/Rules/RuleCommandMiddlewareTests.cs

@ -35,7 +35,7 @@ namespace Squidex.Domain.Apps.Entities.Rules
public RuleCommandMiddlewareTests()
{
A.CallTo(() => appProvider.GetSchemaAsync(A<Guid>.Ignored, A<Guid>.Ignored))
A.CallTo(() => appProvider.GetSchemaAsync(A<Guid>.Ignored, A<Guid>.Ignored, false))
.Returns(A.Fake<ISchemaEntity>());
sut = new RuleCommandMiddleware(Handler, appProvider);

38
tools/Migrate_01/Migration05_RebuildForNewCommands.cs

@ -0,0 +1,38 @@
// ==========================================================================
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex UG (haftungsbeschränkt)
// All rights reserved. Licensed under the MIT license.
// ==========================================================================
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Squidex.Infrastructure.Migrations;
namespace Migrate_01
{
public sealed class Migration05_RebuildForNewCommands : IMigration
{
private readonly Rebuilder rebuilder;
public int FromVersion { get; } = 4;
public int ToVersion { get; } = 5;
public Migration05_RebuildForNewCommands(Rebuilder rebuilder)
{
this.rebuilder = rebuilder;
}
public async Task UpdateAsync(IEnumerable<IMigration> previousMigrations)
{
if (!previousMigrations.Any(x => x is Migration01_FromCqrs))
{
await rebuilder.RebuildConfigAsync();
await rebuilder.RebuildContentAsync();
await rebuilder.RebuildAssetsAsync();
}
}
}
}

13
tools/Migrate_01/SquidexMigrations.cs

@ -0,0 +1,13 @@
// ==========================================================================
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex UG (haftungsbeschraenkt)
// All rights reserved. Licensed under the MIT license.
// ==========================================================================
namespace Migrate_01
{
public static class SquidexMigrations
{
}
}
Loading…
Cancel
Save