Browse Source

Remove support for other mongodb engines.

pull/397/head
Sebastian 7 years ago
parent
commit
a2d003423d
  1. 58
      src/Squidex.Domain.Apps.Entities.MongoDb/Assets/MongoAssetRepository.cs
  2. 4
      src/Squidex.Domain.Apps.Entities.MongoDb/Contents/MongoContentCollection.cs
  3. 4
      src/Squidex.Domain.Apps.Entities.MongoDb/Contents/MongoContentRepository.cs
  4. 32
      src/Squidex.Domain.Apps.Entities.MongoDb/History/MongoHistoryEventRepository.cs
  5. 25
      src/Squidex.Domain.Apps.Entities.MongoDb/Rules/MongoRuleEventRepository.cs
  6. 15
      src/Squidex.Domain.Users.MongoDb/Infrastructure/MongoPersistedGrantStore.cs
  7. 10
      src/Squidex.Domain.Users.MongoDb/MongoRoleStore.cs
  8. 53
      src/Squidex.Domain.Users.MongoDb/MongoUserStore.cs
  9. 25
      src/Squidex.Infrastructure.MongoDb/EventSourcing/MongoEventStore.cs
  10. 4
      src/Squidex.Infrastructure.MongoDb/Migrations/MongoMigrationStatus.cs
  11. 15
      src/Squidex.Infrastructure.MongoDb/MongoDb/MongoDbEngine.cs
  12. 24
      src/Squidex.Infrastructure.MongoDb/MongoDb/MongoDbOptions.cs
  13. 16
      src/Squidex.Infrastructure.MongoDb/MongoDb/MongoRepositoryBase.cs
  14. 4
      src/Squidex.Infrastructure.MongoDb/States/MongoSnapshotStore.cs
  15. 4
      src/Squidex.Infrastructure.MongoDb/UsageTracking/MongoUsageRepository.cs
  16. 2
      src/Squidex/Config/Domain/EventStoreServices.cs
  17. 3
      src/Squidex/Config/Domain/StoreServices.cs
  18. 6
      src/Squidex/appsettings.json
  19. 2
      tests/Squidex.Infrastructure.Tests/EventSourcing/MongoEventStoreFixture.cs

58
src/Squidex.Domain.Apps.Entities.MongoDb/Assets/MongoAssetRepository.cs

