From 0980d423319b661c1371e45443d1bfbfbbdd9e70 Mon Sep 17 00:00:00 2001 From: jvandaal Date: Fri, 17 May 2024 16:30:28 +0200 Subject: [PATCH] fix: add legacy parcel address count ef migration --- ..._AddCountOnParcelDetailAddress.Designer.cs | 388 ++++++++++++++++++ ...517142953_AddCountOnParcelDetailAddress.cs | 119 ++++++ .../Migrations/LegacyContextModelSnapshot.cs | 100 ++++- 3 files changed, 603 insertions(+), 4 deletions(-) create mode 100644 src/ParcelRegistry.Projections.Legacy/Migrations/20240517142953_AddCountOnParcelDetailAddress.Designer.cs create mode 100644 src/ParcelRegistry.Projections.Legacy/Migrations/20240517142953_AddCountOnParcelDetailAddress.cs diff --git a/src/ParcelRegistry.Projections.Legacy/Migrations/20240517142953_AddCountOnParcelDetailAddress.Designer.cs b/src/ParcelRegistry.Projections.Legacy/Migrations/20240517142953_AddCountOnParcelDetailAddress.Designer.cs new file mode 100644 index 00000000..1387c5bf --- /dev/null +++ b/src/ParcelRegistry.Projections.Legacy/Migrations/20240517142953_AddCountOnParcelDetailAddress.Designer.cs @@ -0,0 +1,388 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using ParcelRegistry.Projections.Legacy; + +#nullable disable + +namespace ParcelRegistry.Projections.Legacy.Migrations +{ + [DbContext(typeof(LegacyContext))] + [Migration("20240517142953_AddCountOnParcelDetailAddress")] + partial class AddCountOnParcelDetailAddress + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.3") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("Be.Vlaanderen.Basisregisters.ProjectionHandling.Runner.ProjectionStates.ProjectionStateItem", b => + { + b.Property("Name") + .HasColumnType("nvarchar(450)"); + + b.Property("DesiredState") + .HasColumnType("nvarchar(max)"); + + b.Property("DesiredStateChangedAt") + .HasColumnType("datetimeoffset"); + + b.Property("ErrorMessage") + .HasColumnType("nvarchar(max)"); + + b.Property("Position") + .HasColumnType("bigint"); + + b.HasKey("Name"); + + b.ToTable("ProjectionStates", "ParcelRegistryLegacy"); + }); + + modelBuilder.Entity("ParcelRegistry.Projections.Legacy.ParcelDetail.ParcelDetail", b => + { + b.Property("ParcelId") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("PersistentLocalId") + .HasColumnType("nvarchar(450)"); + + b.Property("Removed") + .HasColumnType("bit"); + + b.Property("Status") + .HasColumnType("nvarchar(450)") + .HasColumnName("Status"); + + b.Property("VersionTimestampAsDateTimeOffset") + .HasColumnType("datetimeoffset") + .HasColumnName("VersionTimestamp"); + + b.HasKey("ParcelId"); + + SqlServerKeyBuilderExtensions.IsClustered(b.HasKey("ParcelId"), false); + + b.HasIndex("PersistentLocalId") + .IsUnique() + .HasDatabaseName("IX_ParcelDetails_PersistentLocalId_1") + .HasFilter("([PersistentLocalId] IS NOT NULL)"); + + SqlServerIndexBuilderExtensions.IsClustered(b.HasIndex("PersistentLocalId"), false); + + b.HasIndex("Removed"); + + b.HasIndex("Status"); + + b.ToTable("ParcelDetails", "ParcelRegistryLegacy"); + }); + + modelBuilder.Entity("ParcelRegistry.Projections.Legacy.ParcelDetail.ParcelDetailAddress", b => + { + b.Property("ParcelId") + .HasColumnType("uniqueidentifier"); + + b.Property("AddressId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("ParcelId", "AddressId"); + + SqlServerKeyBuilderExtensions.IsClustered(b.HasKey("ParcelId", "AddressId")); + + b.HasIndex("AddressId"); + + b.ToTable("ParcelAddresses", "ParcelRegistryLegacy"); + }); + + modelBuilder.Entity("ParcelRegistry.Projections.Legacy.ParcelDetail.ParcelDetailListViewCount", b => + { + b.Property("Count") + .HasColumnType("bigint"); + + b.ToTable((string)null); + + b.ToView("vw_ParcelDetailListCount", "ParcelRegistryLegacy"); + }); + + modelBuilder.Entity("ParcelRegistry.Projections.Legacy.ParcelDetailV2.ParcelDetailAddressV2", b => + { + b.Property("ParcelId") + .HasColumnType("uniqueidentifier"); + + b.Property("AddressPersistentLocalId") + .HasColumnType("int"); + + b.HasKey("ParcelId", "AddressPersistentLocalId"); + + SqlServerKeyBuilderExtensions.IsClustered(b.HasKey("ParcelId", "AddressPersistentLocalId")); + + b.HasIndex("AddressPersistentLocalId"); + + b.ToTable("ParcelAddressesV2", "ParcelRegistryLegacy"); + }); + + modelBuilder.Entity("ParcelRegistry.Projections.Legacy.ParcelDetailV2.ParcelDetailV2", b => + { + b.Property("ParcelId") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("CaPaKey") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.Property("Gml") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("GmlType") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("LastEventHash") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Removed") + .HasColumnType("bit"); + + b.Property("StatusAsString") + .IsRequired() + .HasMaxLength(450) + .HasColumnType("nvarchar(450)") + .HasColumnName("Status"); + + b.Property("VersionTimestampAsDateTimeOffset") + .HasColumnType("datetimeoffset") + .HasColumnName("VersionTimestamp"); + + b.HasKey("ParcelId"); + + SqlServerKeyBuilderExtensions.IsClustered(b.HasKey("ParcelId"), false); + + b.HasAlternateKey("CaPaKey"); + + b.HasIndex("CaPaKey"); + + SqlServerIndexBuilderExtensions.IsClustered(b.HasIndex("CaPaKey")); + + b.HasIndex("Removed"); + + SqlServerIndexBuilderExtensions.IncludeProperties(b.HasIndex("Removed"), new[] { "CaPaKey", "StatusAsString", "VersionTimestampAsDateTimeOffset" }); + + b.HasIndex("StatusAsString"); + + b.ToTable("ParcelDetailsV2", "ParcelRegistryLegacy"); + }); + + modelBuilder.Entity("ParcelRegistry.Projections.Legacy.ParcelDetailV2.ParcelDetailV2ListViewCount", b => + { + b.Property("Count") + .HasColumnType("bigint"); + + b.ToTable((string)null); + + b.ToView("vw_ParcelDetailV2ListCount", "ParcelRegistryLegacy"); + }); + + modelBuilder.Entity("ParcelRegistry.Projections.Legacy.ParcelDetailWithCountV2.ParcelDetailAddressV2", b => + { + b.Property("ParcelId") + .HasColumnType("uniqueidentifier"); + + b.Property("AddressPersistentLocalId") + .HasColumnType("int"); + + b.Property("Count") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasDefaultValue(1); + + b.HasKey("ParcelId", "AddressPersistentLocalId"); + + SqlServerKeyBuilderExtensions.IsClustered(b.HasKey("ParcelId", "AddressPersistentLocalId")); + + b.HasIndex("AddressPersistentLocalId"); + + b.ToTable("ParcelAddressesWithCountV2", "ParcelRegistryLegacy"); + }); + + modelBuilder.Entity("ParcelRegistry.Projections.Legacy.ParcelDetailWithCountV2.ParcelDetailV2", b => + { + b.Property("ParcelId") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("CaPaKey") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.Property("Gml") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("GmlType") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("LastEventHash") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Removed") + .HasColumnType("bit"); + + b.Property("StatusAsString") + .IsRequired() + .HasMaxLength(450) + .HasColumnType("nvarchar(450)") + .HasColumnName("Status"); + + b.Property("VersionTimestampAsDateTimeOffset") + .HasColumnType("datetimeoffset") + .HasColumnName("VersionTimestamp"); + + b.HasKey("ParcelId"); + + SqlServerKeyBuilderExtensions.IsClustered(b.HasKey("ParcelId"), false); + + b.HasAlternateKey("CaPaKey"); + + b.HasIndex("CaPaKey"); + + SqlServerIndexBuilderExtensions.IsClustered(b.HasIndex("CaPaKey")); + + b.HasIndex("Removed"); + + SqlServerIndexBuilderExtensions.IncludeProperties(b.HasIndex("Removed"), new[] { "CaPaKey", "StatusAsString", "VersionTimestampAsDateTimeOffset" }); + + b.HasIndex("StatusAsString"); + + b.ToTable("ParcelDetailsWithCountV2", "ParcelRegistryLegacy"); + }); + + modelBuilder.Entity("ParcelRegistry.Projections.Legacy.ParcelSyndication.ParcelSyndicationItem", b => + { + b.Property("Position") + .HasColumnType("bigint"); + + b.Property("AddressPersistentLocalIdsAsString") + .HasColumnType("nvarchar(max)") + .HasColumnName("AddressPersistentLocalIds"); + + b.Property("AddressesAsString") + .HasColumnType("nvarchar(max)") + .HasColumnName("AddressIds"); + + b.Property("Application") + .HasColumnType("int"); + + b.Property("CaPaKey") + .HasColumnType("nvarchar(max)"); + + b.Property("ChangeType") + .HasColumnType("nvarchar(max)"); + + b.Property("EventDataAsXml") + .HasColumnType("nvarchar(max)"); + + b.Property("ExtendedWkbGeometry") + .HasColumnType("varbinary(max)"); + + b.Property("LastChangedOnAsDateTimeOffset") + .HasColumnType("datetimeoffset") + .HasColumnName("LastChangedOn"); + + b.Property("Modification") + .HasColumnType("int"); + + b.Property("Operator") + .HasColumnType("nvarchar(max)"); + + b.Property("Organisation") + .HasColumnType("int"); + + b.Property("ParcelId") + .IsRequired() + .HasColumnType("uniqueidentifier"); + + b.Property("Reason") + .HasColumnType("nvarchar(max)"); + + b.Property("RecordCreatedAtAsDateTimeOffset") + .HasColumnType("datetimeoffset") + .HasColumnName("RecordCreatedAt"); + + b.Property("StatusAsString") + .HasColumnType("nvarchar(max)") + .HasColumnName("Status"); + + b.Property("SyndicationItemCreatedAt") + .HasColumnType("datetimeoffset"); + + b.HasKey("Position"); + + SqlServerKeyBuilderExtensions.IsClustered(b.HasKey("Position")); + + b.HasIndex("ParcelId"); + + b.HasIndex("Position") + .HasDatabaseName("CI_ParcelSyndication_Position") + .HasAnnotation("SqlServer:ColumnStoreIndex", ""); + + b.ToTable("ParcelSyndication", "ParcelRegistryLegacy"); + }); + + modelBuilder.Entity("ParcelRegistry.Projections.Legacy.ParcelDetail.ParcelDetailAddress", b => + { + b.HasOne("ParcelRegistry.Projections.Legacy.ParcelDetail.ParcelDetail", null) + .WithMany("Addresses") + .HasForeignKey("ParcelId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ParcelRegistry.Projections.Legacy.ParcelDetailV2.ParcelDetailAddressV2", b => + { + b.HasOne("ParcelRegistry.Projections.Legacy.ParcelDetailV2.ParcelDetailV2", null) + .WithMany("Addresses") + .HasForeignKey("ParcelId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ParcelRegistry.Projections.Legacy.ParcelDetailWithCountV2.ParcelDetailAddressV2", b => + { + b.HasOne("ParcelRegistry.Projections.Legacy.ParcelDetailWithCountV2.ParcelDetailV2", null) + .WithMany("Addresses") + .HasForeignKey("ParcelId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ParcelRegistry.Projections.Legacy.ParcelDetail.ParcelDetail", b => + { + b.Navigation("Addresses"); + }); + + modelBuilder.Entity("ParcelRegistry.Projections.Legacy.ParcelDetailV2.ParcelDetailV2", b => + { + b.Navigation("Addresses"); + }); + + modelBuilder.Entity("ParcelRegistry.Projections.Legacy.ParcelDetailWithCountV2.ParcelDetailV2", b => + { + b.Navigation("Addresses"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/ParcelRegistry.Projections.Legacy/Migrations/20240517142953_AddCountOnParcelDetailAddress.cs b/src/ParcelRegistry.Projections.Legacy/Migrations/20240517142953_AddCountOnParcelDetailAddress.cs new file mode 100644 index 00000000..61ad4e54 --- /dev/null +++ b/src/ParcelRegistry.Projections.Legacy/Migrations/20240517142953_AddCountOnParcelDetailAddress.cs @@ -0,0 +1,119 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace ParcelRegistry.Projections.Legacy.Migrations +{ + /// + public partial class AddCountOnParcelDetailAddress : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropPrimaryKey( + name: "PK_ProjectionStates", + schema: "ParcelRegistryLegacy", + table: "ProjectionStates"); + + migrationBuilder.AddPrimaryKey( + name: "PK_ProjectionStates", + schema: "ParcelRegistryLegacy", + table: "ProjectionStates", + column: "Name"); + + migrationBuilder.CreateTable( + name: "ParcelDetailsWithCountV2", + schema: "ParcelRegistryLegacy", + columns: table => new + { + ParcelId = table.Column(type: "uniqueidentifier", nullable: false), + CaPaKey = table.Column(type: "nvarchar(450)", nullable: false), + Status = table.Column(type: "nvarchar(450)", maxLength: 450, nullable: false), + Gml = table.Column(type: "nvarchar(max)", nullable: false), + GmlType = table.Column(type: "nvarchar(max)", nullable: false), + Removed = table.Column(type: "bit", nullable: false), + LastEventHash = table.Column(type: "nvarchar(max)", nullable: false), + VersionTimestamp = table.Column(type: "datetimeoffset", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_ParcelDetailsWithCountV2", x => x.ParcelId) + .Annotation("SqlServer:Clustered", false); + table.UniqueConstraint("AK_ParcelDetailsWithCountV2_CaPaKey", x => x.CaPaKey); + }); + + migrationBuilder.CreateTable( + name: "ParcelAddressesWithCountV2", + schema: "ParcelRegistryLegacy", + columns: table => new + { + ParcelId = table.Column(type: "uniqueidentifier", nullable: false), + AddressPersistentLocalId = table.Column(type: "int", nullable: false), + Count = table.Column(type: "int", nullable: false, defaultValue: 1) + }, + constraints: table => + { + table.PrimaryKey("PK_ParcelAddressesWithCountV2", x => new { x.ParcelId, x.AddressPersistentLocalId }) + .Annotation("SqlServer:Clustered", true); + table.ForeignKey( + name: "FK_ParcelAddressesWithCountV2_ParcelDetailsWithCountV2_ParcelId", + column: x => x.ParcelId, + principalSchema: "ParcelRegistryLegacy", + principalTable: "ParcelDetailsWithCountV2", + principalColumn: "ParcelId", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_ParcelAddressesWithCountV2_AddressPersistentLocalId", + schema: "ParcelRegistryLegacy", + table: "ParcelAddressesWithCountV2", + column: "AddressPersistentLocalId"); + + migrationBuilder.CreateIndex( + name: "IX_ParcelDetailsWithCountV2_CaPaKey", + schema: "ParcelRegistryLegacy", + table: "ParcelDetailsWithCountV2", + column: "CaPaKey") + .Annotation("SqlServer:Clustered", true); + + migrationBuilder.CreateIndex( + name: "IX_ParcelDetailsWithCountV2_Removed", + schema: "ParcelRegistryLegacy", + table: "ParcelDetailsWithCountV2", + column: "Removed") + .Annotation("SqlServer:Include", new[] { "CaPaKey", "Status", "VersionTimestamp" }); + + migrationBuilder.CreateIndex( + name: "IX_ParcelDetailsWithCountV2_Status", + schema: "ParcelRegistryLegacy", + table: "ParcelDetailsWithCountV2", + column: "Status"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "ParcelAddressesWithCountV2", + schema: "ParcelRegistryLegacy"); + + migrationBuilder.DropTable( + name: "ParcelDetailsWithCountV2", + schema: "ParcelRegistryLegacy"); + + migrationBuilder.DropPrimaryKey( + name: "PK_ProjectionStates", + schema: "ParcelRegistryLegacy", + table: "ProjectionStates"); + + migrationBuilder.AddPrimaryKey( + name: "PK_ProjectionStates", + schema: "ParcelRegistryLegacy", + table: "ProjectionStates", + column: "Name") + .Annotation("SqlServer:Clustered", true); + } + } +} diff --git a/src/ParcelRegistry.Projections.Legacy/Migrations/LegacyContextModelSnapshot.cs b/src/ParcelRegistry.Projections.Legacy/Migrations/LegacyContextModelSnapshot.cs index baf62bf0..5cee4a4d 100644 --- a/src/ParcelRegistry.Projections.Legacy/Migrations/LegacyContextModelSnapshot.cs +++ b/src/ParcelRegistry.Projections.Legacy/Migrations/LegacyContextModelSnapshot.cs @@ -17,10 +17,10 @@ protected override void BuildModel(ModelBuilder modelBuilder) { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "6.0.3") + .HasAnnotation("ProductVersion", "8.0.3") .HasAnnotation("Relational:MaxIdentifierLength", 128); - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1); + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); modelBuilder.Entity("Be.Vlaanderen.Basisregisters.ProjectionHandling.Runner.ProjectionStates.ProjectionStateItem", b => { @@ -41,8 +41,6 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasKey("Name"); - SqlServerKeyBuilderExtensions.IsClustered(b.HasKey("Name")); - b.ToTable("ProjectionStates", "ParcelRegistryLegacy"); }); @@ -106,6 +104,8 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Property("Count") .HasColumnType("bigint"); + b.ToTable((string)null); + b.ToView("vw_ParcelDetailListCount", "ParcelRegistryLegacy"); }); @@ -185,9 +185,87 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Property("Count") .HasColumnType("bigint"); + b.ToTable((string)null); + b.ToView("vw_ParcelDetailV2ListCount", "ParcelRegistryLegacy"); }); + modelBuilder.Entity("ParcelRegistry.Projections.Legacy.ParcelDetailWithCountV2.ParcelDetailAddressV2", b => + { + b.Property("ParcelId") + .HasColumnType("uniqueidentifier"); + + b.Property("AddressPersistentLocalId") + .HasColumnType("int"); + + b.Property("Count") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasDefaultValue(1); + + b.HasKey("ParcelId", "AddressPersistentLocalId"); + + SqlServerKeyBuilderExtensions.IsClustered(b.HasKey("ParcelId", "AddressPersistentLocalId")); + + b.HasIndex("AddressPersistentLocalId"); + + b.ToTable("ParcelAddressesWithCountV2", "ParcelRegistryLegacy"); + }); + + modelBuilder.Entity("ParcelRegistry.Projections.Legacy.ParcelDetailWithCountV2.ParcelDetailV2", b => + { + b.Property("ParcelId") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("CaPaKey") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.Property("Gml") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("GmlType") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("LastEventHash") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Removed") + .HasColumnType("bit"); + + b.Property("StatusAsString") + .IsRequired() + .HasMaxLength(450) + .HasColumnType("nvarchar(450)") + .HasColumnName("Status"); + + b.Property("VersionTimestampAsDateTimeOffset") + .HasColumnType("datetimeoffset") + .HasColumnName("VersionTimestamp"); + + b.HasKey("ParcelId"); + + SqlServerKeyBuilderExtensions.IsClustered(b.HasKey("ParcelId"), false); + + b.HasAlternateKey("CaPaKey"); + + b.HasIndex("CaPaKey"); + + SqlServerIndexBuilderExtensions.IsClustered(b.HasIndex("CaPaKey")); + + b.HasIndex("Removed"); + + SqlServerIndexBuilderExtensions.IncludeProperties(b.HasIndex("Removed"), new[] { "CaPaKey", "StatusAsString", "VersionTimestampAsDateTimeOffset" }); + + b.HasIndex("StatusAsString"); + + b.ToTable("ParcelDetailsWithCountV2", "ParcelRegistryLegacy"); + }); + modelBuilder.Entity("ParcelRegistry.Projections.Legacy.ParcelSyndication.ParcelSyndicationItem", b => { b.Property("Position") @@ -278,6 +356,15 @@ protected override void BuildModel(ModelBuilder modelBuilder) .IsRequired(); }); + modelBuilder.Entity("ParcelRegistry.Projections.Legacy.ParcelDetailWithCountV2.ParcelDetailAddressV2", b => + { + b.HasOne("ParcelRegistry.Projections.Legacy.ParcelDetailWithCountV2.ParcelDetailV2", null) + .WithMany("Addresses") + .HasForeignKey("ParcelId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + modelBuilder.Entity("ParcelRegistry.Projections.Legacy.ParcelDetail.ParcelDetail", b => { b.Navigation("Addresses"); @@ -287,6 +374,11 @@ protected override void BuildModel(ModelBuilder modelBuilder) { b.Navigation("Addresses"); }); + + modelBuilder.Entity("ParcelRegistry.Projections.Legacy.ParcelDetailWithCountV2.ParcelDetailV2", b => + { + b.Navigation("Addresses"); + }); #pragma warning restore 612, 618 } }