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
{
[BsonIgnoreExtraElements]
public sealed class MongoContentEntity : IContentEntity, IVersionedEntity<DomainId>
{
[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
{
[BsonIgnoreExtraElements]
public sealed class StatusOnly
{
[BsonId]
@ -36,13 +35,13 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents.Operations
public Status Status { get; set; }
}
[BsonIgnoreExtraElements]
public sealed class IdOnly
{
[BsonId]
[BsonElement("_id")]
public DomainId Id { get; set; }
[BsonElement(nameof(Joined))]
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
{
[BsonId]
[BsonRequired]
[BsonElement("_id")]
public string Key { get; set; }
[BsonElement]
[BsonRequired]
[BsonElement(nameof(Count))]
public long Count { get; set; }
[BsonElement]
[BsonRequired]
[BsonElement(nameof(Created))]
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
{
[BsonIgnoreExtraElements]
public sealed class MongoRuleEventEntity : IRuleEventEntity
{
[BsonId]
[BsonElement]
[BsonElement("_id")]
public DomainId JobId { get; set; }
[BsonRequired]
[BsonElement]
[BsonElement(nameof(AppId))]
public DomainId AppId { get; set; }
[BsonIgnoreIfDefault]
[BsonElement]
[BsonElement(nameof(RuleId))]
public DomainId RuleId { get; set; }
[BsonRequired]
[BsonElement]
[BsonElement(nameof(Created))]
public Instant Created { get; set; }
[BsonRequired]
[BsonElement]
[BsonElement(nameof(LastModified))]
public Instant LastModified { get; set; }
[BsonRequired]
[BsonElement]
[BsonElement(nameof(Result))]
[BsonRepresentation(BsonType.String)]
public RuleResult Result { get; set; }
[BsonRequired]
[BsonElement]
[BsonElement(nameof(JobResult))]
[BsonRepresentation(BsonType.String)]
public RuleJobResult JobResult { get; set; }
[BsonRequired]
[BsonElement]
[BsonElement(nameof(Job))]
[BsonJson]
public RuleJob Job { get; set; }
[BsonRequired]
[BsonElement]
[BsonElement(nameof(LastDump))]
public string? LastDump { get; set; }
[BsonRequired]
[BsonElement]
[BsonElement(nameof(NumCalls))]
public int NumCalls { get; set; }
[BsonRequired]
[BsonElement]
[BsonElement(nameof(Expires))]
public Instant Expires { get; set; }
[BsonRequired]
[BsonElement]
[BsonElement(nameof(NextAttempt))]
public Instant? NextAttempt { get; set; }
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
{
[BsonIgnoreExtraElements]
public sealed class MongoSchemasHashEntity
{
[BsonId]
[BsonElement]
[BsonElement("_id")]
public DomainId AppId { get; set; }
[BsonRequired]

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

@ -24,12 +24,10 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Text
{
[BsonId]
[BsonElement]
[BsonRepresentation(BsonType.String)]
public string Id { get; set; }
[BsonRequired]
[BsonElement("_ci")]
[BsonRepresentation(BsonType.String)]
public DomainId ContentId { get; set; }
[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>
{
[BsonId]
[BsonElement]
[BsonRepresentation(BsonType.String)]
[BsonElement("_id")]
public string Id { get; set; }
[BsonRequired]
[BsonElement]
[BsonElement(nameof(DocId))]
public string DocId { get; set; }
[BsonRequired]

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

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

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

@ -6,7 +6,6 @@
// ==========================================================================
using MongoDB.Bson.Serialization.Attributes;
using Squidex.Infrastructure.MongoDb;
namespace Squidex.Infrastructure.EventSourcing
{
@ -17,10 +16,11 @@ namespace Squidex.Infrastructure.EventSourcing
public string Type { get; set; }
[BsonRequired]
[BsonElement(nameof(Payload))]
public string Payload { get; set; }
[BsonElement("Metadata")]
[BsonRequired]
[BsonElement("Metadata")]
public EnvelopeHeaders Headers { get; set; }
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; }
[BsonRequired]
[BsonElement]
[BsonElement(nameof(Timestamp))]
public BsonTimestamp Timestamp { get; set; }
[BsonElement]
[BsonRequired]
[BsonElement(nameof(Events))]
public MongoEvent[] Events { get; set; }
[BsonElement]
[BsonRequired]
[BsonElement(nameof(EventStreamOffset))]
public long EventStreamOffset { get; set; }
[BsonElement]
[BsonRequired]
[BsonElement(nameof(EventsCount))]
public long EventsCount { get; set; }
[BsonElement]
[BsonRequired]
[BsonElement(nameof(EventStream))]
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
{
[BsonId]
[BsonElement]
[BsonElement("_id")]
public ObjectId Id { get; set; }
[BsonElement]
[BsonRequired]
[BsonElement(nameof(Key))]
public string Key { get; set; }
[BsonElement]
[BsonRequired]
[BsonElement(nameof(Timestamp))]
public Instant Timestamp { get; set; }
[BsonElement]
[BsonRequired]
[BsonElement(nameof(Properties))]
public Dictionary<string, string> Properties { get; set; }
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
{
[BsonId]
[BsonElement]
[BsonRepresentation(BsonType.String)]
[BsonElement("_id")]
public string Id { get; set; }
[BsonElement]
[BsonRequired]
[BsonElement(nameof(IsLocked))]
public bool IsLocked { get; set; }
[BsonElement]

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

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

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

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

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

@ -11,12 +11,10 @@ using Squidex.Infrastructure.MongoDb;
namespace Squidex.Infrastructure.States
{
[BsonIgnoreExtraElements]
public class MongoState<T> : IVersionedEntity<DomainId>
{
[BsonId]
[BsonElement]
[BsonRepresentation(BsonType.String)]
[BsonElement("_id")]
public DomainId DocumentId { get; set; }
[BsonRequired]
@ -25,7 +23,7 @@ namespace Squidex.Infrastructure.States
public T Document { get; set; }
[BsonRequired]
[BsonElement]
[BsonElement(nameof(Version))]
public long Version { get; set; }
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
{
[BsonId]
[BsonElement]
[BsonRepresentation(BsonType.String)]
[BsonElement("_id")]
public string Id { get; set; }
[BsonRequired]
[BsonElement]
[BsonElement(nameof(Date))]
[BsonDateTimeOptions(DateOnly = true)]
public DateTime Date { get; set; }
[BsonRequired]
[BsonElement]
[BsonElement(nameof(Key))]
public string Key { get; set; }
[BsonIgnoreIfNull]
[BsonElement]
[BsonElement(nameof(Category))]
public string Category { get; set; }
[BsonRequired]
[BsonElement]
[BsonElement(nameof(Counters))]
public Counters Counters { get; set; } = new Counters();
}
}

Loading…
Cancel
Save