@ -24,8 +24,8 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Assets
{
public sealed partial class MongoAssetRepository : MongoRepositoryBase<MongoAssetEntity>, IAssetRepository
{
public MongoAssetRepository(IMongoDatabase database, IOptions<MongoDbOptions> options)
: base(database, options)
public MongoAssetRepository(IMongoDatabase database)
: base(database)
{
}
@ -36,40 +36,26 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Assets
protected override Task SetupCollectionAsync(IMongoCollection<MongoAssetEntity> collection, CancellationToken ct = default)
{
return collection.Indexes.CreateManyAsync(
new[]
{
new CreateIndexModel<MongoAssetEntity>(
Index
.Ascending(x => x.AppId)
.Ascending(x => x.IsDeleted)
.Ascending(x => x.FileName)
.Ascending(x => x.Tags)
.Descending(x => x.LastModified),
new CreateIndexOptions
{
Name = Options.IsDocumentDb ? "FileName_Tags" : null
}),
new CreateIndexModel<MongoAssetEntity>(
Index
.Ascending(x => x.AppId)
.Ascending(x => x.IsDeleted)
.Ascending(x => x.FileHash),
new CreateIndexOptions
{
Name = Options.IsDocumentDb ? "FileHash" : null
}),
new CreateIndexModel<MongoAssetEntity>(
Index
.Ascending(x => x.AppId)
.Ascending(x => x.IsDeleted)
.Ascending(x => x.Slug),
new CreateIndexOptions
{
Name = Options.IsDocumentDb ? "Slug" : null
})
},
ct);
return collection.Indexes.CreateManyAsync(new[]
{
new CreateIndexModel<MongoAssetEntity>(
Index
.Ascending(x => x.AppId)
.Ascending(x => x.IsDeleted)
.Ascending(x => x.FileName)
.Ascending(x => x.Tags)
.Descending(x => x.LastModified)),
new CreateIndexModel<MongoAssetEntity>(
Index
.Ascending(x => x.AppId)
.Ascending(x => x.IsDeleted)
.Ascending(x => x.FileHash)),
new CreateIndexModel<MongoAssetEntity>(
Index
.Ascending(x => x.AppId)
.Ascending(x => x.IsDeleted)
.Ascending(x => x.Slug))
}, ct);
}
public async Task<IResultList<IAssetEntity>> QueryAsync(Guid appId, ClrQuery query)

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

@ -34,8 +34,8 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents
private readonly IAppProvider appProvider;
private readonly IJsonSerializer serializer;
public MongoContentCollection(IMongoDatabase database, IOptions<MongoDbOptions> options, IJsonSerializer serializer, IAppProvider appProvider)
: base(database, options)
public MongoContentCollection(IMongoDatabase database, IJsonSerializer serializer, IAppProvider appProvider)
: base(database)
{
this.appProvider = appProvider;

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

@ -43,7 +43,7 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents
StatusSerializer.Register();
}
public MongoContentRepository(IMongoDatabase database, IOptions<MongoDbOptions> options, IAppProvider appProvider, IJsonSerializer serializer, ITextIndexer indexer, TypeNameRegistry typeNameRegistry)
public MongoContentRepository(IMongoDatabase database, IAppProvider appProvider, IJsonSerializer serializer, ITextIndexer indexer, TypeNameRegistry typeNameRegistry)
{
Guard.NotNull(appProvider, nameof(appProvider));
Guard.NotNull(database, nameof(database));
@ -59,7 +59,7 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents
typeAssetDeleted = typeNameRegistry.GetName<AssetDeleted>();
typeContentDeleted = typeNameRegistry.GetName<ContentDeleted>();
contents = new MongoContentCollection(database, options, serializer, appProvider);
contents = new MongoContentCollection(database, serializer, appProvider);
}
public Task InitializeAsync(CancellationToken ct = default)

32
src/Squidex.Domain.Apps.Entities.MongoDb/History/MongoHistoryEventRepository.cs

@ -19,8 +19,8 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.History
{
public class MongoHistoryEventRepository : MongoRepositoryBase<HistoryEvent>, IHistoryEventRepository
{
public MongoHistoryEventRepository(IMongoDatabase database, IOptions<MongoDbOptions> options)
: base(database, options)
public MongoHistoryEventRepository(IMongoDatabase database)
: base(database)
{
}
@ -31,18 +31,22 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.History
protected override Task SetupCollectionAsync(IMongoCollection<HistoryEvent> collection, CancellationToken ct = default)
{
return collection.Indexes.CreateManyAsync(
new[]
{
new CreateIndexModel<HistoryEvent>(
Index
.Ascending(x => x.AppId)
.Ascending(x => x.Channel)
.Descending(x => x.Created)
.Descending(x => x.Version)),
new CreateIndexModel<HistoryEvent>(Index.Ascending(x => x.Created),
new CreateIndexOptions { ExpireAfter = TimeSpan.FromDays(365) })
}, ct);
return collection.Indexes.CreateManyAsync(new[]
{
new CreateIndexModel<HistoryEvent>(
Index
.Ascending(x => x.AppId)
.Ascending(x => x.Channel)
.Descending(x => x.Created)
.Descending(x => x.Version)),
new CreateIndexModel<HistoryEvent>(
Index
.Ascending(x => x.Created),
new CreateIndexOptions
{
ExpireAfter = TimeSpan.FromDays(365)
})
}, ct);
}
public async Task<IReadOnlyList<HistoryEvent>> QueryByChannelAsync(Guid appId, string channelPrefix, int count)

25
src/Squidex.Domain.Apps.Entities.MongoDb/Rules/MongoRuleEventRepository.cs

@ -23,8 +23,8 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Rules
{
public sealed class MongoRuleEventRepository : MongoRepositoryBase<MongoRuleEventEntity>, IRuleEventRepository
{
public MongoRuleEventRepository(IMongoDatabase database, IOptions<MongoDbOptions> options)
: base(database, options)
public MongoRuleEventRepository(IMongoDatabase database)
: base(database)
{
}
@ -33,15 +33,20 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Rules
return "RuleEvents";
}
protected override async Task SetupCollectionAsync(IMongoCollection<MongoRuleEventEntity> collection, CancellationToken ct = default)
protected override Task SetupCollectionAsync(IMongoCollection<MongoRuleEventEntity> collection, CancellationToken ct = default)
{
await collection.Indexes.CreateManyAsync(
new[]
{
new CreateIndexModel<MongoRuleEventEntity>(Index.Ascending(x => x.NextAttempt)),
new CreateIndexModel<MongoRuleEventEntity>(Index.Ascending(x => x.AppId).Descending(x => x.Created)),
new CreateIndexModel<MongoRuleEventEntity>(Index.Ascending(x => x.Expires), new CreateIndexOptions { ExpireAfter = TimeSpan.Zero })
}, ct);
return collection.Indexes.CreateManyAsync(new[]
{
new CreateIndexModel<MongoRuleEventEntity>(Index.Ascending(x => x.NextAttempt)),
new CreateIndexModel<MongoRuleEventEntity>(Index.Ascending(x => x.AppId).Descending(x => x.Created)),
new CreateIndexModel<MongoRuleEventEntity>(
Index
.Ascending(x => x.Expires),
new CreateIndexOptions
{
ExpireAfter = TimeSpan.Zero
})
}, ct);
}
public Task QueryPendingAsync(Instant now, Func<IRuleEventEntity, Task> callback, CancellationToken ct = default)

15
src/Squidex.Domain.Users.MongoDb/Infrastructure/MongoPersistedGrantStore.cs

@ -31,8 +31,8 @@ namespace Squidex.Domain.Users.MongoDb.Infrastructure
});
}
public MongoPersistedGrantStore(IMongoDatabase database, IOptions<MongoDbOptions> options)
: base(database, options)
public MongoPersistedGrantStore(IMongoDatabase database)
: base(database)
{
}
@ -43,12 +43,11 @@ namespace Squidex.Domain.Users.MongoDb.Infrastructure
protected override Task SetupCollectionAsync(IMongoCollection<PersistedGrant> collection, CancellationToken ct = default)
{
return collection.Indexes.CreateManyAsync(
new[]
{
new CreateIndexModel<PersistedGrant>(Index.Ascending(x => x.ClientId)),
new CreateIndexModel<PersistedGrant>(Index.Ascending(x => x.SubjectId))
}, ct);
return collection.Indexes.CreateManyAsync(new[]
{
new CreateIndexModel<PersistedGrant>(Index.Ascending(x => x.ClientId)),
new CreateIndexModel<PersistedGrant>(Index.Ascending(x => x.SubjectId))
}, ct);
}
public Task StoreAsync(PersistedGrant grant)

10
src/Squidex.Domain.Users.MongoDb/MongoRoleStore.cs

@ -31,8 +31,8 @@ namespace Squidex.Domain.Users.MongoDb
});
}
public MongoRoleStore(IMongoDatabase database, IOptions<MongoDbOptions> options)
: base(database, options)
public MongoRoleStore(IMongoDatabase database)
: base(database)
{
}
@ -41,17 +41,11 @@ namespace Squidex.Domain.Users.MongoDb
return "Identity_Roles";
}
protected override string ShardKey()
{
return "Shard";
}
protected override Task SetupCollectionAsync(IMongoCollection<IdentityRole> collection, CancellationToken ct = default)
{
return collection.Indexes.CreateOneAsync(
new CreateIndexModel<IdentityRole>(
Index
.Ascending("Shard")
.Ascending(x => x.NormalizedName),
new CreateIndexOptions
{

53
src/Squidex.Domain.Users.MongoDb/MongoUserStore.cs

@ -105,8 +105,8 @@ namespace Squidex.Domain.Users.MongoDb
});
}
public MongoUserStore(IMongoDatabase database, IOptions<MongoDbOptions> options)
: base(database, options)
public MongoUserStore(IMongoDatabase database)
: base(database)
{
}
@ -115,36 +115,29 @@ namespace Squidex.Domain.Users.MongoDb
return "Identity_Users";
}
protected override string ShardKey()
{
return "Shard";
}
protected override Task SetupCollectionAsync(IMongoCollection<MongoUser> collection, CancellationToken ct = default)
{
return collection.Indexes.CreateManyAsync(
new[]
{
Options.IsDocumentDb ?
new CreateIndexModel<MongoUser>(Index.Ascending("Logins.LoginProvider")) :
new CreateIndexModel<MongoUser>(Index.Ascending("Logins.LoginProvider").Ascending("Logins.ProviderKey")),
new CreateIndexModel<MongoUser>(
Index
.Ascending("Shard")
.Ascending(x => x.NormalizedUserName),
new CreateIndexOptions
{
Unique = true
}),
new CreateIndexModel<MongoUser>(
Index
.Ascending("Shard")
.Ascending(x => x.NormalizedEmail),
new CreateIndexOptions
{
Unique = true
})
}, ct);
return collection.Indexes.CreateManyAsync(new[]
{
new CreateIndexModel<MongoUser>(
Index
.Ascending("Logins.LoginProvider")
.Ascending("Logins.ProviderKey")),
new CreateIndexModel<MongoUser>(
Index
.Ascending(x => x.NormalizedUserName),
new CreateIndexOptions
{
Unique = true
}),
new CreateIndexModel<MongoUser>(
Index
.Ascending(x => x.NormalizedEmail),
new CreateIndexOptions
{
Unique = true
})
}, ct);
}
protected override MongoCollectionSettings CollectionSettings()

