From 0d12e2b406ff15a173435c8bdee860e7d8267e4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikola=20Vetni=C4=87?= <62119280+NikolaVetnic@users.noreply.github.com> Date: Fri, 10 Nov 2023 07:24:25 +0100 Subject: [PATCH] Messages: save blobs in the database instead of in the blob storage (#368) * feat: add PersistMessageBodyInDb migration * feat: update the way of determining whether the message body is already filled * feat: remove the builder.Ignore(a => a.Body) statement * feat: update condition on whether the message body should be filled from blob storage * chore: add required project and package references * test: retrieve message body from blob storage if unavailable in database * test: retrieve message body from blob storage if unavailable in database * feat: remove saving message bodies to blob storage * chore: fix the formatting issues causing the ci/cd test to fail * chore: add project reference needed to use proper TestDataGenerator * fix: await messageRepository.FindMessagesWithIds() to prevent blocking statements * feat: make the Body column nullable and without a default value * chore: extract FillBody logic into a separate method * chore: fix indentation * fix: add missing semicolon * chore: refactor test as per requests in the PR * feat: make the Body column nullable and without a default value in SQL server migration as well * chore: fix the formatting issues causing the ci/cd test to fail * feat: update messages in the database from blob storage on project start if blob storage configuration is present * chore: remove obsolete test * fix: instance BlobStorageOptions to make it possible to run the project when blob storage settings are missing * chore: fix the formatting issues that caused the ci/cd tests fail * chore: move CreateRandomDeviceId() to building blocks for easier access in all modules * chore: add comment to refactor this class so that all necessary methods are contained only in BuildingBlocks.UnitTestTools * chore: remove reference to Devices.Application.Tests * chore: refactor code to match the changes made after requests in the Relationships PR * chore: remove duplicates of methods present in UnitTestTools * chore: update method calls to use unit test tools * chore: fix formatting issues * chore: fix missing indentation * chore: change var name * chore: fix formatting issues --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- .../UnitTestTools/Data/TestDataGenerator.cs | 5 + ConsumerApi/MessagesDbContextSeeder.cs | 44 ++ ConsumerApi/Program.cs | 4 +- ConsumerApi/appsettings.override.json | 5 - .../TestDataGenerator.cs | 20 +- .../Commands/UpdateIdentity/HandlerTests.cs | 11 +- .../Queries/GetIdentity/HandlerTests.cs | 3 +- .../Queries/ListIdentities/HandlerTests.cs | 17 +- .../src/Messages.ConsumerApi/Configuration.cs | 3 +- .../Messages.ConsumerApi/MessagesModule.cs | 17 +- .../src/Messages.Domain/Entities/Message.cs | 2 +- ...6203258_PersistMessageBodyInDb.Designer.cs | 208 +++++++++ .../20231106203258_PersistMessageBodyInDb.cs | 31 ++ .../MessagesDbContextModelSnapshot.cs | 403 +++++++++--------- ...6203230_PersistMessageBodyInDb.Designer.cs | 208 +++++++++ .../20231106203230_PersistMessageBodyInDb.cs | 31 ++ .../ApplicationDbContextModelSnapshot.cs | 403 +++++++++--------- .../Postgres/AttachmentEntityType.cs | 192 ++++----- .../Postgres/MessageEntityType.cs | 208 ++++----- .../Postgres/MessagesDbContextModel.cs | 59 ++- .../Postgres/MessagesDbContextModelBuilder.cs | 70 +-- .../RecipientInformationEntityType.cs | 286 ++++++------- .../Postgres/RelationshipEntityType.cs | 180 ++++---- .../SqlServer/AttachmentEntityType.cs | 196 ++++----- .../SqlServer/MessageEntityType.cs | 219 +++++----- .../SqlServer/MessagesDbContextModel.cs | 59 ++- .../MessagesDbContextModelBuilder.cs | 68 +-- .../RecipientInformationEntityType.cs | 298 ++++++------- .../SqlServer/RelationshipEntityType.cs | 190 ++++----- .../MessageEntityTypeConfiguration.cs | 5 +- .../Database/Repository/MessagesRepository.cs | 25 +- .../IServiceCollectionExtensions.cs | 12 +- .../Messages.Application.Tests.csproj | 33 +- docker-compose/docker-compose.yml | 4 +- 34 files changed, 2019 insertions(+), 1500 deletions(-) create mode 100644 ConsumerApi/MessagesDbContextSeeder.cs create mode 100644 Modules/Messages/src/Messages.Infrastructure.Database.Postgres/Migrations/20231106203258_PersistMessageBodyInDb.Designer.cs create mode 100644 Modules/Messages/src/Messages.Infrastructure.Database.Postgres/Migrations/20231106203258_PersistMessageBodyInDb.cs create mode 100644 Modules/Messages/src/Messages.Infrastructure.Database.SqlServer/Migrations/20231106203230_PersistMessageBodyInDb.Designer.cs create mode 100644 Modules/Messages/src/Messages.Infrastructure.Database.SqlServer/Migrations/20231106203230_PersistMessageBodyInDb.cs diff --git a/BuildingBlocks/src/UnitTestTools/Data/TestDataGenerator.cs b/BuildingBlocks/src/UnitTestTools/Data/TestDataGenerator.cs index 82d3106b4c..338abb145d 100644 --- a/BuildingBlocks/src/UnitTestTools/Data/TestDataGenerator.cs +++ b/BuildingBlocks/src/UnitTestTools/Data/TestDataGenerator.cs @@ -17,6 +17,11 @@ public static IdentityAddress CreateRandomIdentityAddress() return IdentityAddress.Create(CreateRandomBytes(), "id1"); } + public static DeviceId CreateRandomDeviceId() + { + return DeviceId.New(); + } + public static byte[] CreateRandomBytes() { var random = new Random(); diff --git a/ConsumerApi/MessagesDbContextSeeder.cs b/ConsumerApi/MessagesDbContextSeeder.cs new file mode 100644 index 0000000000..e812989596 --- /dev/null +++ b/ConsumerApi/MessagesDbContextSeeder.cs @@ -0,0 +1,44 @@ +using Backbone.BuildingBlocks.API.Extensions; +using Backbone.BuildingBlocks.Application.Abstractions.Infrastructure.Persistence.BlobStorage; +using Backbone.Modules.Messages.Application.Infrastructure.Persistence; +using Backbone.Modules.Messages.Infrastructure.Persistence.Database; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Options; + +namespace Backbone.ConsumerApi; + +public class MessagesDbContextSeeder : IDbSeeder +{ + private readonly IBlobStorage? _blobStorage; + private readonly string? _blobRootFolder; + + public MessagesDbContextSeeder(IServiceProvider serviceProvider) + { + _blobStorage = serviceProvider.GetService(); + _blobRootFolder = serviceProvider.GetService>()?.Value.RootFolder; + } + + public async Task SeedAsync(MessagesDbContext context) + { + await FillBodyColumnsFromBlobStorage(context); + } + + private async Task FillBodyColumnsFromBlobStorage(MessagesDbContext context) + { + // _blobRootFolder is null when blob storage configuration is not provided, meaning the content of database entries should not be loaded from blob storage + if (_blobRootFolder == null) + return; + + // ReSharper disable once ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract + var messagesWithMissingBody = await context.Messages.Where(m => m.Body == null).ToListAsync(); + + foreach (var message in messagesWithMissingBody) + { + var blobMessageBody = await _blobStorage.FindAsync(_blobRootFolder, message.Id); + message.LoadBody(blobMessageBody); + context.Messages.Update(message); + } + + await context.SaveChangesAsync(); + } +} diff --git a/ConsumerApi/Program.cs b/ConsumerApi/Program.cs index d687f2b871..a107a38224 100644 --- a/ConsumerApi/Program.cs +++ b/ConsumerApi/Program.cs @@ -111,7 +111,8 @@ static WebApplication CreateApp(string[] args) app .SeedDbContext() - .SeedDbContext(); + .SeedDbContext() + .SeedDbContext(); foreach (var module in app.Services.GetRequiredService>()) { @@ -127,6 +128,7 @@ static void ConfigureServices(IServiceCollection services, IConfiguration config services.AddTransient(); services.AddTransient(); + services.AddTransient(); services .AddModule(configuration) diff --git a/ConsumerApi/appsettings.override.json b/ConsumerApi/appsettings.override.json index 238f797a9a..e4fd91fede 100644 --- a/ConsumerApi/appsettings.override.json +++ b/ConsumerApi/appsettings.override.json @@ -75,11 +75,6 @@ "Provider": "Postgres", "ConnectionString": "User ID=messages;Password=Passw0rd;Server=postgres;Port=5432;Database=enmeshed;" // postgres // "ConnectionString": "Server=ms-sql-server;Database=enmeshed;User Id=messages;Password=Passw0rd;TrustServerCertificate=True" // sqlserver - }, - "BlobStorage": { - "CloudProvider": "Azure", - "ConnectionInfo": "", - "ContainerName": "" } } }, diff --git a/Modules/Devices/test/Devices.Application.Tests/TestDataGenerator.cs b/Modules/Devices/test/Devices.Application.Tests/TestDataGenerator.cs index 0ef117d9a6..04cea47323 100644 --- a/Modules/Devices/test/Devices.Application.Tests/TestDataGenerator.cs +++ b/Modules/Devices/test/Devices.Application.Tests/TestDataGenerator.cs @@ -1,29 +1,11 @@ -using Backbone.DevelopmentKit.Identity.ValueObjects; using Backbone.Modules.Devices.Domain.Aggregates.Tier; using Backbone.Modules.Devices.Domain.Entities; +using static Backbone.UnitTestTools.Data.TestDataGenerator; namespace Backbone.Modules.Devices.Application.Tests; public static class TestDataGenerator { - public static IdentityAddress CreateRandomIdentityAddress() - { - return IdentityAddress.Create(CreateRandomBytes(), "id1"); - } - - public static DeviceId CreateRandomDeviceId() - { - return DeviceId.New(); - } - - public static byte[] CreateRandomBytes() - { - var random = new Random(); - var bytes = new byte[10]; - random.NextBytes(bytes); - return bytes; - } - public static TierId CreateRandomTierId() { return TierId.Generate(); diff --git a/Modules/Devices/test/Devices.Application.Tests/Tests/Identities/Commands/UpdateIdentity/HandlerTests.cs b/Modules/Devices/test/Devices.Application.Tests/Tests/Identities/Commands/UpdateIdentity/HandlerTests.cs index 38f3235c2c..4ad8a79f11 100644 --- a/Modules/Devices/test/Devices.Application.Tests/Tests/Identities/Commands/UpdateIdentity/HandlerTests.cs +++ b/Modules/Devices/test/Devices.Application.Tests/Tests/Identities/Commands/UpdateIdentity/HandlerTests.cs @@ -11,6 +11,7 @@ using FakeItEasy; using FluentAssertions; using Xunit; +using static Backbone.UnitTestTools.Data.TestDataGenerator; namespace Backbone.Modules.Devices.Application.Tests.Tests.Identities.Commands.UpdateIdentity; public class HandlerTests @@ -25,7 +26,7 @@ public async void Updates_the_identity_in_the_database() var oldTier = new Tier(TierName.Create("Old tier").Value); var newTier = new Tier(TierName.Create("New Tier").Value); - var identity = new Identity(TestDataGenerator.CreateRandomDeviceId(), TestDataGenerator.CreateRandomIdentityAddress(), new byte[] { 1, 1, 1, 1, 1 }, oldTier.Id, 1); + var identity = new Identity(CreateRandomDeviceId(), CreateRandomIdentityAddress(), new byte[] { 1, 1, 1, 1, 1 }, oldTier.Id, 1); A.CallTo(() => identitiesRepository.FindByAddress(identity.Address, A._, A._)).Returns(identity); A.CallTo(() => tiersRepository.FindByIds(A>._, A._)).Returns(new List() { oldTier, newTier }); @@ -54,7 +55,7 @@ public async void Publishes_TierOfIdentityChangedIntegrationEvent() var oldTier = new Tier(TierName.Create("Old tier").Value); var newTier = new Tier(TierName.Create("New Tier").Value); - var identity = new Identity(TestDataGenerator.CreateRandomDeviceId(), TestDataGenerator.CreateRandomIdentityAddress(), new byte[] { 1, 1, 1, 1, 1 }, oldTier.Id, 1); + var identity = new Identity(CreateRandomDeviceId(), CreateRandomIdentityAddress(), new byte[] { 1, 1, 1, 1, 1 }, oldTier.Id, 1); A.CallTo(() => identitiesRepository.FindByAddress(identity.Address, A._, A._)).Returns(identity); A.CallTo(() => tiersRepository.FindByIds(A>._, A._)).Returns(new List() { oldTier, newTier }); @@ -79,7 +80,7 @@ public void Fails_when_identity_does_not_exist() var oldTier = new Tier(TierName.Create("Tier name").Value); var newTier = new Tier(TierName.Create("Tier name").Value); - var identity = new Identity(TestDataGenerator.CreateRandomDeviceId(), TestDataGenerator.CreateRandomIdentityAddress(), new byte[] { 1, 1, 1, 1, 1 }, oldTier.Id, 1); + var identity = new Identity(CreateRandomDeviceId(), CreateRandomIdentityAddress(), new byte[] { 1, 1, 1, 1, 1 }, oldTier.Id, 1); A.CallTo(() => tiersRepository.FindByIds(A>._, A._)).Returns(new List() { oldTier, newTier }); A.CallTo(() => identitiesRepository.FindByAddress(A._, A._, A._)).Returns((Identity)null); @@ -106,7 +107,7 @@ public void Fails_when_tier_does_not_exist() var oldTier = new Tier(TierName.Create("Tier name").Value); var newTier = new Tier(TierName.Create("Tier name").Value); - var identity = new Identity(TestDataGenerator.CreateRandomDeviceId(), TestDataGenerator.CreateRandomIdentityAddress(), new byte[] { 1, 1, 1, 1, 1 }, oldTier.Id, 1); + var identity = new Identity(CreateRandomDeviceId(), CreateRandomIdentityAddress(), new byte[] { 1, 1, 1, 1, 1 }, oldTier.Id, 1); A.CallTo(() => identitiesRepository.FindByAddress(identity.Address, A._, A._)).Returns(identity); A.CallTo(() => tiersRepository.FindByIds(A>._, A._)).Returns(new List() { oldTier }); @@ -133,7 +134,7 @@ public void Does_nothing_when_tiers_are_the_same() var oldAndNewTier = new Tier(TierName.Create("Tier name").Value); - var identity = new Identity(TestDataGenerator.CreateRandomDeviceId(), TestDataGenerator.CreateRandomIdentityAddress(), new byte[] { 1, 1, 1, 1, 1 }, oldAndNewTier.Id, 1); + var identity = new Identity(CreateRandomDeviceId(), CreateRandomIdentityAddress(), new byte[] { 1, 1, 1, 1, 1 }, oldAndNewTier.Id, 1); A.CallTo(() => identitiesRepository.FindByAddress(identity.Address, A._, A._)).Returns(identity); A.CallTo(() => tiersRepository.FindByIds(A>._, A._)).Returns(new List { oldAndNewTier }); diff --git a/Modules/Devices/test/Devices.Application.Tests/Tests/Identities/Queries/GetIdentity/HandlerTests.cs b/Modules/Devices/test/Devices.Application.Tests/Tests/Identities/Queries/GetIdentity/HandlerTests.cs index 57bc59ceb0..628a4dea82 100644 --- a/Modules/Devices/test/Devices.Application.Tests/Tests/Identities/Queries/GetIdentity/HandlerTests.cs +++ b/Modules/Devices/test/Devices.Application.Tests/Tests/Identities/Queries/GetIdentity/HandlerTests.cs @@ -7,6 +7,7 @@ using FakeItEasy; using FluentAssertions; using Xunit; +using static Backbone.UnitTestTools.Data.TestDataGenerator; namespace Backbone.Modules.Devices.Application.Tests.Tests.Identities.Queries.GetIdentity; public class HandlerTests @@ -15,7 +16,7 @@ public class HandlerTests public async void Gets_identity_by_address() { // Arrange - var identity = new Identity(TestDataGenerator.CreateRandomDeviceId(), TestDataGenerator.CreateRandomIdentityAddress(), new byte[] { 1, 1, 1, 1, 1 }, TestDataGenerator.CreateRandomTierId(), 1); + var identity = new Identity(CreateRandomDeviceId(), CreateRandomIdentityAddress(), new byte[] { 1, 1, 1, 1, 1 }, TestDataGenerator.CreateRandomTierId(), 1); var handler = CreateHandler(new FindByAddressStubRepository(identity)); diff --git a/Modules/Devices/test/Devices.Application.Tests/Tests/Identities/Queries/ListIdentities/HandlerTests.cs b/Modules/Devices/test/Devices.Application.Tests/Tests/Identities/Queries/ListIdentities/HandlerTests.cs index 1ee513c0f7..f826f3f495 100644 --- a/Modules/Devices/test/Devices.Application.Tests/Tests/Identities/Queries/ListIdentities/HandlerTests.cs +++ b/Modules/Devices/test/Devices.Application.Tests/Tests/Identities/Queries/ListIdentities/HandlerTests.cs @@ -5,6 +5,7 @@ using FluentAssertions; using FluentAssertions.Execution; using Xunit; +using static Backbone.UnitTestTools.Data.TestDataGenerator; namespace Backbone.Modules.Devices.Application.Tests.Tests.Identities.Queries.ListIdentities; @@ -37,14 +38,14 @@ public async void Returns_a_list_of_all_existing_identities() var request = new PaginationFilter(); List identitiesList = new() { - new(TestDataGenerator.CreateRandomDeviceId(), - TestDataGenerator.CreateRandomIdentityAddress(), - TestDataGenerator.CreateRandomBytes(), + new(CreateRandomDeviceId(), + CreateRandomIdentityAddress(), + CreateRandomBytes(), TestDataGenerator.CreateRandomTierId(), 1), - new(TestDataGenerator.CreateRandomDeviceId(), - TestDataGenerator.CreateRandomIdentityAddress(), - TestDataGenerator.CreateRandomBytes(), + new(CreateRandomDeviceId(), + CreateRandomIdentityAddress(), + CreateRandomBytes(), TestDataGenerator.CreateRandomTierId(), 1) }; @@ -63,8 +64,8 @@ public async void Returned_identities_have_all_properties_filled_as_expected() { // Arrange var request = new PaginationFilter(); - var expectedClientId = TestDataGenerator.CreateRandomDeviceId(); - var expectedAddress = TestDataGenerator.CreateRandomIdentityAddress(); + var expectedClientId = CreateRandomDeviceId(); + var expectedAddress = CreateRandomIdentityAddress(); var expectedTierId = TestDataGenerator.CreateRandomTierId(); List identitiesList = new() { diff --git a/Modules/Messages/src/Messages.ConsumerApi/Configuration.cs b/Modules/Messages/src/Messages.ConsumerApi/Configuration.cs index 20ac9a3d4a..15279ace55 100644 --- a/Modules/Messages/src/Messages.ConsumerApi/Configuration.cs +++ b/Modules/Messages/src/Messages.ConsumerApi/Configuration.cs @@ -16,8 +16,7 @@ public class InfrastructureConfiguration [Required] public SqlDatabaseConfiguration SqlDatabase { get; set; } = new(); - [Required] - public BlobStorageConfiguration BlobStorage { get; set; } = new(); + public BlobStorageConfiguration? BlobStorage { get; set; } public class BlobStorageConfiguration { diff --git a/Modules/Messages/src/Messages.ConsumerApi/MessagesModule.cs b/Modules/Messages/src/Messages.ConsumerApi/MessagesModule.cs index 1ab9de3803..a0a506405b 100644 --- a/Modules/Messages/src/Messages.ConsumerApi/MessagesModule.cs +++ b/Modules/Messages/src/Messages.ConsumerApi/MessagesModule.cs @@ -27,12 +27,17 @@ public override void ConfigureServices(IServiceCollection services, IConfigurati options.DbOptions.Provider = parsedConfiguration.Infrastructure.SqlDatabase.Provider; options.DbOptions.DbConnectionString = parsedConfiguration.Infrastructure.SqlDatabase.ConnectionString; - options.BlobStorageOptions.CloudProvider = parsedConfiguration.Infrastructure.BlobStorage.CloudProvider; - options.BlobStorageOptions.ConnectionInfo = parsedConfiguration.Infrastructure.BlobStorage.ConnectionInfo; - options.BlobStorageOptions.Container = - parsedConfiguration.Infrastructure.BlobStorage.ContainerName.IsNullOrEmpty() - ? "messages" - : parsedConfiguration.Infrastructure.BlobStorage.ContainerName; + if (parsedConfiguration.Infrastructure.BlobStorage != null) + { + options.BlobStorageOptions = new() + { + CloudProvider = parsedConfiguration.Infrastructure.BlobStorage.CloudProvider, + ConnectionInfo = parsedConfiguration.Infrastructure.BlobStorage.ConnectionInfo, + Container = parsedConfiguration.Infrastructure.BlobStorage.ContainerName.IsNullOrEmpty() + ? "messages" + : parsedConfiguration.Infrastructure.BlobStorage.ContainerName + }; + } }); services.AddApplication(); diff --git a/Modules/Messages/src/Messages.Domain/Entities/Message.cs b/Modules/Messages/src/Messages.Domain/Entities/Message.cs index 66e85add04..2750183dd8 100644 --- a/Modules/Messages/src/Messages.Domain/Entities/Message.cs +++ b/Modules/Messages/src/Messages.Domain/Entities/Message.cs @@ -37,7 +37,7 @@ public Message(IdentityAddress createdBy, DeviceId createdByDevice, DateTime? do public void LoadBody(byte[] bytes) { - if (Body != null) + if (Body is { Length: > 0 }) { throw new InvalidOperationException($"The Body of the message {Id} is already filled. It is not possible to change it."); } diff --git a/Modules/Messages/src/Messages.Infrastructure.Database.Postgres/Migrations/20231106203258_PersistMessageBodyInDb.Designer.cs b/Modules/Messages/src/Messages.Infrastructure.Database.Postgres/Migrations/20231106203258_PersistMessageBodyInDb.Designer.cs new file mode 100644 index 0000000000..23cdc29681 --- /dev/null +++ b/Modules/Messages/src/Messages.Infrastructure.Database.Postgres/Migrations/20231106203258_PersistMessageBodyInDb.Designer.cs @@ -0,0 +1,208 @@ +// +using System; +using Backbone.Modules.Messages.Infrastructure.Persistence.Database; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace Backbone.Modules.Messages.Infrastructure.Database.Postgres.Migrations +{ + [DbContext(typeof(MessagesDbContext))] + [Migration("20231106203258_PersistMessageBodyInDb")] + partial class PersistMessageBodyInDb + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.13") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("Backbone.Modules.Messages.Domain.Entities.Attachment", b => + { + b.Property("Id") + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character(20)") + .IsFixedLength(); + + b.Property("MessageId") + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character(20)") + .IsFixedLength(); + + b.HasKey("Id", "MessageId"); + + b.HasIndex("MessageId"); + + b.ToTable("Attachments", (string)null); + }); + + modelBuilder.Entity("Backbone.Modules.Messages.Domain.Entities.Message", b => + { + b.Property("Id") + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character(20)") + .IsFixedLength(); + + b.Property("Body") + .IsRequired() + .HasColumnType("bytea"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("CreatedBy") + .IsRequired() + .HasMaxLength(36) + .IsUnicode(false) + .HasColumnType("character(36)") + .IsFixedLength(); + + b.Property("CreatedByDevice") + .IsRequired() + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character(20)") + .IsFixedLength(); + + b.Property("DoNotSendBefore") + .HasColumnType("timestamp with time zone"); + + b.HasKey("Id"); + + b.HasIndex("CreatedAt"); + + b.HasIndex("CreatedBy"); + + b.HasIndex("DoNotSendBefore"); + + b.ToTable("Messages"); + }); + + modelBuilder.Entity("Backbone.Modules.Messages.Domain.Entities.RecipientInformation", b => + { + b.Property("Address") + .HasMaxLength(36) + .IsUnicode(false) + .HasColumnType("character(36)") + .IsFixedLength(); + + b.Property("MessageId") + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character(20)") + .IsFixedLength(); + + b.Property("EncryptedKey") + .IsRequired() + .HasColumnType("bytea"); + + b.Property("ReceivedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("ReceivedByDevice") + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character(20)") + .IsFixedLength(); + + b.Property("RelationshipId") + .IsRequired() + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character(20)") + .IsFixedLength(); + + b.HasKey("Address", "MessageId"); + + b.HasIndex("MessageId"); + + b.HasIndex("ReceivedAt"); + + b.HasIndex("RelationshipId"); + + b.ToTable("RecipientInformation"); + }); + + modelBuilder.Entity("Backbone.Modules.Messages.Domain.Entities.Relationship", b => + { + b.Property("Id") + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character(20)") + .IsFixedLength(); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("From") + .IsRequired() + .HasMaxLength(36) + .IsUnicode(false) + .HasColumnType("character(36)") + .IsFixedLength(); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("To") + .IsRequired() + .HasMaxLength(36) + .IsUnicode(false) + .HasColumnType("character(36)") + .IsFixedLength(); + + b.HasKey("Id"); + + b.ToTable("Relationships", "Relationships", t => + { + t.ExcludeFromMigrations(); + }); + }); + + modelBuilder.Entity("Backbone.Modules.Messages.Domain.Entities.Attachment", b => + { + b.HasOne("Backbone.Modules.Messages.Domain.Entities.Message", "Message") + .WithMany("Attachments") + .HasForeignKey("MessageId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Message"); + }); + + modelBuilder.Entity("Backbone.Modules.Messages.Domain.Entities.RecipientInformation", b => + { + b.HasOne("Backbone.Modules.Messages.Domain.Entities.Message", null) + .WithMany("Recipients") + .HasForeignKey("MessageId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Backbone.Modules.Messages.Domain.Entities.Relationship", null) + .WithMany() + .HasForeignKey("RelationshipId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Backbone.Modules.Messages.Domain.Entities.Message", b => + { + b.Navigation("Attachments"); + + b.Navigation("Recipients"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Modules/Messages/src/Messages.Infrastructure.Database.Postgres/Migrations/20231106203258_PersistMessageBodyInDb.cs b/Modules/Messages/src/Messages.Infrastructure.Database.Postgres/Migrations/20231106203258_PersistMessageBodyInDb.cs new file mode 100644 index 0000000000..8d7ebd7852 --- /dev/null +++ b/Modules/Messages/src/Messages.Infrastructure.Database.Postgres/Migrations/20231106203258_PersistMessageBodyInDb.cs @@ -0,0 +1,31 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Backbone.Modules.Messages.Infrastructure.Database.Postgres.Migrations +{ + /// + public partial class PersistMessageBodyInDb : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "Body", + table: "Messages", + type: "bytea", + nullable: true); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "Body", + table: "Messages"); + + migrationBuilder.EnsureSchema( + name: "Relationships"); + } + } +} diff --git a/Modules/Messages/src/Messages.Infrastructure.Database.Postgres/Migrations/MessagesDbContextModelSnapshot.cs b/Modules/Messages/src/Messages.Infrastructure.Database.Postgres/Migrations/MessagesDbContextModelSnapshot.cs index e0300f7dca..393c8d52b4 100644 --- a/Modules/Messages/src/Messages.Infrastructure.Database.Postgres/Migrations/MessagesDbContextModelSnapshot.cs +++ b/Modules/Messages/src/Messages.Infrastructure.Database.Postgres/Migrations/MessagesDbContextModelSnapshot.cs @@ -1,198 +1,205 @@ -// -using System; -using Backbone.Modules.Messages.Infrastructure.Persistence.Database; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; - -#nullable disable - -namespace Messages.Infrastructure.Database.Postgres.Migrations -{ - [DbContext(typeof(MessagesDbContext))] - partial class MessagesDbContextModelSnapshot : ModelSnapshot - { - protected override void BuildModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "7.0.2") - .HasAnnotation("Relational:MaxIdentifierLength", 63); - - NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); - - modelBuilder.Entity("Backbone.Modules.Messages.Domain.Entities.Attachment", b => - { - b.Property("Id") - .HasMaxLength(20) - .IsUnicode(false) - .HasColumnType("character(20)") - .IsFixedLength(); - - b.Property("MessageId") - .HasMaxLength(20) - .IsUnicode(false) - .HasColumnType("character(20)") - .IsFixedLength(); - - b.HasKey("Id", "MessageId"); - - b.HasIndex("MessageId"); - - b.ToTable("Attachments", (string)null); - }); - - modelBuilder.Entity("Backbone.Modules.Messages.Domain.Entities.Message", b => - { - b.Property("Id") - .HasMaxLength(20) - .IsUnicode(false) - .HasColumnType("character(20)") - .IsFixedLength(); - - b.Property("CreatedAt") - .HasColumnType("timestamp with time zone"); - - b.Property("CreatedBy") - .IsRequired() - .HasMaxLength(36) - .IsUnicode(false) - .HasColumnType("character(36)") - .IsFixedLength(); - - b.Property("CreatedByDevice") - .IsRequired() - .HasMaxLength(20) - .IsUnicode(false) - .HasColumnType("character(20)") - .IsFixedLength(); - - b.Property("DoNotSendBefore") - .HasColumnType("timestamp with time zone"); - - b.HasKey("Id"); - - b.HasIndex("CreatedAt"); - - b.HasIndex("CreatedBy"); - - b.HasIndex("DoNotSendBefore"); - - b.ToTable("Messages"); - }); - - modelBuilder.Entity("Backbone.Modules.Messages.Domain.Entities.RecipientInformation", b => - { - b.Property("Address") - .HasMaxLength(36) - .IsUnicode(false) - .HasColumnType("character(36)") - .IsFixedLength(); - - b.Property("MessageId") - .HasMaxLength(20) - .IsUnicode(false) - .HasColumnType("character(20)") - .IsFixedLength(); - - b.Property("EncryptedKey") - .IsRequired() - .HasColumnType("bytea"); - - b.Property("ReceivedAt") - .HasColumnType("timestamp with time zone"); - - b.Property("ReceivedByDevice") - .HasMaxLength(20) - .IsUnicode(false) - .HasColumnType("character(20)") - .IsFixedLength(); - - b.Property("RelationshipId") - .IsRequired() - .HasMaxLength(20) - .IsUnicode(false) - .HasColumnType("character(20)") - .IsFixedLength(); - - b.HasKey("Address", "MessageId"); - - b.HasIndex("MessageId"); - - b.HasIndex("ReceivedAt"); - - b.HasIndex("RelationshipId"); - - b.ToTable("RecipientInformation"); - }); - - modelBuilder.Entity("Backbone.Modules.Messages.Domain.Entities.Relationship", b => - { - b.Property("Id") - .HasMaxLength(20) - .IsUnicode(false) - .HasColumnType("character(20)") - .IsFixedLength(); - - b.Property("CreatedAt") - .HasColumnType("timestamp with time zone"); - - b.Property("From") - .IsRequired() - .HasMaxLength(36) - .IsUnicode(false) - .HasColumnType("character(36)") - .IsFixedLength(); - - b.Property("Status") - .HasColumnType("integer"); - - b.Property("To") - .IsRequired() - .HasMaxLength(36) - .IsUnicode(false) - .HasColumnType("character(36)") - .IsFixedLength(); - - b.HasKey("Id"); - - b.ToTable("Relationships", "Relationships"); - }); - - modelBuilder.Entity("Backbone.Modules.Messages.Domain.Entities.Attachment", b => - { - b.HasOne("Backbone.Modules.Messages.Domain.Entities.Message", "Message") - .WithMany("Attachments") - .HasForeignKey("MessageId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Message"); - }); - - modelBuilder.Entity("Backbone.Modules.Messages.Domain.Entities.RecipientInformation", b => - { - b.HasOne("Backbone.Modules.Messages.Domain.Entities.Message", null) - .WithMany("Recipients") - .HasForeignKey("MessageId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("Backbone.Modules.Messages.Domain.Entities.Relationship", null) - .WithMany() - .HasForeignKey("RelationshipId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Backbone.Modules.Messages.Domain.Entities.Message", b => - { - b.Navigation("Attachments"); - - b.Navigation("Recipients"); - }); -#pragma warning restore 612, 618 - } - } -} +// +using System; +using Backbone.Modules.Messages.Infrastructure.Persistence.Database; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace Messages.Infrastructure.Database.Postgres.Migrations +{ + [DbContext(typeof(MessagesDbContext))] + partial class MessagesDbContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.13") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("Backbone.Modules.Messages.Domain.Entities.Attachment", b => + { + b.Property("Id") + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character(20)") + .IsFixedLength(); + + b.Property("MessageId") + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character(20)") + .IsFixedLength(); + + b.HasKey("Id", "MessageId"); + + b.HasIndex("MessageId"); + + b.ToTable("Attachments", (string)null); + }); + + modelBuilder.Entity("Backbone.Modules.Messages.Domain.Entities.Message", b => + { + b.Property("Id") + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character(20)") + .IsFixedLength(); + + b.Property("Body") + .IsRequired() + .HasColumnType("bytea"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("CreatedBy") + .IsRequired() + .HasMaxLength(36) + .IsUnicode(false) + .HasColumnType("character(36)") + .IsFixedLength(); + + b.Property("CreatedByDevice") + .IsRequired() + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character(20)") + .IsFixedLength(); + + b.Property("DoNotSendBefore") + .HasColumnType("timestamp with time zone"); + + b.HasKey("Id"); + + b.HasIndex("CreatedAt"); + + b.HasIndex("CreatedBy"); + + b.HasIndex("DoNotSendBefore"); + + b.ToTable("Messages"); + }); + + modelBuilder.Entity("Backbone.Modules.Messages.Domain.Entities.RecipientInformation", b => + { + b.Property("Address") + .HasMaxLength(36) + .IsUnicode(false) + .HasColumnType("character(36)") + .IsFixedLength(); + + b.Property("MessageId") + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character(20)") + .IsFixedLength(); + + b.Property("EncryptedKey") + .IsRequired() + .HasColumnType("bytea"); + + b.Property("ReceivedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("ReceivedByDevice") + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character(20)") + .IsFixedLength(); + + b.Property("RelationshipId") + .IsRequired() + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character(20)") + .IsFixedLength(); + + b.HasKey("Address", "MessageId"); + + b.HasIndex("MessageId"); + + b.HasIndex("ReceivedAt"); + + b.HasIndex("RelationshipId"); + + b.ToTable("RecipientInformation"); + }); + + modelBuilder.Entity("Backbone.Modules.Messages.Domain.Entities.Relationship", b => + { + b.Property("Id") + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character(20)") + .IsFixedLength(); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("From") + .IsRequired() + .HasMaxLength(36) + .IsUnicode(false) + .HasColumnType("character(36)") + .IsFixedLength(); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("To") + .IsRequired() + .HasMaxLength(36) + .IsUnicode(false) + .HasColumnType("character(36)") + .IsFixedLength(); + + b.HasKey("Id"); + + b.ToTable("Relationships", "Relationships", t => + { + t.ExcludeFromMigrations(); + }); + }); + + modelBuilder.Entity("Backbone.Modules.Messages.Domain.Entities.Attachment", b => + { + b.HasOne("Backbone.Modules.Messages.Domain.Entities.Message", "Message") + .WithMany("Attachments") + .HasForeignKey("MessageId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Message"); + }); + + modelBuilder.Entity("Backbone.Modules.Messages.Domain.Entities.RecipientInformation", b => + { + b.HasOne("Backbone.Modules.Messages.Domain.Entities.Message", null) + .WithMany("Recipients") + .HasForeignKey("MessageId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Backbone.Modules.Messages.Domain.Entities.Relationship", null) + .WithMany() + .HasForeignKey("RelationshipId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Backbone.Modules.Messages.Domain.Entities.Message", b => + { + b.Navigation("Attachments"); + + b.Navigation("Recipients"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Modules/Messages/src/Messages.Infrastructure.Database.SqlServer/Migrations/20231106203230_PersistMessageBodyInDb.Designer.cs b/Modules/Messages/src/Messages.Infrastructure.Database.SqlServer/Migrations/20231106203230_PersistMessageBodyInDb.Designer.cs new file mode 100644 index 0000000000..68fc4dd6a7 --- /dev/null +++ b/Modules/Messages/src/Messages.Infrastructure.Database.SqlServer/Migrations/20231106203230_PersistMessageBodyInDb.Designer.cs @@ -0,0 +1,208 @@ +// +using System; +using Backbone.Modules.Messages.Infrastructure.Persistence.Database; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace Backbone.Modules.Messages.Infrastructure.Database.SqlServer.Migrations +{ + [DbContext(typeof(MessagesDbContext))] + [Migration("20231106203230_PersistMessageBodyInDb")] + partial class PersistMessageBodyInDb + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.13") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("Backbone.Modules.Messages.Domain.Entities.Attachment", b => + { + b.Property("Id") + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("char(20)") + .IsFixedLength(); + + b.Property("MessageId") + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("char(20)") + .IsFixedLength(); + + b.HasKey("Id", "MessageId"); + + b.HasIndex("MessageId"); + + b.ToTable("Attachments", (string)null); + }); + + modelBuilder.Entity("Backbone.Modules.Messages.Domain.Entities.Message", b => + { + b.Property("Id") + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("char(20)") + .IsFixedLength(); + + b.Property("Body") + .IsRequired() + .HasColumnType("varbinary(max)"); + + b.Property("CreatedAt") + .HasColumnType("datetime2"); + + b.Property("CreatedBy") + .IsRequired() + .HasMaxLength(36) + .IsUnicode(false) + .HasColumnType("char(36)") + .IsFixedLength(); + + b.Property("CreatedByDevice") + .IsRequired() + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("char(20)") + .IsFixedLength(); + + b.Property("DoNotSendBefore") + .HasColumnType("datetime2"); + + b.HasKey("Id"); + + b.HasIndex("CreatedAt"); + + b.HasIndex("CreatedBy"); + + b.HasIndex("DoNotSendBefore"); + + b.ToTable("Messages"); + }); + + modelBuilder.Entity("Backbone.Modules.Messages.Domain.Entities.RecipientInformation", b => + { + b.Property("Address") + .HasMaxLength(36) + .IsUnicode(false) + .HasColumnType("char(36)") + .IsFixedLength(); + + b.Property("MessageId") + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("char(20)") + .IsFixedLength(); + + b.Property("EncryptedKey") + .IsRequired() + .HasColumnType("varbinary(max)"); + + b.Property("ReceivedAt") + .HasColumnType("datetime2"); + + b.Property("ReceivedByDevice") + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("char(20)") + .IsFixedLength(); + + b.Property("RelationshipId") + .IsRequired() + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("char(20)") + .IsFixedLength(); + + b.HasKey("Address", "MessageId"); + + b.HasIndex("MessageId"); + + b.HasIndex("ReceivedAt"); + + b.HasIndex("RelationshipId"); + + b.ToTable("RecipientInformation"); + }); + + modelBuilder.Entity("Backbone.Modules.Messages.Domain.Entities.Relationship", b => + { + b.Property("Id") + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("char(20)") + .IsFixedLength(); + + b.Property("CreatedAt") + .HasColumnType("datetime2"); + + b.Property("From") + .IsRequired() + .HasMaxLength(36) + .IsUnicode(false) + .HasColumnType("char(36)") + .IsFixedLength(); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("To") + .IsRequired() + .HasMaxLength(36) + .IsUnicode(false) + .HasColumnType("char(36)") + .IsFixedLength(); + + b.HasKey("Id"); + + b.ToTable("Relationships", "Relationships", t => + { + t.ExcludeFromMigrations(); + }); + }); + + modelBuilder.Entity("Backbone.Modules.Messages.Domain.Entities.Attachment", b => + { + b.HasOne("Backbone.Modules.Messages.Domain.Entities.Message", "Message") + .WithMany("Attachments") + .HasForeignKey("MessageId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Message"); + }); + + modelBuilder.Entity("Backbone.Modules.Messages.Domain.Entities.RecipientInformation", b => + { + b.HasOne("Backbone.Modules.Messages.Domain.Entities.Message", null) + .WithMany("Recipients") + .HasForeignKey("MessageId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Backbone.Modules.Messages.Domain.Entities.Relationship", null) + .WithMany() + .HasForeignKey("RelationshipId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Backbone.Modules.Messages.Domain.Entities.Message", b => + { + b.Navigation("Attachments"); + + b.Navigation("Recipients"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Modules/Messages/src/Messages.Infrastructure.Database.SqlServer/Migrations/20231106203230_PersistMessageBodyInDb.cs b/Modules/Messages/src/Messages.Infrastructure.Database.SqlServer/Migrations/20231106203230_PersistMessageBodyInDb.cs new file mode 100644 index 0000000000..792d2b5775 --- /dev/null +++ b/Modules/Messages/src/Messages.Infrastructure.Database.SqlServer/Migrations/20231106203230_PersistMessageBodyInDb.cs @@ -0,0 +1,31 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Backbone.Modules.Messages.Infrastructure.Database.SqlServer.Migrations +{ + /// + public partial class PersistMessageBodyInDb : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "Body", + table: "Messages", + type: "varbinary(max)", + nullable: true); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "Body", + table: "Messages"); + + migrationBuilder.EnsureSchema( + name: "Relationships"); + } + } +} diff --git a/Modules/Messages/src/Messages.Infrastructure.Database.SqlServer/Migrations/ApplicationDbContextModelSnapshot.cs b/Modules/Messages/src/Messages.Infrastructure.Database.SqlServer/Migrations/ApplicationDbContextModelSnapshot.cs index f3d4b768db..21d1af7a2c 100644 --- a/Modules/Messages/src/Messages.Infrastructure.Database.SqlServer/Migrations/ApplicationDbContextModelSnapshot.cs +++ b/Modules/Messages/src/Messages.Infrastructure.Database.SqlServer/Migrations/ApplicationDbContextModelSnapshot.cs @@ -1,198 +1,205 @@ -// -using System; -using Backbone.Modules.Messages.Infrastructure.Persistence.Database; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -#nullable disable - -namespace Backbone.Modules.Messages.Infrastructure.Database.SqlServer.Migrations -{ - [DbContext(typeof(MessagesDbContext))] - partial class ApplicationDbContextModelSnapshot : ModelSnapshot - { - protected override void BuildModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "6.0.9") - .HasAnnotation("Relational:MaxIdentifierLength", 128); - - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1); - - modelBuilder.Entity("Messages.Domain.Entities.Attachment", b => - { - b.Property("Id") - .HasMaxLength(20) - .IsUnicode(false) - .HasColumnType("char(20)") - .IsFixedLength(); - - b.Property("MessageId") - .HasMaxLength(20) - .IsUnicode(false) - .HasColumnType("char(20)") - .IsFixedLength(); - - b.HasKey("Id", "MessageId"); - - b.HasIndex("MessageId"); - - b.ToTable("Attachments", (string)null); - }); - - modelBuilder.Entity("Messages.Domain.Entities.Message", b => - { - b.Property("Id") - .HasMaxLength(20) - .IsUnicode(false) - .HasColumnType("char(20)") - .IsFixedLength(); - - b.Property("CreatedAt") - .HasColumnType("datetime2"); - - b.Property("CreatedBy") - .IsRequired() - .HasMaxLength(36) - .IsUnicode(false) - .HasColumnType("char(36)") - .IsFixedLength(); - - b.Property("CreatedByDevice") - .IsRequired() - .HasMaxLength(20) - .IsUnicode(false) - .HasColumnType("char(20)") - .IsFixedLength(); - - b.Property("DoNotSendBefore") - .HasColumnType("datetime2"); - - b.HasKey("Id"); - - b.HasIndex("CreatedAt"); - - b.HasIndex("CreatedBy"); - - b.HasIndex("DoNotSendBefore"); - - b.ToTable("Messages"); - }); - - modelBuilder.Entity("Messages.Domain.Entities.RecipientInformation", b => - { - b.Property("Address") - .HasMaxLength(36) - .IsUnicode(false) - .HasColumnType("char(36)") - .IsFixedLength(); - - b.Property("MessageId") - .HasMaxLength(20) - .IsUnicode(false) - .HasColumnType("char(20)") - .IsFixedLength(); - - b.Property("EncryptedKey") - .IsRequired() - .HasColumnType("varbinary(max)"); - - b.Property("ReceivedAt") - .HasColumnType("datetime2"); - - b.Property("ReceivedByDevice") - .HasMaxLength(20) - .IsUnicode(false) - .HasColumnType("char(20)") - .IsFixedLength(); - - b.Property("RelationshipId") - .IsRequired() - .HasMaxLength(20) - .IsUnicode(false) - .HasColumnType("char(20)") - .IsFixedLength(); - - b.HasKey("Address", "MessageId"); - - b.HasIndex("MessageId"); - - b.HasIndex("ReceivedAt"); - - b.HasIndex("RelationshipId"); - - b.ToTable("RecipientInformation"); - }); - - modelBuilder.Entity("Messages.Domain.Entities.Relationship", b => - { - b.Property("Id") - .HasMaxLength(20) - .IsUnicode(false) - .HasColumnType("char(20)") - .IsFixedLength(); - - b.Property("CreatedAt") - .HasColumnType("datetime2"); - - b.Property("From") - .IsRequired() - .HasMaxLength(36) - .IsUnicode(false) - .HasColumnType("char(36)") - .IsFixedLength(); - - b.Property("Status") - .HasColumnType("int"); - - b.Property("To") - .IsRequired() - .HasMaxLength(36) - .IsUnicode(false) - .HasColumnType("char(36)") - .IsFixedLength(); - - b.HasKey("Id"); - - b.ToTable("Relationships", "Relationships"); - }); - - modelBuilder.Entity("Messages.Domain.Entities.Attachment", b => - { - b.HasOne("Messages.Domain.Entities.Message", "Message") - .WithMany("Attachments") - .HasForeignKey("MessageId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Message"); - }); - - modelBuilder.Entity("Messages.Domain.Entities.RecipientInformation", b => - { - b.HasOne("Messages.Domain.Entities.Message", null) - .WithMany("Recipients") - .HasForeignKey("MessageId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("Messages.Domain.Entities.Relationship", null) - .WithMany() - .HasForeignKey("RelationshipId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Messages.Domain.Entities.Message", b => - { - b.Navigation("Attachments"); - - b.Navigation("Recipients"); - }); -#pragma warning restore 612, 618 - } - } -} +// +using System; +using Backbone.Modules.Messages.Infrastructure.Persistence.Database; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace Backbone.Modules.Messages.Infrastructure.Database.SqlServer.Migrations +{ + [DbContext(typeof(MessagesDbContext))] + partial class ApplicationDbContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.13") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("Backbone.Modules.Messages.Domain.Entities.Attachment", b => + { + b.Property("Id") + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("char(20)") + .IsFixedLength(); + + b.Property("MessageId") + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("char(20)") + .IsFixedLength(); + + b.HasKey("Id", "MessageId"); + + b.HasIndex("MessageId"); + + b.ToTable("Attachments", (string)null); + }); + + modelBuilder.Entity("Backbone.Modules.Messages.Domain.Entities.Message", b => + { + b.Property("Id") + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("char(20)") + .IsFixedLength(); + + b.Property("Body") + .IsRequired() + .HasColumnType("varbinary(max)"); + + b.Property("CreatedAt") + .HasColumnType("datetime2"); + + b.Property("CreatedBy") + .IsRequired() + .HasMaxLength(36) + .IsUnicode(false) + .HasColumnType("char(36)") + .IsFixedLength(); + + b.Property("CreatedByDevice") + .IsRequired() + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("char(20)") + .IsFixedLength(); + + b.Property("DoNotSendBefore") + .HasColumnType("datetime2"); + + b.HasKey("Id"); + + b.HasIndex("CreatedAt"); + + b.HasIndex("CreatedBy"); + + b.HasIndex("DoNotSendBefore"); + + b.ToTable("Messages"); + }); + + modelBuilder.Entity("Backbone.Modules.Messages.Domain.Entities.RecipientInformation", b => + { + b.Property("Address") + .HasMaxLength(36) + .IsUnicode(false) + .HasColumnType("char(36)") + .IsFixedLength(); + + b.Property("MessageId") + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("char(20)") + .IsFixedLength(); + + b.Property("EncryptedKey") + .IsRequired() + .HasColumnType("varbinary(max)"); + + b.Property("ReceivedAt") + .HasColumnType("datetime2"); + + b.Property("ReceivedByDevice") + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("char(20)") + .IsFixedLength(); + + b.Property("RelationshipId") + .IsRequired() + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("char(20)") + .IsFixedLength(); + + b.HasKey("Address", "MessageId"); + + b.HasIndex("MessageId"); + + b.HasIndex("ReceivedAt"); + + b.HasIndex("RelationshipId"); + + b.ToTable("RecipientInformation"); + }); + + modelBuilder.Entity("Backbone.Modules.Messages.Domain.Entities.Relationship", b => + { + b.Property("Id") + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("char(20)") + .IsFixedLength(); + + b.Property("CreatedAt") + .HasColumnType("datetime2"); + + b.Property("From") + .IsRequired() + .HasMaxLength(36) + .IsUnicode(false) + .HasColumnType("char(36)") + .IsFixedLength(); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("To") + .IsRequired() + .HasMaxLength(36) + .IsUnicode(false) + .HasColumnType("char(36)") + .IsFixedLength(); + + b.HasKey("Id"); + + b.ToTable("Relationships", "Relationships", t => + { + t.ExcludeFromMigrations(); + }); + }); + + modelBuilder.Entity("Backbone.Modules.Messages.Domain.Entities.Attachment", b => + { + b.HasOne("Backbone.Modules.Messages.Domain.Entities.Message", "Message") + .WithMany("Attachments") + .HasForeignKey("MessageId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Message"); + }); + + modelBuilder.Entity("Backbone.Modules.Messages.Domain.Entities.RecipientInformation", b => + { + b.HasOne("Backbone.Modules.Messages.Domain.Entities.Message", null) + .WithMany("Recipients") + .HasForeignKey("MessageId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Backbone.Modules.Messages.Domain.Entities.Relationship", null) + .WithMany() + .HasForeignKey("RelationshipId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Backbone.Modules.Messages.Domain.Entities.Message", b => + { + b.Navigation("Attachments"); + + b.Navigation("Recipients"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Modules/Messages/src/Messages.Infrastructure/CompiledModels/Postgres/AttachmentEntityType.cs b/Modules/Messages/src/Messages.Infrastructure/CompiledModels/Postgres/AttachmentEntityType.cs index 5de3e3cdec..ebe585c017 100644 --- a/Modules/Messages/src/Messages.Infrastructure/CompiledModels/Postgres/AttachmentEntityType.cs +++ b/Modules/Messages/src/Messages.Infrastructure/CompiledModels/Postgres/AttachmentEntityType.cs @@ -1,96 +1,96 @@ -// -using System; -using System.Collections.Generic; -using System.Reflection; -using Backbone.Modules.Messages.Domain.Entities; -using Backbone.Modules.Messages.Domain.Ids; -using Backbone.Modules.Messages.Infrastructure.Persistence.Database.ValueConverters; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Metadata; - -#pragma warning disable 219, 612, 618 -#nullable enable - -namespace Backbone.Modules.Messages.Infrastructure.CompiledModels.Postgres -{ - internal partial class AttachmentEntityType - { - public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType? baseEntityType = null) - { - var runtimeEntityType = model.AddEntityType( - "Backbone.Modules.Messages.Domain.Entities.Attachment", - typeof(Attachment), - baseEntityType); - - var id = runtimeEntityType.AddProperty( - "Id", - typeof(FileId), - propertyInfo: typeof(Attachment).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), - fieldInfo: typeof(Attachment).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), - afterSaveBehavior: PropertySaveBehavior.Throw, - maxLength: 20, - unicode: false, - valueConverter: new FileIdEntityFrameworkValueConverter()); - id.AddAnnotation("Relational:IsFixedLength", true); - - var messageId = runtimeEntityType.AddProperty( - "MessageId", - typeof(MessageId), - propertyInfo: typeof(Attachment).GetProperty("MessageId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), - fieldInfo: typeof(Attachment).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), - afterSaveBehavior: PropertySaveBehavior.Throw, - maxLength: 20, - unicode: false, - valueConverter: new MessageIdEntityFrameworkValueConverter()); - messageId.AddAnnotation("Relational:IsFixedLength", true); - - var key = runtimeEntityType.AddKey( - new[] { id, messageId }); - runtimeEntityType.SetPrimaryKey(key); - - var index = runtimeEntityType.AddIndex( - new[] { messageId }); - - return runtimeEntityType; - } - - public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) - { - var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("MessageId")! }, - principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id")! })!, - principalEntityType, - deleteBehavior: DeleteBehavior.Cascade, - required: true); - - var message = declaringEntityType.AddNavigation("Message", - runtimeForeignKey, - onDependent: true, - typeof(Message), - propertyInfo: typeof(Attachment).GetProperty("Message", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), - fieldInfo: typeof(Attachment).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); - - var attachments = principalEntityType.AddNavigation("Attachments", - runtimeForeignKey, - onDependent: false, - typeof(IReadOnlyCollection), - propertyInfo: typeof(Message).GetProperty("Attachments", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), - fieldInfo: typeof(Message).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); - - return runtimeForeignKey; - } - - public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) - { - runtimeEntityType.AddAnnotation("Relational:FunctionName", null); - runtimeEntityType.AddAnnotation("Relational:Schema", null); - runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); - runtimeEntityType.AddAnnotation("Relational:TableName", "Attachments"); - runtimeEntityType.AddAnnotation("Relational:ViewName", null); - runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); - - Customize(runtimeEntityType); - } - - static partial void Customize(RuntimeEntityType runtimeEntityType); - } -} +// +using System; +using System.Collections.Generic; +using System.Reflection; +using Backbone.Modules.Messages.Domain.Entities; +using Backbone.Modules.Messages.Domain.Ids; +using Backbone.Modules.Messages.Infrastructure.Persistence.Database.ValueConverters; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable enable + +namespace Backbone.Modules.Messages.Infrastructure.CompiledModels.Postgres +{ + internal partial class AttachmentEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType? baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Backbone.Modules.Messages.Domain.Entities.Attachment", + typeof(Attachment), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(FileId), + propertyInfo: typeof(Attachment).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Attachment).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 20, + unicode: false, + valueConverter: new FileIdEntityFrameworkValueConverter()); + id.AddAnnotation("Relational:IsFixedLength", true); + + var messageId = runtimeEntityType.AddProperty( + "MessageId", + typeof(MessageId), + propertyInfo: typeof(Attachment).GetProperty("MessageId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Attachment).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 20, + unicode: false, + valueConverter: new MessageIdEntityFrameworkValueConverter()); + messageId.AddAnnotation("Relational:IsFixedLength", true); + + var key = runtimeEntityType.AddKey( + new[] { id, messageId }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { messageId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("MessageId")! }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id")! })!, + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + var message = declaringEntityType.AddNavigation("Message", + runtimeForeignKey, + onDependent: true, + typeof(Message), + propertyInfo: typeof(Attachment).GetProperty("Message", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Attachment).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var attachments = principalEntityType.AddNavigation("Attachments", + runtimeForeignKey, + onDependent: false, + typeof(IReadOnlyCollection), + propertyInfo: typeof(Message).GetProperty("Attachments", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Message).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Attachments"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/Modules/Messages/src/Messages.Infrastructure/CompiledModels/Postgres/MessageEntityType.cs b/Modules/Messages/src/Messages.Infrastructure/CompiledModels/Postgres/MessageEntityType.cs index 171a432f08..bfab9cbce1 100644 --- a/Modules/Messages/src/Messages.Infrastructure/CompiledModels/Postgres/MessageEntityType.cs +++ b/Modules/Messages/src/Messages.Infrastructure/CompiledModels/Postgres/MessageEntityType.cs @@ -1,101 +1,107 @@ -// -using System; -using System.Reflection; -using Backbone.BuildingBlocks.Infrastructure.Persistence.Database.ValueConverters; -using Backbone.DevelopmentKit.Identity.ValueObjects; -using Backbone.Modules.Messages.Domain.Entities; -using Backbone.Modules.Messages.Domain.Ids; -using Backbone.Modules.Messages.Infrastructure.Persistence.Database.ValueConverters; -using Microsoft.EntityFrameworkCore.Metadata; - -#pragma warning disable 219, 612, 618 -#nullable enable - -namespace Backbone.Modules.Messages.Infrastructure.CompiledModels.Postgres -{ - internal partial class MessageEntityType - { - public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType? baseEntityType = null) - { - var runtimeEntityType = model.AddEntityType( - "Backbone.Modules.Messages.Domain.Entities.Message", - typeof(Message), - baseEntityType); - - var id = runtimeEntityType.AddProperty( - "Id", - typeof(MessageId), - propertyInfo: typeof(Message).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), - fieldInfo: typeof(Message).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), - afterSaveBehavior: PropertySaveBehavior.Throw, - maxLength: 20, - unicode: false, - valueConverter: new MessageIdEntityFrameworkValueConverter()); - id.AddAnnotation("Relational:IsFixedLength", true); - - var createdAt = runtimeEntityType.AddProperty( - "CreatedAt", - typeof(DateTime), - propertyInfo: typeof(Message).GetProperty("CreatedAt", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), - fieldInfo: typeof(Message).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), - valueConverter: new DateTimeValueConverter()); - - var createdBy = runtimeEntityType.AddProperty( - "CreatedBy", - typeof(IdentityAddress), - propertyInfo: typeof(Message).GetProperty("CreatedBy", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), - fieldInfo: typeof(Message).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), - maxLength: 36, - unicode: false, - valueConverter: new IdentityAddressValueConverter()); - createdBy.AddAnnotation("Relational:IsFixedLength", true); - - var createdByDevice = runtimeEntityType.AddProperty( - "CreatedByDevice", - typeof(DeviceId), - propertyInfo: typeof(Message).GetProperty("CreatedByDevice", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), - fieldInfo: typeof(Message).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), - maxLength: 20, - unicode: false, - valueConverter: new DeviceIdValueConverter()); - createdByDevice.AddAnnotation("Relational:IsFixedLength", true); - - var doNotSendBefore = runtimeEntityType.AddProperty( - "DoNotSendBefore", - typeof(DateTime?), - propertyInfo: typeof(Message).GetProperty("DoNotSendBefore", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), - fieldInfo: typeof(Message).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), - nullable: true, - valueConverter: new NullableDateTimeValueConverter()); - - var key = runtimeEntityType.AddKey( - new[] { id }); - runtimeEntityType.SetPrimaryKey(key); - - var index = runtimeEntityType.AddIndex( - new[] { createdAt }); - - var index0 = runtimeEntityType.AddIndex( - new[] { createdBy }); - - var index1 = runtimeEntityType.AddIndex( - new[] { doNotSendBefore }); - - return runtimeEntityType; - } - - public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) - { - runtimeEntityType.AddAnnotation("Relational:FunctionName", null); - runtimeEntityType.AddAnnotation("Relational:Schema", null); - runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); - runtimeEntityType.AddAnnotation("Relational:TableName", "Messages"); - runtimeEntityType.AddAnnotation("Relational:ViewName", null); - runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); - - Customize(runtimeEntityType); - } - - static partial void Customize(RuntimeEntityType runtimeEntityType); - } -} +// +using System; +using System.Reflection; +using Backbone.BuildingBlocks.Infrastructure.Persistence.Database.ValueConverters; +using Backbone.DevelopmentKit.Identity.ValueObjects; +using Backbone.Modules.Messages.Domain.Entities; +using Backbone.Modules.Messages.Domain.Ids; +using Backbone.Modules.Messages.Infrastructure.Persistence.Database.ValueConverters; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable enable + +namespace Backbone.Modules.Messages.Infrastructure.CompiledModels.Postgres +{ + internal partial class MessageEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType? baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Backbone.Modules.Messages.Domain.Entities.Message", + typeof(Message), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(MessageId), + propertyInfo: typeof(Message).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Message).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 20, + unicode: false, + valueConverter: new MessageIdEntityFrameworkValueConverter()); + id.AddAnnotation("Relational:IsFixedLength", true); + + var body = runtimeEntityType.AddProperty( + "Body", + typeof(byte[]), + propertyInfo: typeof(Message).GetProperty("Body", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Message).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var createdAt = runtimeEntityType.AddProperty( + "CreatedAt", + typeof(DateTime), + propertyInfo: typeof(Message).GetProperty("CreatedAt", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Message).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueConverter: new DateTimeValueConverter()); + + var createdBy = runtimeEntityType.AddProperty( + "CreatedBy", + typeof(IdentityAddress), + propertyInfo: typeof(Message).GetProperty("CreatedBy", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Message).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 36, + unicode: false, + valueConverter: new IdentityAddressValueConverter()); + createdBy.AddAnnotation("Relational:IsFixedLength", true); + + var createdByDevice = runtimeEntityType.AddProperty( + "CreatedByDevice", + typeof(DeviceId), + propertyInfo: typeof(Message).GetProperty("CreatedByDevice", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Message).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 20, + unicode: false, + valueConverter: new DeviceIdValueConverter()); + createdByDevice.AddAnnotation("Relational:IsFixedLength", true); + + var doNotSendBefore = runtimeEntityType.AddProperty( + "DoNotSendBefore", + typeof(DateTime?), + propertyInfo: typeof(Message).GetProperty("DoNotSendBefore", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Message).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + valueConverter: new NullableDateTimeValueConverter()); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { createdAt }); + + var index0 = runtimeEntityType.AddIndex( + new[] { createdBy }); + + var index1 = runtimeEntityType.AddIndex( + new[] { doNotSendBefore }); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Messages"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/Modules/Messages/src/Messages.Infrastructure/CompiledModels/Postgres/MessagesDbContextModel.cs b/Modules/Messages/src/Messages.Infrastructure/CompiledModels/Postgres/MessagesDbContextModel.cs index b770f86890..1517d9af83 100644 --- a/Modules/Messages/src/Messages.Infrastructure/CompiledModels/Postgres/MessagesDbContextModel.cs +++ b/Modules/Messages/src/Messages.Infrastructure/CompiledModels/Postgres/MessagesDbContextModel.cs @@ -1,30 +1,29 @@ -// - -using Backbone.Modules.Messages.Infrastructure.Persistence.Database; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; - -#pragma warning disable 219, 612, 618 -#nullable enable - -namespace Backbone.Modules.Messages.Infrastructure.CompiledModels.Postgres -{ - [DbContext(typeof(MessagesDbContext))] - public partial class MessagesDbContextModel : RuntimeModel - { - static MessagesDbContextModel() - { - var model = new MessagesDbContextModel(); - model.Initialize(); - model.Customize(); - _instance = model; - } - - private static MessagesDbContextModel _instance; - public static IModel Instance => _instance; - - partial void Initialize(); - - partial void Customize(); - } -} +// +using Backbone.Modules.Messages.Infrastructure.Persistence.Database; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable enable + +namespace Backbone.Modules.Messages.Infrastructure.CompiledModels.Postgres +{ + [DbContext(typeof(MessagesDbContext))] + public partial class MessagesDbContextModel : RuntimeModel + { + static MessagesDbContextModel() + { + var model = new MessagesDbContextModel(); + model.Initialize(); + model.Customize(); + _instance = model; + } + + private static MessagesDbContextModel _instance; + public static IModel Instance => _instance; + + partial void Initialize(); + + partial void Customize(); + } +} diff --git a/Modules/Messages/src/Messages.Infrastructure/CompiledModels/Postgres/MessagesDbContextModelBuilder.cs b/Modules/Messages/src/Messages.Infrastructure/CompiledModels/Postgres/MessagesDbContextModelBuilder.cs index 164432a0bc..082380e208 100644 --- a/Modules/Messages/src/Messages.Infrastructure/CompiledModels/Postgres/MessagesDbContextModelBuilder.cs +++ b/Modules/Messages/src/Messages.Infrastructure/CompiledModels/Postgres/MessagesDbContextModelBuilder.cs @@ -1,35 +1,35 @@ -// -using System; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; - -#pragma warning disable 219, 612, 618 -#nullable enable - -namespace Backbone.Modules.Messages.Infrastructure.CompiledModels.Postgres -{ - public partial class MessagesDbContextModel - { - partial void Initialize() - { - var attachment = AttachmentEntityType.Create(this); - var message = MessageEntityType.Create(this); - var recipientInformation = RecipientInformationEntityType.Create(this); - var relationship = RelationshipEntityType.Create(this); - - AttachmentEntityType.CreateForeignKey1(attachment, message); - RecipientInformationEntityType.CreateForeignKey1(recipientInformation, message); - RecipientInformationEntityType.CreateForeignKey2(recipientInformation, relationship); - - AttachmentEntityType.CreateAnnotations(attachment); - MessageEntityType.CreateAnnotations(message); - RecipientInformationEntityType.CreateAnnotations(recipientInformation); - RelationshipEntityType.CreateAnnotations(relationship); - - AddAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); - AddAnnotation("ProductVersion", "7.0.11"); - AddAnnotation("Relational:MaxIdentifierLength", 63); - } - } -} +// +using System; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable enable + +namespace Backbone.Modules.Messages.Infrastructure.CompiledModels.Postgres +{ + public partial class MessagesDbContextModel + { + partial void Initialize() + { + var attachment = AttachmentEntityType.Create(this); + var message = MessageEntityType.Create(this); + var recipientInformation = RecipientInformationEntityType.Create(this); + var relationship = RelationshipEntityType.Create(this); + + AttachmentEntityType.CreateForeignKey1(attachment, message); + RecipientInformationEntityType.CreateForeignKey1(recipientInformation, message); + RecipientInformationEntityType.CreateForeignKey2(recipientInformation, relationship); + + AttachmentEntityType.CreateAnnotations(attachment); + MessageEntityType.CreateAnnotations(message); + RecipientInformationEntityType.CreateAnnotations(recipientInformation); + RelationshipEntityType.CreateAnnotations(relationship); + + AddAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); + AddAnnotation("ProductVersion", "7.0.13"); + AddAnnotation("Relational:MaxIdentifierLength", 63); + } + } +} diff --git a/Modules/Messages/src/Messages.Infrastructure/CompiledModels/Postgres/RecipientInformationEntityType.cs b/Modules/Messages/src/Messages.Infrastructure/CompiledModels/Postgres/RecipientInformationEntityType.cs index 4403677b64..442f401ecd 100644 --- a/Modules/Messages/src/Messages.Infrastructure/CompiledModels/Postgres/RecipientInformationEntityType.cs +++ b/Modules/Messages/src/Messages.Infrastructure/CompiledModels/Postgres/RecipientInformationEntityType.cs @@ -1,143 +1,143 @@ -// -using System; -using System.Collections.Generic; -using System.Reflection; -using Backbone.BuildingBlocks.Infrastructure.Persistence.Database.ValueConverters; -using Backbone.DevelopmentKit.Identity.ValueObjects; -using Backbone.Modules.Messages.Domain.Entities; -using Backbone.Modules.Messages.Domain.Ids; -using Backbone.Modules.Messages.Infrastructure.Persistence.Database.ValueConverters; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Metadata; - -#pragma warning disable 219, 612, 618 -#nullable enable - -namespace Backbone.Modules.Messages.Infrastructure.CompiledModels.Postgres -{ - internal partial class RecipientInformationEntityType - { - public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType? baseEntityType = null) - { - var runtimeEntityType = model.AddEntityType( - "Backbone.Modules.Messages.Domain.Entities.RecipientInformation", - typeof(RecipientInformation), - baseEntityType); - - var address = runtimeEntityType.AddProperty( - "Address", - typeof(IdentityAddress), - propertyInfo: typeof(RecipientInformation).GetProperty("Address", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), - fieldInfo: typeof(RecipientInformation).GetField("
k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), - afterSaveBehavior: PropertySaveBehavior.Throw, - maxLength: 36, - unicode: false, - valueConverter: new IdentityAddressValueConverter()); - address.AddAnnotation("Relational:IsFixedLength", true); - - var messageId = runtimeEntityType.AddProperty( - "MessageId", - typeof(MessageId), - propertyInfo: typeof(RecipientInformation).GetProperty("MessageId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), - fieldInfo: typeof(RecipientInformation).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), - afterSaveBehavior: PropertySaveBehavior.Throw, - maxLength: 20, - unicode: false, - valueConverter: new MessageIdEntityFrameworkValueConverter()); - messageId.AddAnnotation("Relational:IsFixedLength", true); - - var encryptedKey = runtimeEntityType.AddProperty( - "EncryptedKey", - typeof(byte[]), - propertyInfo: typeof(RecipientInformation).GetProperty("EncryptedKey", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), - fieldInfo: typeof(RecipientInformation).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); - - var receivedAt = runtimeEntityType.AddProperty( - "ReceivedAt", - typeof(DateTime?), - propertyInfo: typeof(RecipientInformation).GetProperty("ReceivedAt", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), - fieldInfo: typeof(RecipientInformation).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), - nullable: true, - valueConverter: new NullableDateTimeValueConverter()); - - var receivedByDevice = runtimeEntityType.AddProperty( - "ReceivedByDevice", - typeof(DeviceId), - propertyInfo: typeof(RecipientInformation).GetProperty("ReceivedByDevice", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), - fieldInfo: typeof(RecipientInformation).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), - nullable: true, - maxLength: 20, - unicode: false, - valueConverter: new DeviceIdValueConverter()); - receivedByDevice.AddAnnotation("Relational:IsFixedLength", true); - - var relationshipId = runtimeEntityType.AddProperty( - "RelationshipId", - typeof(RelationshipId), - propertyInfo: typeof(RecipientInformation).GetProperty("RelationshipId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), - fieldInfo: typeof(RecipientInformation).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), - maxLength: 20, - unicode: false, - valueConverter: new RelationshipIdEntityFrameworkValueConverter()); - relationshipId.AddAnnotation("Relational:IsFixedLength", true); - - var key = runtimeEntityType.AddKey( - new[] { address, messageId }); - runtimeEntityType.SetPrimaryKey(key); - - var index = runtimeEntityType.AddIndex( - new[] { messageId }); - - var index0 = runtimeEntityType.AddIndex( - new[] { receivedAt }); - - var index1 = runtimeEntityType.AddIndex( - new[] { relationshipId }); - - return runtimeEntityType; - } - - public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) - { - var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("MessageId")! }, - principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id")! })!, - principalEntityType, - deleteBehavior: DeleteBehavior.Cascade, - required: true); - - var recipients = principalEntityType.AddNavigation("Recipients", - runtimeForeignKey, - onDependent: false, - typeof(IReadOnlyCollection), - propertyInfo: typeof(Message).GetProperty("Recipients", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), - fieldInfo: typeof(Message).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); - - return runtimeForeignKey; - } - - public static RuntimeForeignKey CreateForeignKey2(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) - { - var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("RelationshipId")! }, - principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id")! })!, - principalEntityType, - deleteBehavior: DeleteBehavior.Cascade, - required: true); - - return runtimeForeignKey; - } - - public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) - { - runtimeEntityType.AddAnnotation("Relational:FunctionName", null); - runtimeEntityType.AddAnnotation("Relational:Schema", null); - runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); - runtimeEntityType.AddAnnotation("Relational:TableName", "RecipientInformation"); - runtimeEntityType.AddAnnotation("Relational:ViewName", null); - runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); - - Customize(runtimeEntityType); - } - - static partial void Customize(RuntimeEntityType runtimeEntityType); - } -} +// +using System; +using System.Collections.Generic; +using System.Reflection; +using Backbone.BuildingBlocks.Infrastructure.Persistence.Database.ValueConverters; +using Backbone.DevelopmentKit.Identity.ValueObjects; +using Backbone.Modules.Messages.Domain.Entities; +using Backbone.Modules.Messages.Domain.Ids; +using Backbone.Modules.Messages.Infrastructure.Persistence.Database.ValueConverters; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable enable + +namespace Backbone.Modules.Messages.Infrastructure.CompiledModels.Postgres +{ + internal partial class RecipientInformationEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType? baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Backbone.Modules.Messages.Domain.Entities.RecipientInformation", + typeof(RecipientInformation), + baseEntityType); + + var address = runtimeEntityType.AddProperty( + "Address", + typeof(IdentityAddress), + propertyInfo: typeof(RecipientInformation).GetProperty("Address", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(RecipientInformation).GetField("
k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 36, + unicode: false, + valueConverter: new IdentityAddressValueConverter()); + address.AddAnnotation("Relational:IsFixedLength", true); + + var messageId = runtimeEntityType.AddProperty( + "MessageId", + typeof(MessageId), + propertyInfo: typeof(RecipientInformation).GetProperty("MessageId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(RecipientInformation).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 20, + unicode: false, + valueConverter: new MessageIdEntityFrameworkValueConverter()); + messageId.AddAnnotation("Relational:IsFixedLength", true); + + var encryptedKey = runtimeEntityType.AddProperty( + "EncryptedKey", + typeof(byte[]), + propertyInfo: typeof(RecipientInformation).GetProperty("EncryptedKey", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(RecipientInformation).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var receivedAt = runtimeEntityType.AddProperty( + "ReceivedAt", + typeof(DateTime?), + propertyInfo: typeof(RecipientInformation).GetProperty("ReceivedAt", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(RecipientInformation).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + valueConverter: new NullableDateTimeValueConverter()); + + var receivedByDevice = runtimeEntityType.AddProperty( + "ReceivedByDevice", + typeof(DeviceId), + propertyInfo: typeof(RecipientInformation).GetProperty("ReceivedByDevice", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(RecipientInformation).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 20, + unicode: false, + valueConverter: new DeviceIdValueConverter()); + receivedByDevice.AddAnnotation("Relational:IsFixedLength", true); + + var relationshipId = runtimeEntityType.AddProperty( + "RelationshipId", + typeof(RelationshipId), + propertyInfo: typeof(RecipientInformation).GetProperty("RelationshipId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(RecipientInformation).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 20, + unicode: false, + valueConverter: new RelationshipIdEntityFrameworkValueConverter()); + relationshipId.AddAnnotation("Relational:IsFixedLength", true); + + var key = runtimeEntityType.AddKey( + new[] { address, messageId }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { messageId }); + + var index0 = runtimeEntityType.AddIndex( + new[] { receivedAt }); + + var index1 = runtimeEntityType.AddIndex( + new[] { relationshipId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("MessageId")! }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id")! })!, + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + var recipients = principalEntityType.AddNavigation("Recipients", + runtimeForeignKey, + onDependent: false, + typeof(IReadOnlyCollection), + propertyInfo: typeof(Message).GetProperty("Recipients", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Message).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static RuntimeForeignKey CreateForeignKey2(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("RelationshipId")! }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id")! })!, + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "RecipientInformation"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/Modules/Messages/src/Messages.Infrastructure/CompiledModels/Postgres/RelationshipEntityType.cs b/Modules/Messages/src/Messages.Infrastructure/CompiledModels/Postgres/RelationshipEntityType.cs index ff6df58163..aec48575f5 100644 --- a/Modules/Messages/src/Messages.Infrastructure/CompiledModels/Postgres/RelationshipEntityType.cs +++ b/Modules/Messages/src/Messages.Infrastructure/CompiledModels/Postgres/RelationshipEntityType.cs @@ -1,90 +1,90 @@ -// -using System; -using System.Reflection; -using Backbone.BuildingBlocks.Infrastructure.Persistence.Database.ValueConverters; -using Backbone.DevelopmentKit.Identity.ValueObjects; -using Backbone.Modules.Messages.Domain.Entities; -using Backbone.Modules.Messages.Domain.Ids; -using Backbone.Modules.Messages.Infrastructure.Persistence.Database.ValueConverters; -using Microsoft.EntityFrameworkCore.Metadata; - -#pragma warning disable 219, 612, 618 -#nullable enable - -namespace Backbone.Modules.Messages.Infrastructure.CompiledModels.Postgres -{ - internal partial class RelationshipEntityType - { - public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType? baseEntityType = null) - { - var runtimeEntityType = model.AddEntityType( - "Backbone.Modules.Messages.Domain.Entities.Relationship", - typeof(Relationship), - baseEntityType); - - var id = runtimeEntityType.AddProperty( - "Id", - typeof(RelationshipId), - propertyInfo: typeof(Relationship).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), - fieldInfo: typeof(Relationship).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), - afterSaveBehavior: PropertySaveBehavior.Throw, - maxLength: 20, - unicode: false, - valueConverter: new RelationshipIdEntityFrameworkValueConverter()); - id.AddAnnotation("Relational:IsFixedLength", true); - - var createdAt = runtimeEntityType.AddProperty( - "CreatedAt", - typeof(DateTime), - propertyInfo: typeof(Relationship).GetProperty("CreatedAt", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), - fieldInfo: typeof(Relationship).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), - valueConverter: new DateTimeValueConverter()); - - var from = runtimeEntityType.AddProperty( - "From", - typeof(IdentityAddress), - propertyInfo: typeof(Relationship).GetProperty("From", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), - fieldInfo: typeof(Relationship).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), - maxLength: 36, - unicode: false, - valueConverter: new IdentityAddressValueConverter()); - from.AddAnnotation("Relational:IsFixedLength", true); - - var status = runtimeEntityType.AddProperty( - "Status", - typeof(RelationshipStatus), - propertyInfo: typeof(Relationship).GetProperty("Status", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), - fieldInfo: typeof(Relationship).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); - - var to = runtimeEntityType.AddProperty( - "To", - typeof(IdentityAddress), - propertyInfo: typeof(Relationship).GetProperty("To", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), - fieldInfo: typeof(Relationship).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), - maxLength: 36, - unicode: false, - valueConverter: new IdentityAddressValueConverter()); - to.AddAnnotation("Relational:IsFixedLength", true); - - var key = runtimeEntityType.AddKey( - new[] { id }); - runtimeEntityType.SetPrimaryKey(key); - - return runtimeEntityType; - } - - public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) - { - runtimeEntityType.AddAnnotation("Relational:FunctionName", null); - runtimeEntityType.AddAnnotation("Relational:Schema", "Relationships"); - runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); - runtimeEntityType.AddAnnotation("Relational:TableName", "Relationships"); - runtimeEntityType.AddAnnotation("Relational:ViewName", null); - runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); - - Customize(runtimeEntityType); - } - - static partial void Customize(RuntimeEntityType runtimeEntityType); - } -} +// +using System; +using System.Reflection; +using Backbone.BuildingBlocks.Infrastructure.Persistence.Database.ValueConverters; +using Backbone.DevelopmentKit.Identity.ValueObjects; +using Backbone.Modules.Messages.Domain.Entities; +using Backbone.Modules.Messages.Domain.Ids; +using Backbone.Modules.Messages.Infrastructure.Persistence.Database.ValueConverters; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable enable + +namespace Backbone.Modules.Messages.Infrastructure.CompiledModels.Postgres +{ + internal partial class RelationshipEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType? baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Backbone.Modules.Messages.Domain.Entities.Relationship", + typeof(Relationship), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(RelationshipId), + propertyInfo: typeof(Relationship).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Relationship).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 20, + unicode: false, + valueConverter: new RelationshipIdEntityFrameworkValueConverter()); + id.AddAnnotation("Relational:IsFixedLength", true); + + var createdAt = runtimeEntityType.AddProperty( + "CreatedAt", + typeof(DateTime), + propertyInfo: typeof(Relationship).GetProperty("CreatedAt", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Relationship).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueConverter: new DateTimeValueConverter()); + + var from = runtimeEntityType.AddProperty( + "From", + typeof(IdentityAddress), + propertyInfo: typeof(Relationship).GetProperty("From", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Relationship).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 36, + unicode: false, + valueConverter: new IdentityAddressValueConverter()); + from.AddAnnotation("Relational:IsFixedLength", true); + + var status = runtimeEntityType.AddProperty( + "Status", + typeof(RelationshipStatus), + propertyInfo: typeof(Relationship).GetProperty("Status", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Relationship).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var to = runtimeEntityType.AddProperty( + "To", + typeof(IdentityAddress), + propertyInfo: typeof(Relationship).GetProperty("To", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Relationship).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 36, + unicode: false, + valueConverter: new IdentityAddressValueConverter()); + to.AddAnnotation("Relational:IsFixedLength", true); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", "Relationships"); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Relationships"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/Modules/Messages/src/Messages.Infrastructure/CompiledModels/SqlServer/AttachmentEntityType.cs b/Modules/Messages/src/Messages.Infrastructure/CompiledModels/SqlServer/AttachmentEntityType.cs index 726914d295..e9d80c3916 100644 --- a/Modules/Messages/src/Messages.Infrastructure/CompiledModels/SqlServer/AttachmentEntityType.cs +++ b/Modules/Messages/src/Messages.Infrastructure/CompiledModels/SqlServer/AttachmentEntityType.cs @@ -1,98 +1,98 @@ -// -using System; -using System.Collections.Generic; -using System.Reflection; -using Backbone.Modules.Messages.Domain.Entities; -using Backbone.Modules.Messages.Domain.Ids; -using Backbone.Modules.Messages.Infrastructure.Persistence.Database.ValueConverters; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Metadata; - -#pragma warning disable 219, 612, 618 -#nullable enable - -namespace Backbone.Modules.Messages.Infrastructure.CompiledModels.SqlServer -{ - internal partial class AttachmentEntityType - { - public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType? baseEntityType = null) - { - var runtimeEntityType = model.AddEntityType( - "Backbone.Modules.Messages.Domain.Entities.Attachment", - typeof(Attachment), - baseEntityType); - - var id = runtimeEntityType.AddProperty( - "Id", - typeof(FileId), - propertyInfo: typeof(Attachment).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), - fieldInfo: typeof(Attachment).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), - afterSaveBehavior: PropertySaveBehavior.Throw, - maxLength: 20, - unicode: false, - valueConverter: new FileIdEntityFrameworkValueConverter()); - id.AddAnnotation("Relational:IsFixedLength", true); - id.AddAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.None); - - var messageId = runtimeEntityType.AddProperty( - "MessageId", - typeof(MessageId), - propertyInfo: typeof(Attachment).GetProperty("MessageId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), - fieldInfo: typeof(Attachment).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), - afterSaveBehavior: PropertySaveBehavior.Throw, - maxLength: 20, - unicode: false, - valueConverter: new MessageIdEntityFrameworkValueConverter()); - messageId.AddAnnotation("Relational:IsFixedLength", true); - messageId.AddAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.None); - - var key = runtimeEntityType.AddKey( - new[] { id, messageId }); - runtimeEntityType.SetPrimaryKey(key); - - var index = runtimeEntityType.AddIndex( - new[] { messageId }); - - return runtimeEntityType; - } - - public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) - { - var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("MessageId")! }, - principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id")! })!, - principalEntityType, - deleteBehavior: DeleteBehavior.Cascade, - required: true); - - var message = declaringEntityType.AddNavigation("Message", - runtimeForeignKey, - onDependent: true, - typeof(Message), - propertyInfo: typeof(Attachment).GetProperty("Message", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), - fieldInfo: typeof(Attachment).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); - - var attachments = principalEntityType.AddNavigation("Attachments", - runtimeForeignKey, - onDependent: false, - typeof(IReadOnlyCollection), - propertyInfo: typeof(Message).GetProperty("Attachments", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), - fieldInfo: typeof(Message).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); - - return runtimeForeignKey; - } - - public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) - { - runtimeEntityType.AddAnnotation("Relational:FunctionName", null); - runtimeEntityType.AddAnnotation("Relational:Schema", null); - runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); - runtimeEntityType.AddAnnotation("Relational:TableName", "Attachments"); - runtimeEntityType.AddAnnotation("Relational:ViewName", null); - runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); - - Customize(runtimeEntityType); - } - - static partial void Customize(RuntimeEntityType runtimeEntityType); - } -} +// +using System; +using System.Collections.Generic; +using System.Reflection; +using Backbone.Modules.Messages.Domain.Entities; +using Backbone.Modules.Messages.Domain.Ids; +using Backbone.Modules.Messages.Infrastructure.Persistence.Database.ValueConverters; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable enable + +namespace Backbone.Modules.Messages.Infrastructure.CompiledModels.SqlServer +{ + internal partial class AttachmentEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType? baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Backbone.Modules.Messages.Domain.Entities.Attachment", + typeof(Attachment), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(FileId), + propertyInfo: typeof(Attachment).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Attachment).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 20, + unicode: false, + valueConverter: new FileIdEntityFrameworkValueConverter()); + id.AddAnnotation("Relational:IsFixedLength", true); + id.AddAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.None); + + var messageId = runtimeEntityType.AddProperty( + "MessageId", + typeof(MessageId), + propertyInfo: typeof(Attachment).GetProperty("MessageId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Attachment).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 20, + unicode: false, + valueConverter: new MessageIdEntityFrameworkValueConverter()); + messageId.AddAnnotation("Relational:IsFixedLength", true); + messageId.AddAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.None); + + var key = runtimeEntityType.AddKey( + new[] { id, messageId }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { messageId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("MessageId")! }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id")! })!, + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + var message = declaringEntityType.AddNavigation("Message", + runtimeForeignKey, + onDependent: true, + typeof(Message), + propertyInfo: typeof(Attachment).GetProperty("Message", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Attachment).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + var attachments = principalEntityType.AddNavigation("Attachments", + runtimeForeignKey, + onDependent: false, + typeof(IReadOnlyCollection), + propertyInfo: typeof(Message).GetProperty("Attachments", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Message).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Attachments"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/Modules/Messages/src/Messages.Infrastructure/CompiledModels/SqlServer/MessageEntityType.cs b/Modules/Messages/src/Messages.Infrastructure/CompiledModels/SqlServer/MessageEntityType.cs index 146d747742..0df4c5f0e5 100644 --- a/Modules/Messages/src/Messages.Infrastructure/CompiledModels/SqlServer/MessageEntityType.cs +++ b/Modules/Messages/src/Messages.Infrastructure/CompiledModels/SqlServer/MessageEntityType.cs @@ -1,106 +1,113 @@ -// -using System; -using System.Reflection; -using Backbone.BuildingBlocks.Infrastructure.Persistence.Database.ValueConverters; -using Backbone.DevelopmentKit.Identity.ValueObjects; -using Backbone.Modules.Messages.Domain.Entities; -using Backbone.Modules.Messages.Domain.Ids; -using Backbone.Modules.Messages.Infrastructure.Persistence.Database.ValueConverters; -using Microsoft.EntityFrameworkCore.Metadata; - -#pragma warning disable 219, 612, 618 -#nullable enable - -namespace Backbone.Modules.Messages.Infrastructure.CompiledModels.SqlServer -{ - internal partial class MessageEntityType - { - public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType? baseEntityType = null) - { - var runtimeEntityType = model.AddEntityType( - "Backbone.Modules.Messages.Domain.Entities.Message", - typeof(Message), - baseEntityType); - - var id = runtimeEntityType.AddProperty( - "Id", - typeof(MessageId), - propertyInfo: typeof(Message).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), - fieldInfo: typeof(Message).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), - afterSaveBehavior: PropertySaveBehavior.Throw, - maxLength: 20, - unicode: false, - valueConverter: new MessageIdEntityFrameworkValueConverter()); - id.AddAnnotation("Relational:IsFixedLength", true); - id.AddAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.None); - - var createdAt = runtimeEntityType.AddProperty( - "CreatedAt", - typeof(DateTime), - propertyInfo: typeof(Message).GetProperty("CreatedAt", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), - fieldInfo: typeof(Message).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), - valueConverter: new DateTimeValueConverter()); - createdAt.AddAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.None); - - var createdBy = runtimeEntityType.AddProperty( - "CreatedBy", - typeof(IdentityAddress), - propertyInfo: typeof(Message).GetProperty("CreatedBy", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), - fieldInfo: typeof(Message).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), - maxLength: 36, - unicode: false, - valueConverter: new IdentityAddressValueConverter()); - createdBy.AddAnnotation("Relational:IsFixedLength", true); - createdBy.AddAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.None); - - var createdByDevice = runtimeEntityType.AddProperty( - "CreatedByDevice", - typeof(DeviceId), - propertyInfo: typeof(Message).GetProperty("CreatedByDevice", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), - fieldInfo: typeof(Message).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), - maxLength: 20, - unicode: false, - valueConverter: new DeviceIdValueConverter()); - createdByDevice.AddAnnotation("Relational:IsFixedLength", true); - createdByDevice.AddAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.None); - - var doNotSendBefore = runtimeEntityType.AddProperty( - "DoNotSendBefore", - typeof(DateTime?), - propertyInfo: typeof(Message).GetProperty("DoNotSendBefore", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), - fieldInfo: typeof(Message).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), - nullable: true, - valueConverter: new NullableDateTimeValueConverter()); - doNotSendBefore.AddAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.None); - - var key = runtimeEntityType.AddKey( - new[] { id }); - runtimeEntityType.SetPrimaryKey(key); - - var index = runtimeEntityType.AddIndex( - new[] { createdAt }); - - var index0 = runtimeEntityType.AddIndex( - new[] { createdBy }); - - var index1 = runtimeEntityType.AddIndex( - new[] { doNotSendBefore }); - - return runtimeEntityType; - } - - public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) - { - runtimeEntityType.AddAnnotation("Relational:FunctionName", null); - runtimeEntityType.AddAnnotation("Relational:Schema", null); - runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); - runtimeEntityType.AddAnnotation("Relational:TableName", "Messages"); - runtimeEntityType.AddAnnotation("Relational:ViewName", null); - runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); - - Customize(runtimeEntityType); - } - - static partial void Customize(RuntimeEntityType runtimeEntityType); - } -} +// +using System; +using System.Reflection; +using Backbone.BuildingBlocks.Infrastructure.Persistence.Database.ValueConverters; +using Backbone.DevelopmentKit.Identity.ValueObjects; +using Backbone.Modules.Messages.Domain.Entities; +using Backbone.Modules.Messages.Domain.Ids; +using Backbone.Modules.Messages.Infrastructure.Persistence.Database.ValueConverters; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable enable + +namespace Backbone.Modules.Messages.Infrastructure.CompiledModels.SqlServer +{ + internal partial class MessageEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType? baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Backbone.Modules.Messages.Domain.Entities.Message", + typeof(Message), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(MessageId), + propertyInfo: typeof(Message).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Message).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 20, + unicode: false, + valueConverter: new MessageIdEntityFrameworkValueConverter()); + id.AddAnnotation("Relational:IsFixedLength", true); + id.AddAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.None); + + var body = runtimeEntityType.AddProperty( + "Body", + typeof(byte[]), + propertyInfo: typeof(Message).GetProperty("Body", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Message).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + body.AddAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.None); + + var createdAt = runtimeEntityType.AddProperty( + "CreatedAt", + typeof(DateTime), + propertyInfo: typeof(Message).GetProperty("CreatedAt", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Message).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueConverter: new DateTimeValueConverter()); + createdAt.AddAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.None); + + var createdBy = runtimeEntityType.AddProperty( + "CreatedBy", + typeof(IdentityAddress), + propertyInfo: typeof(Message).GetProperty("CreatedBy", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Message).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 36, + unicode: false, + valueConverter: new IdentityAddressValueConverter()); + createdBy.AddAnnotation("Relational:IsFixedLength", true); + createdBy.AddAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.None); + + var createdByDevice = runtimeEntityType.AddProperty( + "CreatedByDevice", + typeof(DeviceId), + propertyInfo: typeof(Message).GetProperty("CreatedByDevice", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Message).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 20, + unicode: false, + valueConverter: new DeviceIdValueConverter()); + createdByDevice.AddAnnotation("Relational:IsFixedLength", true); + createdByDevice.AddAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.None); + + var doNotSendBefore = runtimeEntityType.AddProperty( + "DoNotSendBefore", + typeof(DateTime?), + propertyInfo: typeof(Message).GetProperty("DoNotSendBefore", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Message).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + valueConverter: new NullableDateTimeValueConverter()); + doNotSendBefore.AddAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.None); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { createdAt }); + + var index0 = runtimeEntityType.AddIndex( + new[] { createdBy }); + + var index1 = runtimeEntityType.AddIndex( + new[] { doNotSendBefore }); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Messages"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/Modules/Messages/src/Messages.Infrastructure/CompiledModels/SqlServer/MessagesDbContextModel.cs b/Modules/Messages/src/Messages.Infrastructure/CompiledModels/SqlServer/MessagesDbContextModel.cs index dc501582db..458e006c92 100644 --- a/Modules/Messages/src/Messages.Infrastructure/CompiledModels/SqlServer/MessagesDbContextModel.cs +++ b/Modules/Messages/src/Messages.Infrastructure/CompiledModels/SqlServer/MessagesDbContextModel.cs @@ -1,30 +1,29 @@ -// - -using Backbone.Modules.Messages.Infrastructure.Persistence.Database; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; - -#pragma warning disable 219, 612, 618 -#nullable enable - -namespace Backbone.Modules.Messages.Infrastructure.CompiledModels.SqlServer -{ - [DbContext(typeof(MessagesDbContext))] - public partial class MessagesDbContextModel : RuntimeModel - { - static MessagesDbContextModel() - { - var model = new MessagesDbContextModel(); - model.Initialize(); - model.Customize(); - _instance = model; - } - - private static MessagesDbContextModel _instance; - public static IModel Instance => _instance; - - partial void Initialize(); - - partial void Customize(); - } -} +// +using Backbone.Modules.Messages.Infrastructure.Persistence.Database; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable enable + +namespace Backbone.Modules.Messages.Infrastructure.CompiledModels.SqlServer +{ + [DbContext(typeof(MessagesDbContext))] + public partial class MessagesDbContextModel : RuntimeModel + { + static MessagesDbContextModel() + { + var model = new MessagesDbContextModel(); + model.Initialize(); + model.Customize(); + _instance = model; + } + + private static MessagesDbContextModel _instance; + public static IModel Instance => _instance; + + partial void Initialize(); + + partial void Customize(); + } +} diff --git a/Modules/Messages/src/Messages.Infrastructure/CompiledModels/SqlServer/MessagesDbContextModelBuilder.cs b/Modules/Messages/src/Messages.Infrastructure/CompiledModels/SqlServer/MessagesDbContextModelBuilder.cs index df0db45442..8bdfa6626a 100644 --- a/Modules/Messages/src/Messages.Infrastructure/CompiledModels/SqlServer/MessagesDbContextModelBuilder.cs +++ b/Modules/Messages/src/Messages.Infrastructure/CompiledModels/SqlServer/MessagesDbContextModelBuilder.cs @@ -1,34 +1,34 @@ -// -using System; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; - -#pragma warning disable 219, 612, 618 -#nullable enable - -namespace Backbone.Modules.Messages.Infrastructure.CompiledModels.SqlServer -{ - public partial class MessagesDbContextModel - { - partial void Initialize() - { - var attachment = AttachmentEntityType.Create(this); - var message = MessageEntityType.Create(this); - var recipientInformation = RecipientInformationEntityType.Create(this); - var relationship = RelationshipEntityType.Create(this); - - AttachmentEntityType.CreateForeignKey1(attachment, message); - RecipientInformationEntityType.CreateForeignKey1(recipientInformation, message); - RecipientInformationEntityType.CreateForeignKey2(recipientInformation, relationship); - - AttachmentEntityType.CreateAnnotations(attachment); - MessageEntityType.CreateAnnotations(message); - RecipientInformationEntityType.CreateAnnotations(recipientInformation); - RelationshipEntityType.CreateAnnotations(relationship); - - AddAnnotation("ProductVersion", "7.0.11"); - AddAnnotation("Relational:MaxIdentifierLength", 128); - AddAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); - } - } -} +// +using System; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable enable + +namespace Backbone.Modules.Messages.Infrastructure.CompiledModels.SqlServer +{ + public partial class MessagesDbContextModel + { + partial void Initialize() + { + var attachment = AttachmentEntityType.Create(this); + var message = MessageEntityType.Create(this); + var recipientInformation = RecipientInformationEntityType.Create(this); + var relationship = RelationshipEntityType.Create(this); + + AttachmentEntityType.CreateForeignKey1(attachment, message); + RecipientInformationEntityType.CreateForeignKey1(recipientInformation, message); + RecipientInformationEntityType.CreateForeignKey2(recipientInformation, relationship); + + AttachmentEntityType.CreateAnnotations(attachment); + MessageEntityType.CreateAnnotations(message); + RecipientInformationEntityType.CreateAnnotations(recipientInformation); + RelationshipEntityType.CreateAnnotations(relationship); + + AddAnnotation("ProductVersion", "7.0.13"); + AddAnnotation("Relational:MaxIdentifierLength", 128); + AddAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + } + } +} diff --git a/Modules/Messages/src/Messages.Infrastructure/CompiledModels/SqlServer/RecipientInformationEntityType.cs b/Modules/Messages/src/Messages.Infrastructure/CompiledModels/SqlServer/RecipientInformationEntityType.cs index 7e0d2b2a09..7894cb243b 100644 --- a/Modules/Messages/src/Messages.Infrastructure/CompiledModels/SqlServer/RecipientInformationEntityType.cs +++ b/Modules/Messages/src/Messages.Infrastructure/CompiledModels/SqlServer/RecipientInformationEntityType.cs @@ -1,149 +1,149 @@ -// -using System; -using System.Collections.Generic; -using System.Reflection; -using Backbone.BuildingBlocks.Infrastructure.Persistence.Database.ValueConverters; -using Backbone.DevelopmentKit.Identity.ValueObjects; -using Backbone.Modules.Messages.Domain.Entities; -using Backbone.Modules.Messages.Domain.Ids; -using Backbone.Modules.Messages.Infrastructure.Persistence.Database.ValueConverters; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Metadata; - -#pragma warning disable 219, 612, 618 -#nullable enable - -namespace Backbone.Modules.Messages.Infrastructure.CompiledModels.SqlServer -{ - internal partial class RecipientInformationEntityType - { - public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType? baseEntityType = null) - { - var runtimeEntityType = model.AddEntityType( - "Backbone.Modules.Messages.Domain.Entities.RecipientInformation", - typeof(RecipientInformation), - baseEntityType); - - var address = runtimeEntityType.AddProperty( - "Address", - typeof(IdentityAddress), - propertyInfo: typeof(RecipientInformation).GetProperty("Address", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), - fieldInfo: typeof(RecipientInformation).GetField("
k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), - afterSaveBehavior: PropertySaveBehavior.Throw, - maxLength: 36, - unicode: false, - valueConverter: new IdentityAddressValueConverter()); - address.AddAnnotation("Relational:IsFixedLength", true); - address.AddAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.None); - - var messageId = runtimeEntityType.AddProperty( - "MessageId", - typeof(MessageId), - propertyInfo: typeof(RecipientInformation).GetProperty("MessageId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), - fieldInfo: typeof(RecipientInformation).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), - afterSaveBehavior: PropertySaveBehavior.Throw, - maxLength: 20, - unicode: false, - valueConverter: new MessageIdEntityFrameworkValueConverter()); - messageId.AddAnnotation("Relational:IsFixedLength", true); - messageId.AddAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.None); - - var encryptedKey = runtimeEntityType.AddProperty( - "EncryptedKey", - typeof(byte[]), - propertyInfo: typeof(RecipientInformation).GetProperty("EncryptedKey", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), - fieldInfo: typeof(RecipientInformation).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); - encryptedKey.AddAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.None); - - var receivedAt = runtimeEntityType.AddProperty( - "ReceivedAt", - typeof(DateTime?), - propertyInfo: typeof(RecipientInformation).GetProperty("ReceivedAt", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), - fieldInfo: typeof(RecipientInformation).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), - nullable: true, - valueConverter: new NullableDateTimeValueConverter()); - receivedAt.AddAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.None); - - var receivedByDevice = runtimeEntityType.AddProperty( - "ReceivedByDevice", - typeof(DeviceId), - propertyInfo: typeof(RecipientInformation).GetProperty("ReceivedByDevice", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), - fieldInfo: typeof(RecipientInformation).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), - nullable: true, - maxLength: 20, - unicode: false, - valueConverter: new DeviceIdValueConverter()); - receivedByDevice.AddAnnotation("Relational:IsFixedLength", true); - receivedByDevice.AddAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.None); - - var relationshipId = runtimeEntityType.AddProperty( - "RelationshipId", - typeof(RelationshipId), - propertyInfo: typeof(RecipientInformation).GetProperty("RelationshipId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), - fieldInfo: typeof(RecipientInformation).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), - maxLength: 20, - unicode: false, - valueConverter: new RelationshipIdEntityFrameworkValueConverter()); - relationshipId.AddAnnotation("Relational:IsFixedLength", true); - relationshipId.AddAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.None); - - var key = runtimeEntityType.AddKey( - new[] { address, messageId }); - runtimeEntityType.SetPrimaryKey(key); - - var index = runtimeEntityType.AddIndex( - new[] { messageId }); - - var index0 = runtimeEntityType.AddIndex( - new[] { receivedAt }); - - var index1 = runtimeEntityType.AddIndex( - new[] { relationshipId }); - - return runtimeEntityType; - } - - public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) - { - var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("MessageId")! }, - principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id")! })!, - principalEntityType, - deleteBehavior: DeleteBehavior.Cascade, - required: true); - - var recipients = principalEntityType.AddNavigation("Recipients", - runtimeForeignKey, - onDependent: false, - typeof(IReadOnlyCollection), - propertyInfo: typeof(Message).GetProperty("Recipients", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), - fieldInfo: typeof(Message).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); - - return runtimeForeignKey; - } - - public static RuntimeForeignKey CreateForeignKey2(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) - { - var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("RelationshipId")! }, - principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id")! })!, - principalEntityType, - deleteBehavior: DeleteBehavior.Cascade, - required: true); - - return runtimeForeignKey; - } - - public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) - { - runtimeEntityType.AddAnnotation("Relational:FunctionName", null); - runtimeEntityType.AddAnnotation("Relational:Schema", null); - runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); - runtimeEntityType.AddAnnotation("Relational:TableName", "RecipientInformation"); - runtimeEntityType.AddAnnotation("Relational:ViewName", null); - runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); - - Customize(runtimeEntityType); - } - - static partial void Customize(RuntimeEntityType runtimeEntityType); - } -} +// +using System; +using System.Collections.Generic; +using System.Reflection; +using Backbone.BuildingBlocks.Infrastructure.Persistence.Database.ValueConverters; +using Backbone.DevelopmentKit.Identity.ValueObjects; +using Backbone.Modules.Messages.Domain.Entities; +using Backbone.Modules.Messages.Domain.Ids; +using Backbone.Modules.Messages.Infrastructure.Persistence.Database.ValueConverters; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable enable + +namespace Backbone.Modules.Messages.Infrastructure.CompiledModels.SqlServer +{ + internal partial class RecipientInformationEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType? baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Backbone.Modules.Messages.Domain.Entities.RecipientInformation", + typeof(RecipientInformation), + baseEntityType); + + var address = runtimeEntityType.AddProperty( + "Address", + typeof(IdentityAddress), + propertyInfo: typeof(RecipientInformation).GetProperty("Address", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(RecipientInformation).GetField("
k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 36, + unicode: false, + valueConverter: new IdentityAddressValueConverter()); + address.AddAnnotation("Relational:IsFixedLength", true); + address.AddAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.None); + + var messageId = runtimeEntityType.AddProperty( + "MessageId", + typeof(MessageId), + propertyInfo: typeof(RecipientInformation).GetProperty("MessageId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(RecipientInformation).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 20, + unicode: false, + valueConverter: new MessageIdEntityFrameworkValueConverter()); + messageId.AddAnnotation("Relational:IsFixedLength", true); + messageId.AddAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.None); + + var encryptedKey = runtimeEntityType.AddProperty( + "EncryptedKey", + typeof(byte[]), + propertyInfo: typeof(RecipientInformation).GetProperty("EncryptedKey", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(RecipientInformation).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + encryptedKey.AddAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.None); + + var receivedAt = runtimeEntityType.AddProperty( + "ReceivedAt", + typeof(DateTime?), + propertyInfo: typeof(RecipientInformation).GetProperty("ReceivedAt", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(RecipientInformation).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + valueConverter: new NullableDateTimeValueConverter()); + receivedAt.AddAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.None); + + var receivedByDevice = runtimeEntityType.AddProperty( + "ReceivedByDevice", + typeof(DeviceId), + propertyInfo: typeof(RecipientInformation).GetProperty("ReceivedByDevice", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(RecipientInformation).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + nullable: true, + maxLength: 20, + unicode: false, + valueConverter: new DeviceIdValueConverter()); + receivedByDevice.AddAnnotation("Relational:IsFixedLength", true); + receivedByDevice.AddAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.None); + + var relationshipId = runtimeEntityType.AddProperty( + "RelationshipId", + typeof(RelationshipId), + propertyInfo: typeof(RecipientInformation).GetProperty("RelationshipId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(RecipientInformation).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 20, + unicode: false, + valueConverter: new RelationshipIdEntityFrameworkValueConverter()); + relationshipId.AddAnnotation("Relational:IsFixedLength", true); + relationshipId.AddAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.None); + + var key = runtimeEntityType.AddKey( + new[] { address, messageId }); + runtimeEntityType.SetPrimaryKey(key); + + var index = runtimeEntityType.AddIndex( + new[] { messageId }); + + var index0 = runtimeEntityType.AddIndex( + new[] { receivedAt }); + + var index1 = runtimeEntityType.AddIndex( + new[] { relationshipId }); + + return runtimeEntityType; + } + + public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("MessageId")! }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id")! })!, + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + var recipients = principalEntityType.AddNavigation("Recipients", + runtimeForeignKey, + onDependent: false, + typeof(IReadOnlyCollection), + propertyInfo: typeof(Message).GetProperty("Recipients", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Message).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + + return runtimeForeignKey; + } + + public static RuntimeForeignKey CreateForeignKey2(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType) + { + var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("RelationshipId")! }, + principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id")! })!, + principalEntityType, + deleteBehavior: DeleteBehavior.Cascade, + required: true); + + return runtimeForeignKey; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", null); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "RecipientInformation"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/Modules/Messages/src/Messages.Infrastructure/CompiledModels/SqlServer/RelationshipEntityType.cs b/Modules/Messages/src/Messages.Infrastructure/CompiledModels/SqlServer/RelationshipEntityType.cs index 6a76a40027..9ca4564151 100644 --- a/Modules/Messages/src/Messages.Infrastructure/CompiledModels/SqlServer/RelationshipEntityType.cs +++ b/Modules/Messages/src/Messages.Infrastructure/CompiledModels/SqlServer/RelationshipEntityType.cs @@ -1,95 +1,95 @@ -// -using System; -using System.Reflection; -using Backbone.BuildingBlocks.Infrastructure.Persistence.Database.ValueConverters; -using Backbone.DevelopmentKit.Identity.ValueObjects; -using Backbone.Modules.Messages.Domain.Entities; -using Backbone.Modules.Messages.Domain.Ids; -using Backbone.Modules.Messages.Infrastructure.Persistence.Database.ValueConverters; -using Microsoft.EntityFrameworkCore.Metadata; - -#pragma warning disable 219, 612, 618 -#nullable enable - -namespace Backbone.Modules.Messages.Infrastructure.CompiledModels.SqlServer -{ - internal partial class RelationshipEntityType - { - public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType? baseEntityType = null) - { - var runtimeEntityType = model.AddEntityType( - "Backbone.Modules.Messages.Domain.Entities.Relationship", - typeof(Relationship), - baseEntityType); - - var id = runtimeEntityType.AddProperty( - "Id", - typeof(RelationshipId), - propertyInfo: typeof(Relationship).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), - fieldInfo: typeof(Relationship).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), - afterSaveBehavior: PropertySaveBehavior.Throw, - maxLength: 20, - unicode: false, - valueConverter: new RelationshipIdEntityFrameworkValueConverter()); - id.AddAnnotation("Relational:IsFixedLength", true); - id.AddAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.None); - - var createdAt = runtimeEntityType.AddProperty( - "CreatedAt", - typeof(DateTime), - propertyInfo: typeof(Relationship).GetProperty("CreatedAt", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), - fieldInfo: typeof(Relationship).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), - valueConverter: new DateTimeValueConverter()); - createdAt.AddAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.None); - - var from = runtimeEntityType.AddProperty( - "From", - typeof(IdentityAddress), - propertyInfo: typeof(Relationship).GetProperty("From", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), - fieldInfo: typeof(Relationship).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), - maxLength: 36, - unicode: false, - valueConverter: new IdentityAddressValueConverter()); - from.AddAnnotation("Relational:IsFixedLength", true); - from.AddAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.None); - - var status = runtimeEntityType.AddProperty( - "Status", - typeof(RelationshipStatus), - propertyInfo: typeof(Relationship).GetProperty("Status", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), - fieldInfo: typeof(Relationship).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); - status.AddAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.None); - - var to = runtimeEntityType.AddProperty( - "To", - typeof(IdentityAddress), - propertyInfo: typeof(Relationship).GetProperty("To", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), - fieldInfo: typeof(Relationship).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), - maxLength: 36, - unicode: false, - valueConverter: new IdentityAddressValueConverter()); - to.AddAnnotation("Relational:IsFixedLength", true); - to.AddAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.None); - - var key = runtimeEntityType.AddKey( - new[] { id }); - runtimeEntityType.SetPrimaryKey(key); - - return runtimeEntityType; - } - - public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) - { - runtimeEntityType.AddAnnotation("Relational:FunctionName", null); - runtimeEntityType.AddAnnotation("Relational:Schema", "Relationships"); - runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); - runtimeEntityType.AddAnnotation("Relational:TableName", "Relationships"); - runtimeEntityType.AddAnnotation("Relational:ViewName", null); - runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); - - Customize(runtimeEntityType); - } - - static partial void Customize(RuntimeEntityType runtimeEntityType); - } -} +// +using System; +using System.Reflection; +using Backbone.BuildingBlocks.Infrastructure.Persistence.Database.ValueConverters; +using Backbone.DevelopmentKit.Identity.ValueObjects; +using Backbone.Modules.Messages.Domain.Entities; +using Backbone.Modules.Messages.Domain.Ids; +using Backbone.Modules.Messages.Infrastructure.Persistence.Database.ValueConverters; +using Microsoft.EntityFrameworkCore.Metadata; + +#pragma warning disable 219, 612, 618 +#nullable enable + +namespace Backbone.Modules.Messages.Infrastructure.CompiledModels.SqlServer +{ + internal partial class RelationshipEntityType + { + public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType? baseEntityType = null) + { + var runtimeEntityType = model.AddEntityType( + "Backbone.Modules.Messages.Domain.Entities.Relationship", + typeof(Relationship), + baseEntityType); + + var id = runtimeEntityType.AddProperty( + "Id", + typeof(RelationshipId), + propertyInfo: typeof(Relationship).GetProperty("Id", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Relationship).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + afterSaveBehavior: PropertySaveBehavior.Throw, + maxLength: 20, + unicode: false, + valueConverter: new RelationshipIdEntityFrameworkValueConverter()); + id.AddAnnotation("Relational:IsFixedLength", true); + id.AddAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.None); + + var createdAt = runtimeEntityType.AddProperty( + "CreatedAt", + typeof(DateTime), + propertyInfo: typeof(Relationship).GetProperty("CreatedAt", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Relationship).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + valueConverter: new DateTimeValueConverter()); + createdAt.AddAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.None); + + var from = runtimeEntityType.AddProperty( + "From", + typeof(IdentityAddress), + propertyInfo: typeof(Relationship).GetProperty("From", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Relationship).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 36, + unicode: false, + valueConverter: new IdentityAddressValueConverter()); + from.AddAnnotation("Relational:IsFixedLength", true); + from.AddAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.None); + + var status = runtimeEntityType.AddProperty( + "Status", + typeof(RelationshipStatus), + propertyInfo: typeof(Relationship).GetProperty("Status", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Relationship).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)); + status.AddAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.None); + + var to = runtimeEntityType.AddProperty( + "To", + typeof(IdentityAddress), + propertyInfo: typeof(Relationship).GetProperty("To", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly), + fieldInfo: typeof(Relationship).GetField("k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly), + maxLength: 36, + unicode: false, + valueConverter: new IdentityAddressValueConverter()); + to.AddAnnotation("Relational:IsFixedLength", true); + to.AddAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.None); + + var key = runtimeEntityType.AddKey( + new[] { id }); + runtimeEntityType.SetPrimaryKey(key); + + return runtimeEntityType; + } + + public static void CreateAnnotations(RuntimeEntityType runtimeEntityType) + { + runtimeEntityType.AddAnnotation("Relational:FunctionName", null); + runtimeEntityType.AddAnnotation("Relational:Schema", "Relationships"); + runtimeEntityType.AddAnnotation("Relational:SqlQuery", null); + runtimeEntityType.AddAnnotation("Relational:TableName", "Relationships"); + runtimeEntityType.AddAnnotation("Relational:ViewName", null); + runtimeEntityType.AddAnnotation("Relational:ViewSchema", null); + + Customize(runtimeEntityType); + } + + static partial void Customize(RuntimeEntityType runtimeEntityType); + } +} diff --git a/Modules/Messages/src/Messages.Infrastructure/Persistence/Database/EntityConfigurations/MessageEntityTypeConfiguration.cs b/Modules/Messages/src/Messages.Infrastructure/Persistence/Database/EntityConfigurations/MessageEntityTypeConfiguration.cs index f07452fe42..9c63f1fc13 100644 --- a/Modules/Messages/src/Messages.Infrastructure/Persistence/Database/EntityConfigurations/MessageEntityTypeConfiguration.cs +++ b/Modules/Messages/src/Messages.Infrastructure/Persistence/Database/EntityConfigurations/MessageEntityTypeConfiguration.cs @@ -14,9 +14,6 @@ public void Configure(EntityTypeBuilder builder) builder.Property(x => x.CreatedByDevice); - builder - .HasKey(m => m.Id); - - builder.Ignore(a => a.Body); + builder.HasKey(m => m.Id); } } diff --git a/Modules/Messages/src/Messages.Infrastructure/Persistence/Database/Repository/MessagesRepository.cs b/Modules/Messages/src/Messages.Infrastructure/Persistence/Database/Repository/MessagesRepository.cs index a3b73e5ea5..6b9e9d7991 100644 --- a/Modules/Messages/src/Messages.Infrastructure/Persistence/Database/Repository/MessagesRepository.cs +++ b/Modules/Messages/src/Messages.Infrastructure/Persistence/Database/Repository/MessagesRepository.cs @@ -1,15 +1,12 @@ -using Backbone.BuildingBlocks.Application.Abstractions.Infrastructure.Persistence.BlobStorage; -using Backbone.BuildingBlocks.Application.Abstractions.Infrastructure.Persistence.Database; +using Backbone.BuildingBlocks.Application.Abstractions.Infrastructure.Persistence.Database; using Backbone.BuildingBlocks.Application.Extensions; using Backbone.BuildingBlocks.Application.Pagination; using Backbone.DevelopmentKit.Identity.ValueObjects; -using Backbone.Modules.Messages.Application.Infrastructure.Persistence; using Backbone.Modules.Messages.Application.Infrastructure.Persistence.Repository; using Backbone.Modules.Messages.Domain.Entities; using Backbone.Modules.Messages.Domain.Ids; using Backbone.Modules.Messages.Infrastructure.Persistence.Database.QueryableExtensions; using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Options; namespace Backbone.Modules.Messages.Infrastructure.Persistence.Database.Repository; public class MessagesRepository : IMessagesRepository @@ -17,16 +14,12 @@ public class MessagesRepository : IMessagesRepository private readonly DbSet _messages; private readonly IQueryable _readOnlyMessages; private readonly MessagesDbContext _dbContext; - private readonly IBlobStorage _blobStorage; - private readonly BlobOptions _blobOptions; - public MessagesRepository(MessagesDbContext dbContext, IBlobStorage blobStorage, IOptions blobOptions) + public MessagesRepository(MessagesDbContext dbContext) { _messages = dbContext.Messages; _readOnlyMessages = dbContext.Messages.AsNoTracking(); _dbContext = dbContext; - _blobStorage = blobStorage; - _blobOptions = blobOptions.Value; } public async Task Find(MessageId id, IdentityAddress address, CancellationToken cancellationToken, bool track = false, bool fillBody = true) @@ -36,19 +29,12 @@ public async Task Find(MessageId id, IdentityAddress address, Cancellat .WithSenderOrRecipient(address) .FirstWithId(id, cancellationToken); - if (fillBody) - { - await FillBody(message); - } - return message; } public async Task Add(Message message, CancellationToken cancellationToken) { - _blobStorage.Add(_blobOptions.RootFolder, message.Id, message.Body); await _messages.AddAsync(message, cancellationToken); - await _blobStorage.SaveAsync(); await _dbContext.SaveChangesAsync(cancellationToken); } @@ -73,16 +59,9 @@ public async Task> FindMessagesWithIds(IEnumerable d.CreatedAt, paginationFilter, cancellationToken); - await Task.WhenAll(messages.ItemsOnPage.Select(FillBody).ToArray()); - return messages; } - private async Task FillBody(Message message) - { - message.LoadBody(await _blobStorage.FindAsync(_blobOptions.RootFolder, message.Id)); - } - public async Task Update(Message message) { _messages.Update(message); diff --git a/Modules/Messages/src/Messages.Infrastructure/Persistence/IServiceCollectionExtensions.cs b/Modules/Messages/src/Messages.Infrastructure/Persistence/IServiceCollectionExtensions.cs index 13c1f79284..3993a8f542 100644 --- a/Modules/Messages/src/Messages.Infrastructure/Persistence/IServiceCollectionExtensions.cs +++ b/Modules/Messages/src/Messages.Infrastructure/Persistence/IServiceCollectionExtensions.cs @@ -20,9 +20,13 @@ public static void AddPersistence(this IServiceCollection services, Action(blobOptions => - blobOptions.RootFolder = options.BlobStorageOptions.Container); - services.AddBlobStorage(options.BlobStorageOptions); + + if (options.BlobStorageOptions != null) + { + services.Configure(blobOptions => + blobOptions.RootFolder = options.BlobStorageOptions.Container); + services.AddBlobStorage(options.BlobStorageOptions); + } services.AddTransient(); services.AddTransient(); @@ -32,5 +36,5 @@ public static void AddPersistence(this IServiceCollection services, PersistenceO public class PersistenceOptions { public DbOptions DbOptions { get; set; } = new(); - public BlobStorageOptions BlobStorageOptions { get; set; } = new(); + public BlobStorageOptions? BlobStorageOptions { get; set; } } diff --git a/Modules/Messages/test/Messages.Application.Tests/Messages.Application.Tests.csproj b/Modules/Messages/test/Messages.Application.Tests/Messages.Application.Tests.csproj index a735b7d1c7..3d113eb28f 100644 --- a/Modules/Messages/test/Messages.Application.Tests/Messages.Application.Tests.csproj +++ b/Modules/Messages/test/Messages.Application.Tests/Messages.Application.Tests.csproj @@ -1,20 +1,23 @@ - + - - false - + + false + - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + - - - + + + + diff --git a/docker-compose/docker-compose.yml b/docker-compose/docker-compose.yml index 86d1b73516..bb28c18211 100644 --- a/docker-compose/docker-compose.yml +++ b/docker-compose/docker-compose.yml @@ -11,9 +11,7 @@ services: - ASPNETCORE_URLS=http://0.0.0.0:80 - Modules__Files__Infrastructure__BlobStorage__ConnectionInfo=${ENMESHED_BLOB_STORAGE_CONNECTION_STRING} # set this environment variable on your local system to an appropriate value (DefaultEndpointsProtocol=https;AccountName=;AccountKey=;EndpointSuffix=core.windows.net) - - - Modules__Messages__Infrastructure__BlobStorage__ConnectionInfo=${ENMESHED_BLOB_STORAGE_CONNECTION_STRING} # set this environment variable on your local system to an appropriate value (DefaultEndpointsProtocol=https;AccountName=;AccountKey=;EndpointSuffix=core.windows.net) - + - Modules__Relationships__Infrastructure__BlobStorage__ConnectionInfo=${ENMESHED_BLOB_STORAGE_CONNECTION_STRING} # set this environment variable on your local system to an appropriate value (DefaultEndpointsProtocol=https;AccountName=;AccountKey=;EndpointSuffix=core.windows.net) - Modules__Synchronization__Infrastructure__BlobStorage__ConnectionInfo=${ENMESHED_BLOB_STORAGE_CONNECTION_STRING} # set this environment variable on your local system to an appropriate value (DefaultEndpointsProtocol=https;AccountName=;AccountKey=;EndpointSuffix=core.windows.net)