Browse Source

Use concrete field names to have less issues with conventions later.

pull/908/head
Sebastian 3 years ago
parent
commit
7842f41ed1
  1. 1
      backend/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/MongoContentEntity.cs
  2. 3
      backend/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/Operations/Extensions.cs
  3. 8
      backend/src/Squidex.Domain.Apps.Entities.MongoDb/MongoCountEntity.cs
  4. 25
      backend/src/Squidex.Domain.Apps.Entities.MongoDb/Rules/MongoRuleEventEntity.cs
  5. 3
      backend/src/Squidex.Domain.Apps.Entities.MongoDb/Schemas/MongoSchemasHashEntity.cs
  6. 2
      backend/src/Squidex.Domain.Apps.Entities.MongoDb/Text/MongoTextIndexBase.cs
  7. 5
      backend/src/Squidex.Domain.Apps.Entities.MongoDb/Text/MongoTextIndexEntity.cs
  8. 7
      backend/src/Squidex.Infrastructure.MongoDb/Caching/MongoCacheEntry.cs
  9. 4
      backend/src/Squidex.Infrastructure.MongoDb/EventSourcing/MongoEvent.cs
  10. 10
      backend/src/Squidex.Infrastructure.MongoDb/EventSourcing/MongoEventCommit.cs
  11. 8
      backend/src/Squidex.Infrastructure.MongoDb/Log/MongoRequest.cs
  12. 5
      backend/src/Squidex.Infrastructure.MongoDb/Migrations/MongoMigrationEntity.cs
  13. 9
      backend/src/Squidex.Infrastructure.MongoDb/MongoDb/BsonJsonConvention.cs
  14. 1
      backend/src/Squidex.Infrastructure.MongoDb/MongoDb/MongoBase.cs
  15. 6
      backend/src/Squidex.Infrastructure.MongoDb/States/MongoState.cs
  16. 11
      backend/src/Squidex.Infrastructure.MongoDb/UsageTracking/MongoUsage.cs

1
backend/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/MongoContentEntity.cs