25
src/Squidex.Infrastructure.MongoDb/EventSourcing/MongoEventStore.cs

@ -27,8 +27,8 @@ namespace Squidex.Infrastructure.EventSourcing
get { return Database.GetCollection<BsonDocument>(CollectionName()); }
}
public MongoEventStore(IMongoDatabase database, IOptions<MongoDbOptions> options, IEventNotifier notifier)
: base(database, options)
public MongoEventStore(IMongoDatabase database, IEventNotifier notifier)
: base(database)
{
Guard.NotNull(notifier, nameof(notifier));
@ -47,12 +47,21 @@ namespace Squidex.Infrastructure.EventSourcing
protected override Task SetupCollectionAsync(IMongoCollection<MongoEventCommit> collection, CancellationToken ct = default)
{
return collection.Indexes.CreateManyAsync(
new[]
{
new CreateIndexModel<MongoEventCommit>(Index.Ascending(x => x.Timestamp).Ascending(x => x.EventStream)),
new CreateIndexModel<MongoEventCommit>(Index.Ascending(x => x.EventStream).Descending(x => x.EventStreamOffset), new CreateIndexOptions { Unique = true })
}, ct);
return collection.Indexes.CreateManyAsync(new[]
{
new CreateIndexModel<MongoEventCommit>(
Index
.Ascending(x => x.Timestamp)
.Ascending(x => x.EventStream)),
new CreateIndexModel<MongoEventCommit>(
Index
.Ascending(x => x.EventStream)
.Descending(x => x.EventStreamOffset),
new CreateIndexOptions
{
Unique = true
})
}, ct);
}
}
}

