diff --git a/Squidex.ruleset b/Squidex.ruleset index 3a545b672..d1a5bbeb2 100644 --- a/Squidex.ruleset +++ b/Squidex.ruleset @@ -60,6 +60,8 @@ + + diff --git a/extensions/Squidex.Extensions/Squidex.Extensions.csproj b/extensions/Squidex.Extensions/Squidex.Extensions.csproj index 1723cbaae..e3b3ae52e 100644 --- a/extensions/Squidex.Extensions/Squidex.Extensions.csproj +++ b/extensions/Squidex.Extensions/Squidex.Extensions.csproj @@ -10,13 +10,13 @@ - + - + - + diff --git a/src/Squidex.Domain.Apps.Core.Model/Squidex.Domain.Apps.Core.Model.csproj b/src/Squidex.Domain.Apps.Core.Model/Squidex.Domain.Apps.Core.Model.csproj index 70163bdfd..7a88572ce 100644 --- a/src/Squidex.Domain.Apps.Core.Model/Squidex.Domain.Apps.Core.Model.csproj +++ b/src/Squidex.Domain.Apps.Core.Model/Squidex.Domain.Apps.Core.Model.csproj @@ -9,7 +9,7 @@ True - + all runtime; build; native; contentfiles; analyzers diff --git a/src/Squidex.Domain.Apps.Core.Operations/Squidex.Domain.Apps.Core.Operations.csproj b/src/Squidex.Domain.Apps.Core.Operations/Squidex.Domain.Apps.Core.Operations.csproj index 20dfa8cb5..19104863c 100644 --- a/src/Squidex.Domain.Apps.Core.Operations/Squidex.Domain.Apps.Core.Operations.csproj +++ b/src/Squidex.Domain.Apps.Core.Operations/Squidex.Domain.Apps.Core.Operations.csproj @@ -17,9 +17,9 @@ - + - + diff --git a/src/Squidex.Domain.Apps.Entities.MongoDb/Assets/MongoAssetRepository.cs b/src/Squidex.Domain.Apps.Entities.MongoDb/Assets/MongoAssetRepository.cs index 3597e55a3..44d93d8d4 100644 --- a/src/Squidex.Domain.Apps.Entities.MongoDb/Assets/MongoAssetRepository.cs +++ b/src/Squidex.Domain.Apps.Entities.MongoDb/Assets/MongoAssetRepository.cs @@ -10,6 +10,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; +using Microsoft.Extensions.Options; using MongoDB.Driver; using Squidex.Domain.Apps.Entities.Assets; using Squidex.Domain.Apps.Entities.Assets.Repositories; @@ -23,9 +24,14 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Assets { public sealed partial class MongoAssetRepository : MongoRepositoryBase, IAssetRepository { - public MongoAssetRepository(IMongoDatabase database) + private readonly MongoDbOptions options; + + public MongoAssetRepository(IMongoDatabase database, IOptions options) : base(database) { + Guard.NotNull(options, nameof(options)); + + this.options = options.Value; } protected override string CollectionName() @@ -44,17 +50,29 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Assets .Ascending(x => x.IsDeleted) .Ascending(x => x.FileName) .Ascending(x => x.Tags) - .Descending(x => x.LastModified)), + .Descending(x => x.LastModified), + new CreateIndexOptions + { + Name = options.IsDocumentDb ? "FileName_Tags" : null + }), new CreateIndexModel( Index .Ascending(x => x.AppId) .Ascending(x => x.IsDeleted) - .Ascending(x => x.FileHash)), + .Ascending(x => x.FileHash), + new CreateIndexOptions + { + Name = options.IsDocumentDb ? "FileHash" : null + }), new CreateIndexModel( Index .Ascending(x => x.AppId) .Ascending(x => x.IsDeleted) - .Ascending(x => x.Slug)) + .Ascending(x => x.Slug), + new CreateIndexOptions + { + Name = options.IsDocumentDb ? "Slug" : null + }) }, ct); } diff --git a/src/Squidex.Domain.Apps.Entities.MongoDb/History/MongoHistoryEventRepository.cs b/src/Squidex.Domain.Apps.Entities.MongoDb/History/MongoHistoryEventRepository.cs index 5a39bb706..cb76c8bc1 100644 --- a/src/Squidex.Domain.Apps.Entities.MongoDb/History/MongoHistoryEventRepository.cs +++ b/src/Squidex.Domain.Apps.Entities.MongoDb/History/MongoHistoryEventRepository.cs @@ -27,8 +27,7 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.History { var classMap = BsonClassMap.RegisterClassMap(); - classMap.MapProperty(x => x.Created) - .SetElementName("_ts"); + classMap.MapProperty(x => x.Created).SetElementName("_ts"); classMap.AutoMap(); } } diff --git a/src/Squidex.Domain.Apps.Entities.MongoDb/Squidex.Domain.Apps.Entities.MongoDb.csproj b/src/Squidex.Domain.Apps.Entities.MongoDb/Squidex.Domain.Apps.Entities.MongoDb.csproj index b8c6ea495..04c970954 100644 --- a/src/Squidex.Domain.Apps.Entities.MongoDb/Squidex.Domain.Apps.Entities.MongoDb.csproj +++ b/src/Squidex.Domain.Apps.Entities.MongoDb/Squidex.Domain.Apps.Entities.MongoDb.csproj @@ -17,9 +17,9 @@ - + - + diff --git a/src/Squidex.Domain.Apps.Entities/Squidex.Domain.Apps.Entities.csproj b/src/Squidex.Domain.Apps.Entities/Squidex.Domain.Apps.Entities.csproj index cc01356e9..3bb34a283 100644 --- a/src/Squidex.Domain.Apps.Entities/Squidex.Domain.Apps.Entities.csproj +++ b/src/Squidex.Domain.Apps.Entities/Squidex.Domain.Apps.Entities.csproj @@ -20,14 +20,14 @@ - + all runtime; build; native; contentfiles; analyzers - + - + diff --git a/src/Squidex.Domain.Apps.Events/Squidex.Domain.Apps.Events.csproj b/src/Squidex.Domain.Apps.Events/Squidex.Domain.Apps.Events.csproj index 3ebd7ece0..7ed7fbafe 100644 --- a/src/Squidex.Domain.Apps.Events/Squidex.Domain.Apps.Events.csproj +++ b/src/Squidex.Domain.Apps.Events/Squidex.Domain.Apps.Events.csproj @@ -15,7 +15,7 @@ - + diff --git a/src/Squidex.Domain.Users.MongoDb/MongoUserStore.cs b/src/Squidex.Domain.Users.MongoDb/MongoUserStore.cs index ff8c6a130..40ff5ed33 100644 --- a/src/Squidex.Domain.Users.MongoDb/MongoUserStore.cs +++ b/src/Squidex.Domain.Users.MongoDb/MongoUserStore.cs @@ -12,10 +12,12 @@ using System.Security.Claims; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Identity; +using Microsoft.Extensions.Options; using MongoDB.Bson; using MongoDB.Bson.Serialization; using MongoDB.Bson.Serialization.Serializers; using MongoDB.Driver; +using Squidex.Infrastructure; using Squidex.Infrastructure.MongoDb; using Squidex.Infrastructure.Tasks; @@ -41,6 +43,7 @@ namespace Squidex.Domain.Users.MongoDb private const string InternalLoginProvider = "[AspNetUserStore]"; private const string AuthenticatorKeyTokenName = "AuthenticatorKey"; private const string RecoveryCodeTokenName = "RecoveryCodes"; + private readonly MongoDbOptions options; static MongoUserStore() { @@ -104,9 +107,12 @@ namespace Squidex.Domain.Users.MongoDb }); } - public MongoUserStore(IMongoDatabase database) + public MongoUserStore(IMongoDatabase database, IOptions options) : base(database) { + Guard.NotNull(options, nameof(options)); + + this.options = options.Value; } protected override string CollectionName() @@ -119,7 +125,9 @@ namespace Squidex.Domain.Users.MongoDb return collection.Indexes.CreateManyAsync( new[] { - new CreateIndexModel(Index.Ascending("Logins.LoginProvider").Ascending("Logins.ProviderKey")), + options.IsDocumentDb ? + new CreateIndexModel(Index.Ascending("Logins.LoginProvider")) : + new CreateIndexModel(Index.Ascending("Logins.LoginProvider").Ascending("Logins.ProviderKey")), new CreateIndexModel(Index.Ascending(x => x.NormalizedUserName), new CreateIndexOptions { Unique = true }), new CreateIndexModel(Index.Ascending(x => x.NormalizedEmail), new CreateIndexOptions { Unique = true }) }, ct); diff --git a/src/Squidex.Domain.Users.MongoDb/Squidex.Domain.Users.MongoDb.csproj b/src/Squidex.Domain.Users.MongoDb/Squidex.Domain.Users.MongoDb.csproj index a314a3872..7eb93654c 100644 --- a/src/Squidex.Domain.Users.MongoDb/Squidex.Domain.Users.MongoDb.csproj +++ b/src/Squidex.Domain.Users.MongoDb/Squidex.Domain.Users.MongoDb.csproj @@ -17,9 +17,9 @@ - + - + diff --git a/src/Squidex.Domain.Users/Squidex.Domain.Users.csproj b/src/Squidex.Domain.Users/Squidex.Domain.Users.csproj index 3d9817fb3..135fee181 100644 --- a/src/Squidex.Domain.Users/Squidex.Domain.Users.csproj +++ b/src/Squidex.Domain.Users/Squidex.Domain.Users.csproj @@ -17,7 +17,7 @@ - + diff --git a/src/Squidex.Infrastructure.Azure/Squidex.Infrastructure.Azure.csproj b/src/Squidex.Infrastructure.Azure/Squidex.Infrastructure.Azure.csproj index b2bd38afe..0746062d9 100644 --- a/src/Squidex.Infrastructure.Azure/Squidex.Infrastructure.Azure.csproj +++ b/src/Squidex.Infrastructure.Azure/Squidex.Infrastructure.Azure.csproj @@ -5,10 +5,10 @@ 7.3 - - + + - + diff --git a/src/Squidex.Infrastructure.GetEventStore/Squidex.Infrastructure.GetEventStore.csproj b/src/Squidex.Infrastructure.GetEventStore/Squidex.Infrastructure.GetEventStore.csproj index e6a7f9ab0..8e213b530 100644 --- a/src/Squidex.Infrastructure.GetEventStore/Squidex.Infrastructure.GetEventStore.csproj +++ b/src/Squidex.Infrastructure.GetEventStore/Squidex.Infrastructure.GetEventStore.csproj @@ -11,7 +11,7 @@ - + diff --git a/src/Squidex.Infrastructure.GoogleCloud/Squidex.Infrastructure.GoogleCloud.csproj b/src/Squidex.Infrastructure.GoogleCloud/Squidex.Infrastructure.GoogleCloud.csproj index c7a60841d..7151f2bde 100644 --- a/src/Squidex.Infrastructure.GoogleCloud/Squidex.Infrastructure.GoogleCloud.csproj +++ b/src/Squidex.Infrastructure.GoogleCloud/Squidex.Infrastructure.GoogleCloud.csproj @@ -11,7 +11,7 @@ - + diff --git a/src/Squidex.Infrastructure.MongoDb/MongoDb/MongoDbEngine.cs b/src/Squidex.Infrastructure.MongoDb/MongoDb/MongoDbEngine.cs new file mode 100644 index 000000000..14591c8d0 --- /dev/null +++ b/src/Squidex.Infrastructure.MongoDb/MongoDb/MongoDbEngine.cs @@ -0,0 +1,16 @@ +// ========================================================================== +// Squidex Headless CMS +// ========================================================================== +// Copyright (c) Squidex UG (haftungsbeschraenkt) +// All rights reserved. Licensed under the MIT license. +// ========================================================================== + +namespace Squidex.Infrastructure.MongoDb +{ + public enum MongoDbEngine + { + CosmosDb, + DocumentDb, + MongoDb, + } +} diff --git a/src/Squidex.Infrastructure.MongoDb/MongoDb/MongoDbOptions.cs b/src/Squidex.Infrastructure.MongoDb/MongoDb/MongoDbOptions.cs index 65462dc6c..d18599b03 100644 --- a/src/Squidex.Infrastructure.MongoDb/MongoDb/MongoDbOptions.cs +++ b/src/Squidex.Infrastructure.MongoDb/MongoDb/MongoDbOptions.cs @@ -9,6 +9,21 @@ namespace Squidex.Infrastructure.MongoDb { public sealed class MongoDbOptions { - public bool IsCosmosDb { get; set; } + public MongoDbEngine Engine { get; set; } = MongoDbEngine.MongoDb; + + public bool IsCosmosDb + { + get { return Engine == MongoDbEngine.CosmosDb; } + } + + public bool IsDocumentDb + { + get { return Engine == MongoDbEngine.DocumentDb; } + } + + public bool IsMongoDb + { + get { return Engine == MongoDbEngine.MongoDb; } + } } } diff --git a/src/Squidex.Infrastructure.MongoDb/Squidex.Infrastructure.MongoDb.csproj b/src/Squidex.Infrastructure.MongoDb/Squidex.Infrastructure.MongoDb.csproj index 0acd60699..97583aaa5 100644 --- a/src/Squidex.Infrastructure.MongoDb/Squidex.Infrastructure.MongoDb.csproj +++ b/src/Squidex.Infrastructure.MongoDb/Squidex.Infrastructure.MongoDb.csproj @@ -12,10 +12,10 @@ - - + + - + diff --git a/src/Squidex.Infrastructure.RabbitMq/Squidex.Infrastructure.RabbitMq.csproj b/src/Squidex.Infrastructure.RabbitMq/Squidex.Infrastructure.RabbitMq.csproj index c45daaebf..53db2cb03 100644 --- a/src/Squidex.Infrastructure.RabbitMq/Squidex.Infrastructure.RabbitMq.csproj +++ b/src/Squidex.Infrastructure.RabbitMq/Squidex.Infrastructure.RabbitMq.csproj @@ -11,7 +11,7 @@ - + diff --git a/src/Squidex.Infrastructure.Redis/Squidex.Infrastructure.Redis.csproj b/src/Squidex.Infrastructure.Redis/Squidex.Infrastructure.Redis.csproj index c0e1ca1d1..5cf748e0a 100644 --- a/src/Squidex.Infrastructure.Redis/Squidex.Infrastructure.Redis.csproj +++ b/src/Squidex.Infrastructure.Redis/Squidex.Infrastructure.Redis.csproj @@ -14,7 +14,7 @@ - + diff --git a/src/Squidex.Infrastructure/Squidex.Infrastructure.csproj b/src/Squidex.Infrastructure/Squidex.Infrastructure.csproj index a57b8836d..882061c58 100644 --- a/src/Squidex.Infrastructure/Squidex.Infrastructure.csproj +++ b/src/Squidex.Infrastructure/Squidex.Infrastructure.csproj @@ -13,17 +13,17 @@ - + all runtime; build; native; contentfiles; analyzers - - - + + + - + diff --git a/src/Squidex.Shared/Squidex.Shared.csproj b/src/Squidex.Shared/Squidex.Shared.csproj index b70852495..51c30aaf0 100644 --- a/src/Squidex.Shared/Squidex.Shared.csproj +++ b/src/Squidex.Shared/Squidex.Shared.csproj @@ -9,7 +9,7 @@ - + diff --git a/src/Squidex.Web/CommandMiddlewares/ETagCommandMiddleware.cs b/src/Squidex.Web/CommandMiddlewares/ETagCommandMiddleware.cs index 0ebb669f3..06cf91311 100644 --- a/src/Squidex.Web/CommandMiddlewares/ETagCommandMiddleware.cs +++ b/src/Squidex.Web/CommandMiddlewares/ETagCommandMiddleware.cs @@ -26,7 +26,9 @@ namespace Squidex.Web.CommandMiddlewares public async Task HandleAsync(CommandContext context, Func next) { - if (httpContextAccessor.HttpContext == null) + var httpContext = httpContextAccessor.HttpContext; + + if (httpContext == null) { await next(); @@ -35,7 +37,7 @@ namespace Squidex.Web.CommandMiddlewares context.Command.ExpectedVersion = EtagVersion.Any; - var headers = httpContextAccessor.HttpContext.Request.Headers; + var headers = httpContext.Request.Headers; if (headers.TryGetValue(HeaderNames.IfMatch, out var etag) && !string.IsNullOrWhiteSpace(etag)) { @@ -56,7 +58,7 @@ namespace Squidex.Web.CommandMiddlewares if (context.PlainResult is EntitySavedResult result) { - httpContextAccessor.HttpContext.Response.Headers[HeaderNames.ETag] = result.Version.ToString(); + httpContext.Response.Headers[HeaderNames.ETag] = result.Version.ToString(); } } } diff --git a/src/Squidex/Squidex.csproj b/src/Squidex/Squidex.csproj index a6db529aa..df440715e 100644 --- a/src/Squidex/Squidex.csproj +++ b/src/Squidex/Squidex.csproj @@ -63,21 +63,21 @@ - - - - - - - + + + + + + + - + - - - + + + diff --git a/src/Squidex/appsettings.json b/src/Squidex/appsettings.json index 70a795373..45c7851a7 100644 --- a/src/Squidex/appsettings.json +++ b/src/Squidex/appsettings.json @@ -354,9 +354,9 @@ */ "database": "Squidex", /* - * Indicate wheter the connection string is for cosmos db. + * The MongoDb Engine. Supported: MongoDb, CosmosDb, DocumentDb */ - "isCosmosDB": "false" + "engine": "MongoDb" } }, diff --git a/tests/Squidex.Domain.Apps.Core.Tests/Squidex.Domain.Apps.Core.Tests.csproj b/tests/Squidex.Domain.Apps.Core.Tests/Squidex.Domain.Apps.Core.Tests.csproj index bd553242c..7c5aefb48 100644 --- a/tests/Squidex.Domain.Apps.Core.Tests/Squidex.Domain.Apps.Core.Tests.csproj +++ b/tests/Squidex.Domain.Apps.Core.Tests/Squidex.Domain.Apps.Core.Tests.csproj @@ -12,11 +12,11 @@ - + - + - + diff --git a/tests/Squidex.Domain.Apps.Entities.Tests/Squidex.Domain.Apps.Entities.Tests.csproj b/tests/Squidex.Domain.Apps.Entities.Tests/Squidex.Domain.Apps.Entities.Tests.csproj index 4c48bcdba..1ff7a0929 100644 --- a/tests/Squidex.Domain.Apps.Entities.Tests/Squidex.Domain.Apps.Entities.Tests.csproj +++ b/tests/Squidex.Domain.Apps.Entities.Tests/Squidex.Domain.Apps.Entities.Tests.csproj @@ -17,13 +17,13 @@ - + - - + + - + diff --git a/tests/Squidex.Domain.Users.Tests/Squidex.Domain.Users.Tests.csproj b/tests/Squidex.Domain.Users.Tests/Squidex.Domain.Users.Tests.csproj index 23cf6dbe4..984d6f806 100644 --- a/tests/Squidex.Domain.Users.Tests/Squidex.Domain.Users.Tests.csproj +++ b/tests/Squidex.Domain.Users.Tests/Squidex.Domain.Users.Tests.csproj @@ -12,11 +12,11 @@ - + - + - + diff --git a/tests/Squidex.Infrastructure.Tests/Squidex.Infrastructure.Tests.csproj b/tests/Squidex.Infrastructure.Tests/Squidex.Infrastructure.Tests.csproj index a50b7fc40..3230df80c 100644 --- a/tests/Squidex.Infrastructure.Tests/Squidex.Infrastructure.Tests.csproj +++ b/tests/Squidex.Infrastructure.Tests/Squidex.Infrastructure.Tests.csproj @@ -18,14 +18,14 @@ - + - + - + diff --git a/tests/Squidex.Web.Tests/Squidex.Web.Tests.csproj b/tests/Squidex.Web.Tests/Squidex.Web.Tests.csproj index 75c5e5e66..47b122f8f 100644 --- a/tests/Squidex.Web.Tests/Squidex.Web.Tests.csproj +++ b/tests/Squidex.Web.Tests/Squidex.Web.Tests.csproj @@ -11,13 +11,13 @@ - + - - + + - + all diff --git a/tools/Migrate_00/Migrate_00.csproj b/tools/Migrate_00/Migrate_00.csproj index ca15a7163..65bb2fb6a 100644 --- a/tools/Migrate_00/Migrate_00.csproj +++ b/tools/Migrate_00/Migrate_00.csproj @@ -6,9 +6,9 @@ 7.3 - + - + ..\..\Squidex.ruleset diff --git a/tools/Migrate_01/Migrate_01.csproj b/tools/Migrate_01/Migrate_01.csproj index 30b235cec..c2bda99af 100644 --- a/tools/Migrate_01/Migrate_01.csproj +++ b/tools/Migrate_01/Migrate_01.csproj @@ -5,7 +5,7 @@ - +