@ -18,7 +18,6 @@ using Squidex.Infrastructure.States;
namespace Squidex.Domain.Apps.Entities.MongoDb.Contents namespace Squidex.Domain.Apps.Entities.MongoDb.Contents
{ {
[BsonIgnoreExtraElements]
public sealed class MongoContentEntity : IContentEntity, IVersionedEntity<DomainId> public sealed class MongoContentEntity : IContentEntity, IVersionedEntity<DomainId>
{ {
[BsonId] [BsonId]

3
backend/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/Operations/Extensions.cs

@ -16,7 +16,6 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents.Operations
{ {
public static class Extensions public static class Extensions
{ {
[BsonIgnoreExtraElements]
public sealed class StatusOnly public sealed class StatusOnly
{ {
[BsonId] [BsonId]
@ -36,13 +35,13 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents.Operations
public Status Status { get; set; } public Status Status { get; set; }
} }
[BsonIgnoreExtraElements]
public sealed class IdOnly public sealed class IdOnly
{ {
[BsonId] [BsonId]
[BsonElement("_id")] [BsonElement("_id")]
public DomainId Id { get; set; } public DomainId Id { get; set; }
[BsonElement(nameof(Joined))]
public MongoContentEntity[] Joined { get; set; } public MongoContentEntity[] Joined { get; set; }
} }

8
backend/src/Squidex.Domain.Apps.Entities.MongoDb/MongoCountEntity.cs

@ -13,13 +13,15 @@ namespace Squidex.Domain.Apps.Entities.MongoDb
internal sealed class MongoCountEntity internal sealed class MongoCountEntity
{ {
[BsonId] [BsonId]
[BsonRequired] [BsonElement("_id")]
public string Key { get; set; } public string Key { get; set; }
[BsonElement] [BsonRequired]
[BsonElement(nameof(Count))]
public long Count { get; set; } public long Count { get; set; }
[BsonElement] [BsonRequired]
[BsonElement(nameof(Created))]
public Instant Created { get; set; } public Instant Created { get; set; }
} }
} }

25
backend/src/Squidex.Domain.Apps.Entities.MongoDb/Rules/MongoRuleEventEntity.cs

@ -17,58 +17,57 @@ using Squidex.Infrastructure.Reflection;
namespace Squidex.Domain.Apps.Entities.MongoDb.Rules namespace Squidex.Domain.Apps.Entities.MongoDb.Rules
{ {
[BsonIgnoreExtraElements]
public sealed class MongoRuleEventEntity : IRuleEventEntity public sealed class MongoRuleEventEntity : IRuleEventEntity
{ {
[BsonId] [BsonId]
[BsonElement] [BsonElement("_id")]
public DomainId JobId { get; set; } public DomainId JobId { get; set; }
[BsonRequired] [BsonRequired]
[BsonElement] [BsonElement(nameof(AppId))]
public DomainId AppId { get; set; } public DomainId AppId { get; set; }
[BsonIgnoreIfDefault] [BsonIgnoreIfDefault]
[BsonElement] [BsonElement(nameof(RuleId))]
public DomainId RuleId { get; set; } public DomainId RuleId { get; set; }
[BsonRequired] [BsonRequired]
[BsonElement] [BsonElement(nameof(Created))]
public Instant Created { get; set; } public Instant Created { get; set; }
[BsonRequired] [BsonRequired]
[BsonElement] [BsonElement(nameof(LastModified))]
public Instant LastModified { get; set; } public Instant LastModified { get; set; }
[BsonRequired] [BsonRequired]
[BsonElement] [BsonElement(nameof(Result))]
[BsonRepresentation(BsonType.String)] [BsonRepresentation(BsonType.String)]
public RuleResult Result { get; set; } public RuleResult Result { get; set; }
[BsonRequired] [BsonRequired]
[BsonElement] [BsonElement(nameof(JobResult))]
[BsonRepresentation(BsonType.String)] [BsonRepresentation(BsonType.String)]
public RuleJobResult JobResult { get; set; } public RuleJobResult JobResult { get; set; }
[BsonRequired] [BsonRequired]
[BsonElement] [BsonElement(nameof(Job))]
[BsonJson] [BsonJson]
public RuleJob Job { get; set; } public RuleJob Job { get; set; }
[BsonRequired] [BsonRequired]
[BsonElement] [BsonElement(nameof(LastDump))]
public string? LastDump { get; set; } public string? LastDump { get; set; }
[BsonRequired] [BsonRequired]
[BsonElement] [BsonElement(nameof(NumCalls))]
public int NumCalls { get; set; } public int NumCalls { get; set; }
[BsonRequired] [BsonRequired]
[BsonElement] [BsonElement(nameof(Expires))]
public Instant Expires { get; set; } public Instant Expires { get; set; }
[BsonRequired] [BsonRequired]
[BsonElement] [BsonElement(nameof(NextAttempt))]
public Instant? NextAttempt { get; set; } public Instant? NextAttempt { get; set; }
DomainId IWithId<DomainId>.Id DomainId IWithId<DomainId>.Id

3
backend/src/Squidex.Domain.Apps.Entities.MongoDb/Schemas/MongoSchemasHashEntity.cs

@ -11,11 +11,10 @@ using Squidex.Infrastructure;
namespace Squidex.Domain.Apps.Entities.MongoDb.Schemas namespace Squidex.Domain.Apps.Entities.MongoDb.Schemas
{ {
[BsonIgnoreExtraElements]
public sealed class MongoSchemasHashEntity public sealed class MongoSchemasHashEntity
{ {
[BsonId] [BsonId]
[BsonElement] [BsonElement("_id")]
public DomainId AppId { get; set; } public DomainId AppId { get; set; }
[BsonRequired] [BsonRequired]

2
backend/src/Squidex.Domain.Apps.Entities.MongoDb/Text/MongoTextIndexBase.cs

@ -24,12 +24,10 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Text
{ {
[BsonId] [BsonId]
[BsonElement] [BsonElement]
[BsonRepresentation(BsonType.String)]
public string Id { get; set; } public string Id { get; set; }
[BsonRequired] [BsonRequired]
[BsonElement("_ci")] [BsonElement("_ci")]
[BsonRepresentation(BsonType.String)]
public DomainId ContentId { get; set; } public DomainId ContentId { get; set; }
[BsonIgnoreIfDefault] [BsonIgnoreIfDefault]

5
backend/src/Squidex.Domain.Apps.Entities.MongoDb/Text/MongoTextIndexEntity.cs

@ -16,12 +16,11 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Text
public sealed class MongoTextIndexEntity<T> public sealed class MongoTextIndexEntity<T>
{ {
[BsonId] [BsonId]
[BsonElement] [BsonElement("_id")]
[BsonRepresentation(BsonType.String)]
public string Id { get; set; } public string Id { get; set; }
[BsonRequired] [BsonRequired]
[BsonElement] [BsonElement(nameof(DocId))]
public string DocId { get; set; } public string DocId { get; set; }
[BsonRequired] [BsonRequired]

7
backend/src/Squidex.Infrastructure.MongoDb/Caching/MongoCacheEntry.cs

@ -12,12 +12,15 @@ namespace Squidex.Infrastructure.Caching
public sealed class MongoCacheEntry public sealed class MongoCacheEntry
{ {
[BsonId] [BsonId]
[BsonElement("_id")]
public string Key { get; set; } public string Key { get; set; }
[BsonElement] [BsonRequired]
[BsonElement(nameof(Expires))]
public DateTime Expires { get; set; } public DateTime Expires { get; set; }
[BsonElement] [BsonRequired]
[BsonElement(nameof(Value))]
public byte[] Value { get; set; } public byte[] Value { get; set; }
} }
} }

4
backend/src/Squidex.Infrastructure.MongoDb/EventSourcing/MongoEvent.cs

@ -6,7 +6,6 @@
// ========================================================================== // ==========================================================================
using MongoDB.Bson.Serialization.Attributes; using MongoDB.Bson.Serialization.Attributes;
using Squidex.Infrastructure.MongoDb;
namespace Squidex.Infrastructure.EventSourcing namespace Squidex.Infrastructure.EventSourcing
{ {
@ -17,10 +16,11 @@ namespace Squidex.Infrastructure.EventSourcing
public string Type { get; set; } public string Type { get; set; }
[BsonRequired] [BsonRequired]
[BsonElement(nameof(Payload))]
public string Payload { get; set; } public string Payload { get; set; }
[BsonElement("Metadata")]
[BsonRequired] [BsonRequired]
[BsonElement("Metadata")]
public EnvelopeHeaders Headers { get; set; } public EnvelopeHeaders Headers { get; set; }
public static MongoEvent FromEventData(EventData data) public static MongoEvent FromEventData(EventData data)

10
backend/src/Squidex.Infrastructure.MongoDb/EventSourcing/MongoEventCommit.cs

@ -18,23 +18,23 @@ namespace Squidex.Infrastructure.EventSourcing
public Guid Id { get; set; } public Guid Id { get; set; }
[BsonRequired] [BsonRequired]
[BsonElement] [BsonElement(nameof(Timestamp))]
public BsonTimestamp Timestamp { get; set; } public BsonTimestamp Timestamp { get; set; }
[BsonElement]
[BsonRequired] [BsonRequired]
[BsonElement(nameof(Events))]
public MongoEvent[] Events { get; set; } public MongoEvent[] Events { get; set; }
[BsonElement]
[BsonRequired] [BsonRequired]
[BsonElement(nameof(EventStreamOffset))]
public long EventStreamOffset { get; set; } public long EventStreamOffset { get; set; }
[BsonElement]
[BsonRequired] [BsonRequired]
[BsonElement(nameof(EventsCount))]
public long EventsCount { get; set; } public long EventsCount { get; set; }
[BsonElement]
[BsonRequired] [BsonRequired]
[BsonElement(nameof(EventStream))]
public string EventStream { get; set; } public string EventStream { get; set; }
} }
} }

8
backend/src/Squidex.Infrastructure.MongoDb/Log/MongoRequest.cs

@ -14,19 +14,19 @@ namespace Squidex.Infrastructure.Log
public sealed class MongoRequest public sealed class MongoRequest
{ {
[BsonId] [BsonId]
[BsonElement] [BsonElement("_id")]
public ObjectId Id { get; set; } public ObjectId Id { get; set; }
[BsonElement]
[BsonRequired] [BsonRequired]
[BsonElement(nameof(Key))]
public string Key { get; set; } public string Key { get; set; }
[BsonElement]
[BsonRequired] [BsonRequired]
[BsonElement(nameof(Timestamp))]
public Instant Timestamp { get; set; } public Instant Timestamp { get; set; }
[BsonElement]
[BsonRequired] [BsonRequired]
[BsonElement(nameof(Properties))]
public Dictionary<string, string> Properties { get; set; } public Dictionary<string, string> Properties { get; set; }
public static MongoRequest FromRequest(Request request) public static MongoRequest FromRequest(Request request)

5
backend/src/Squidex.Infrastructure.MongoDb/Migrations/MongoMigrationEntity.cs

@ -13,12 +13,11 @@ namespace Squidex.Infrastructure.Migrations
public sealed class MongoMigrationEntity public sealed class MongoMigrationEntity
{ {
[BsonId] [BsonId]
[BsonElement] [BsonElement("_id")]
[BsonRepresentation(BsonType.String)]
public string Id { get; set; } public string Id { get; set; }
[BsonElement]
[BsonRequired] [BsonRequired]
[BsonElement(nameof(IsLocked))]
public bool IsLocked { get; set; } public bool IsLocked { get; set; }
[BsonElement] [BsonElement]

9
backend/src/Squidex.Infrastructure.MongoDb/MongoDb/BsonJsonConvention.cs

@ -15,6 +15,8 @@ namespace Squidex.Infrastructure.MongoDb
{ {
public static class BsonJsonConvention public static class BsonJsonConvention
{ {
private static bool isRegistered;
public static JsonSerializerOptions Options { get; set; } = new JsonSerializerOptions(JsonSerializerDefaults.Web); public static JsonSerializerOptions Options { get; set; } = new JsonSerializerOptions(JsonSerializerDefaults.Web);
public static void Register(JsonSerializerOptions? options = null) public static void Register(JsonSerializerOptions? options = null)
@ -26,6 +28,11 @@ namespace Squidex.Infrastructure.MongoDb
Options = options; Options = options;
} }
if (isRegistered)
{
return;
}
var pack = new ConventionPack(); var pack = new ConventionPack();
pack.AddMemberMapConvention("JsonBson", memberMap => pack.AddMemberMapConvention("JsonBson", memberMap =>
@ -42,6 +49,8 @@ namespace Squidex.Infrastructure.MongoDb
}); });
ConventionRegistry.Register("json", pack, t => true); ConventionRegistry.Register("json", pack, t => true);
isRegistered = true;
} }
catch (BsonSerializationException) catch (BsonSerializationException)
{ {

1
backend/src/Squidex.Infrastructure.MongoDb/MongoDb/MongoBase.cs

@ -46,6 +46,7 @@ namespace Squidex.Infrastructure.MongoDb
static MongoBase() static MongoBase()
{ {
BsonDefaultConventions.Register();
BsonDomainIdSerializer.Register(); BsonDomainIdSerializer.Register();
BsonInstantSerializer.Register(); BsonInstantSerializer.Register();
BsonJsonConvention.Register(); BsonJsonConvention.Register();

6
backend/src/Squidex.Infrastructure.MongoDb/States/MongoState.cs

@ -11,12 +11,10 @@ using Squidex.Infrastructure.MongoDb;
namespace Squidex.Infrastructure.States namespace Squidex.Infrastructure.States
{ {
[BsonIgnoreExtraElements]
public class MongoState<T> : IVersionedEntity<DomainId> public class MongoState<T> : IVersionedEntity<DomainId>
{ {
[BsonId] [BsonId]
[BsonElement] [BsonElement("_id")]
[BsonRepresentation(BsonType.String)]
public DomainId DocumentId { get; set; } public DomainId DocumentId { get; set; }
[BsonRequired] [BsonRequired]
@ -25,7 +23,7 @@ namespace Squidex.Infrastructure.States
public T Document { get; set; } public T Document { get; set; }
[BsonRequired] [BsonRequired]
[BsonElement] [BsonElement(nameof(Version))]
public long Version { get; set; } public long Version { get; set; }
public virtual void Prepare() public virtual void Prepare()

11
backend/src/Squidex.Infrastructure.MongoDb/UsageTracking/MongoUsage.cs

@ -13,25 +13,24 @@ namespace Squidex.Infrastructure.UsageTracking
public sealed class MongoUsage public sealed class MongoUsage
{ {
[BsonId] [BsonId]
[BsonElement] [BsonElement("_id")]
[BsonRepresentation(BsonType.String)]
public string Id { get; set; } public string Id { get; set; }
[BsonRequired] [BsonRequired]
[BsonElement] [BsonElement(nameof(Date))]
[BsonDateTimeOptions(DateOnly = true)] [BsonDateTimeOptions(DateOnly = true)]
public DateTime Date { get; set; } public DateTime Date { get; set; }
[BsonRequired] [BsonRequired]
[BsonElement] [BsonElement(nameof(Key))]
public string Key { get; set; } public string Key { get; set; }
[BsonIgnoreIfNull] [BsonIgnoreIfNull]
[BsonElement] [BsonElement(nameof(Category))]
public string Category { get; set; } public string Category { get; set; }
[BsonRequired] [BsonRequired]
[BsonElement] [BsonElement(nameof(Counters))]
public Counters Counters { get; set; } = new Counters(); public Counters Counters { get; set; } = new Counters();
} }
} }

Loading…
Cancel
Save