4
src/Squidex.Infrastructure.MongoDb/Migrations/MongoMigrationStatus.cs

@ -17,8 +17,8 @@ namespace Squidex.Infrastructure.Migrations
private const string DefaultId = "Default";
private static readonly FindOneAndUpdateOptions<MongoMigrationEntity> UpsertFind = new FindOneAndUpdateOptions<MongoMigrationEntity> { IsUpsert = true };
public MongoMigrationStatus(IMongoDatabase database, IOptions<MongoDbOptions> options)
: base(database, options)
public MongoMigrationStatus(IMongoDatabase database)
: base(database)
{
}

15
src/Squidex.Infrastructure.MongoDb/MongoDb/MongoDbEngine.cs

@ -1,15 +0,0 @@
// ==========================================================================
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex UG (haftungsbeschraenkt)
// All rights reserved. Licensed under the MIT license.
// ==========================================================================
namespace Squidex.Infrastructure.MongoDb
{
public enum MongoDbEngine
{
DocumentDb,
MongoDb,
}
}

24
src/Squidex.Infrastructure.MongoDb/MongoDb/MongoDbOptions.cs

@ -1,24 +0,0 @@
// ==========================================================================
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex UG (haftungsbeschraenkt)
// All rights reserved. Licensed under the MIT license.
// ==========================================================================
namespace Squidex.Infrastructure.MongoDb
{
public sealed class MongoDbOptions
{
public MongoDbEngine Engine { get; set; } = MongoDbEngine.MongoDb;
public bool IsDocumentDb
{
get { return Engine == MongoDbEngine.DocumentDb; }
}
public bool IsMongoDb
{
get { return Engine == MongoDbEngine.MongoDb; }
}
}
}

16
src/Squidex.Infrastructure.MongoDb/MongoDb/MongoRepositoryBase.cs

@ -31,7 +31,6 @@ namespace Squidex.Infrastructure.MongoDb
protected static readonly ProjectionDefinitionBuilder<TEntity> Projection = Builders<TEntity>.Projection;
private readonly IMongoDatabase mongoDatabase;
private readonly MongoDbOptions options;
private Lazy<IMongoCollection<TEntity>> mongoCollection;
protected IMongoCollection<TEntity> Collection
@ -44,11 +43,6 @@ namespace Squidex.Infrastructure.MongoDb
get { return mongoDatabase; }
}
protected MongoDbOptions Options
{
get { return options; }
}
static MongoRepositoryBase()
{
RefTokenSerializer.Register();
@ -56,15 +50,12 @@ namespace Squidex.Infrastructure.MongoDb
InstantSerializer.Register();
}
protected MongoRepositoryBase(IMongoDatabase database, IOptions<MongoDbOptions> options)
protected MongoRepositoryBase(IMongoDatabase database)
{
Guard.NotNull(database, nameof(database));
Guard.NotNull(options, nameof(options));
mongoDatabase = database;
mongoCollection = CreateCollection();
this.options = options.Value;
}
protected virtual MongoCollectionSettings CollectionSettings()
@ -72,11 +63,6 @@ namespace Squidex.Infrastructure.MongoDb
return new MongoCollectionSettings();
}
protected virtual string ShardKey()
{
return "_id";
}
protected virtual string CollectionName()
{
return string.Format(CultureInfo.InvariantCulture, CollectionFormat, typeof(TEntity).Name);

4
src/Squidex.Infrastructure.MongoDb/States/MongoSnapshotStore.cs

@ -20,8 +20,8 @@ namespace Squidex.Infrastructure.States
{
public class MongoSnapshotStore<T, TKey> : MongoRepositoryBase<MongoState<T, TKey>>, ISnapshotStore<T, TKey>
{
public MongoSnapshotStore(IMongoDatabase database, IOptions<MongoDbOptions> options, JsonSerializer jsonSerializer)
: base(database, options)
public MongoSnapshotStore(IMongoDatabase database, JsonSerializer jsonSerializer)
: base(database)
{
Guard.NotNull(jsonSerializer, nameof(jsonSerializer));

4
src/Squidex.Infrastructure.MongoDb/UsageTracking/MongoUsageRepository.cs

@ -20,8 +20,8 @@ namespace Squidex.Infrastructure.UsageTracking
{
private static readonly BulkWriteOptions Unordered = new BulkWriteOptions { IsOrdered = false };
public MongoUsageRepository(IMongoDatabase database, IOptions<MongoDbOptions> options)
: base(database, options)
public MongoUsageRepository(IMongoDatabase database)
: base(database)
{
}

2
src/Squidex/Config/Domain/EventStoreServices.cs

@ -40,7 +40,7 @@ namespace Squidex.Config.Domain
var mongoClient = Singletons<IMongoClient>.GetOrAdd(mongoConfiguration, s => new MongoClient(s));
var mongDatabase = mongoClient.GetDatabase(mongoDatabaseName);
return new MongoEventStore(mongDatabase, c.GetRequiredService<IOptions<MongoDbOptions>>(), c.GetRequiredService<IEventNotifier>());
return new MongoEventStore(mongDatabase, c.GetRequiredService<IEventNotifier>());
})
.As<IEventStore>();
},

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

@ -52,8 +52,6 @@ namespace Squidex.Config.Domain
var mongoDatabaseName = config.GetRequiredValue("store:mongoDb:database");
var mongoContentDatabaseName = config.GetOptionalValue("store:mongoDb:contentDatabase", mongoDatabaseName);
services.Configure<MongoDbOptions>(config.GetSection("store:mongoDB"));
services.AddSingleton(typeof(ISnapshotStore<,>), typeof(MongoSnapshotStore<,>));
services.AddSingletonAs(_ => Singletons<IMongoClient>.GetOrAdd(mongoConfiguration, s => new MongoClient(s)))
@ -105,7 +103,6 @@ namespace Squidex.Config.Domain
services.AddSingletonAs(c => new MongoContentRepository(
c.GetRequiredService<IMongoClient>().GetDatabase(mongoContentDatabaseName),
c.GetRequiredService<IOptions<MongoDbOptions>>(),
c.GetRequiredService<IAppProvider>(),
c.GetRequiredService<IJsonSerializer>(),
c.GetRequiredService<ITextIndexer>(),

6
src/Squidex/appsettings.json

@ -395,11 +395,7 @@
/*
* The database for all your other read collections.
*/
"database": "Squidex",
/*
* The MongoDb Engine. Supported: MongoDb, DocumentDb
*/
"engine": "MongoDb"
"database": "Squidex"
}
},

2
tests/Squidex.Infrastructure.Tests/EventSourcing/MongoEventStoreFixture.cs

@ -29,7 +29,7 @@ namespace Squidex.Infrastructure.EventSourcing
BsonJsonConvention.Register(JsonSerializer.Create(JsonHelper.DefaultSettings()));
EventStore = new MongoEventStore(mongoDatabase, Options.Create(new MongoDbOptions()), notifier);
EventStore = new MongoEventStore(mongoDatabase, notifier);
EventStore.InitializeAsync().Wait();
}

Loading…
Cancel
Save