From 40c20b7b97520023eeb78e1b0ba153059d2f2419 Mon Sep 17 00:00:00 2001 From: Arne Dumarey Date: Tue, 12 Nov 2024 09:31:57 +0100 Subject: [PATCH] fix(suspicious): recreate parcel related views to v2 tables --- .../Infrastructure/Schema.cs | 4 +- ...1112080757_RecreateParcelViews.Designer.cs | 472 ++++++++++++++++++ .../20241112080757_RecreateParcelViews.cs | 43 ++ .../SuspiciousCasesContextModelSnapshot.cs | 2 +- 4 files changed, 518 insertions(+), 3 deletions(-) create mode 100644 src/Basisregisters.IntegrationDb.SuspiciousCases/Migrations/20241112080757_RecreateParcelViews.Designer.cs create mode 100644 src/Basisregisters.IntegrationDb.SuspiciousCases/Migrations/20241112080757_RecreateParcelViews.cs diff --git a/src/Basisregisters.IntegrationDb.SuspiciousCases/Infrastructure/Schema.cs b/src/Basisregisters.IntegrationDb.SuspiciousCases/Infrastructure/Schema.cs index c6eca4b..5eacbde 100644 --- a/src/Basisregisters.IntegrationDb.SuspiciousCases/Infrastructure/Schema.cs +++ b/src/Basisregisters.IntegrationDb.SuspiciousCases/Infrastructure/Schema.cs @@ -7,8 +7,8 @@ public static class SchemaLatestItems public const string Building = "integration_building.building_latest_items"; public const string BuildingUnit = "integration_building.building_unit_latest_items"; public const string BuildingUnitAddresses = "integration_building.building_unit_addresses"; - public const string Parcel = "integration_parcel.parcel_latest_items"; - public const string ParcelAddresses = "integration_parcel.parcel_latest_item_addresses"; + public const string Parcel = "integration_parcel.parcel_latest_items_v2"; + public const string ParcelAddresses = "integration_parcel.parcel_latest_item_addresses_v2"; public const string Postal = "integration_postal.postal_latest_items"; public const string RoadSegment = "integration_road.road_segment_latest_items"; public const string Municipality = "integration_municipality.municipality_latest_items"; diff --git a/src/Basisregisters.IntegrationDb.SuspiciousCases/Migrations/20241112080757_RecreateParcelViews.Designer.cs b/src/Basisregisters.IntegrationDb.SuspiciousCases/Migrations/20241112080757_RecreateParcelViews.Designer.cs new file mode 100644 index 0000000..3ec9225 --- /dev/null +++ b/src/Basisregisters.IntegrationDb.SuspiciousCases/Migrations/20241112080757_RecreateParcelViews.Designer.cs @@ -0,0 +1,472 @@ +// +using Basisregisters.IntegrationDb.SuspiciousCases; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace Basisregisters.IntegrationDb.SuspiciousCases.Migrations +{ + [DbContext(typeof(SuspiciousCasesContext))] + [Migration("20241112080757_RecreateParcelViews")] + partial class RecreateParcelViews + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.3") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.HasPostgresExtension(modelBuilder, "postgis"); + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("Basisregisters.IntegrationDb.SuspiciousCases.Views.ActiveAddresLinkedToMultipleBuildingUnits", b => + { + b.Property("AddressPersistentLocalId") + .HasColumnType("integer") + .HasColumnName("address_persistent_local_id"); + + b.Property("Description") + .IsRequired() + .HasColumnType("text") + .HasColumnName("description"); + + b.Property("NisCode") + .IsRequired() + .HasColumnType("text") + .HasColumnName("nis_code"); + + b.Property("PersistentLocalId") + .IsRequired() + .HasColumnType("text") + .HasColumnName("persistent_local_id"); + + b.ToTable((string)null); + + b.ToView("view_active_address_linked_to_multiple_building_units", "integration_suspicious_cases"); + + b.ToSqlQuery("\r\n SELECT\r\n persistent_local_id,\r\n address_persistent_local_id,\r\n nis_code,\r\n description\r\n FROM integration_suspicious_cases.view_active_address_linked_to_multiple_building_units"); + }); + + modelBuilder.Entity("Basisregisters.IntegrationDb.SuspiciousCases.Views.ActiveAddressOutsideMunicipalityBounds", b => + { + b.Property("AddressPersistentLocalId") + .HasColumnType("integer") + .HasColumnName("address_persistent_local_id"); + + b.Property("Description") + .IsRequired() + .HasColumnType("text") + .HasColumnName("description"); + + b.Property("NisCode") + .IsRequired() + .HasColumnType("text") + .HasColumnName("nis_code"); + + b.Property("PersistentLocalId") + .IsRequired() + .HasColumnType("text") + .HasColumnName("persistent_local_id"); + + b.ToTable((string)null); + + b.ToView("view_active_address_outside_municipality_bounds", "integration_suspicious_cases"); + + b.ToSqlQuery("\r\n SELECT\r\n persistent_local_id,\r\n address_persistent_local_id,\r\n nis_code,\r\n description\r\n FROM integration_suspicious_cases.view_active_address_outside_municipality_bounds"); + }); + + modelBuilder.Entity("Basisregisters.IntegrationDb.SuspiciousCases.Views.ActiveBuildingUnitLinkedToMultipleAddresses", b => + { + b.Property("BuildingUnitPersistentLocalId") + .HasColumnType("integer") + .HasColumnName("building_unit_persistent_local_id"); + + b.Property("Description") + .IsRequired() + .HasColumnType("text") + .HasColumnName("description"); + + b.Property("NisCode") + .IsRequired() + .HasColumnType("text") + .HasColumnName("nis_code"); + + b.Property("PersistentLocalId") + .IsRequired() + .HasColumnType("text") + .HasColumnName("persistent_local_id"); + + b.ToTable((string)null); + + b.ToView("view_building_unit_linked_to_multiple_addresses", "integration_suspicious_cases"); + + b.ToSqlQuery("SELECT\r\n persistent_local_id,\r\n building_unit_persistent_local_id,\r\n nis_code,\r\n CONCAT('Gebouweenheid-', building_unit_persistent_local_id) as description\r\n FROM integration_suspicious_cases.view_building_unit_linked_to_multiple_addresses"); + }); + + modelBuilder.Entity("Basisregisters.IntegrationDb.SuspiciousCases.Views.AddressLongerThanTwoYearsProposed", b => + { + b.Property("AddressPersistentLocalId") + .HasColumnType("integer") + .HasColumnName("address_persistent_local_id"); + + b.Property("Description") + .IsRequired() + .HasColumnType("text") + .HasColumnName("description"); + + b.Property("NisCode") + .IsRequired() + .HasColumnType("text") + .HasColumnName("nis_code"); + + b.Property("PersistentLocalId") + .IsRequired() + .HasColumnType("text") + .HasColumnName("persistent_local_id"); + + b.ToTable((string)null); + + b.ToView("view_address_longer_than_two_years_proposed", "integration_suspicious_cases"); + + b.ToSqlQuery("\r\n SELECT\r\n persistent_local_id,\r\n address_persistent_local_id,\r\n nis_code,\r\n description\r\n FROM integration_suspicious_cases.view_address_longer_than_two_years_proposed"); + }); + + modelBuilder.Entity("Basisregisters.IntegrationDb.SuspiciousCases.Views.BuildingLongerThanTwoYearsPlanned", b => + { + b.Property("BuildingPersistentLocalId") + .HasColumnType("integer") + .HasColumnName("building_persistent_local_id"); + + b.Property("Description") + .IsRequired() + .HasColumnType("text") + .HasColumnName("description"); + + b.Property("NisCode") + .IsRequired() + .HasColumnType("text") + .HasColumnName("nis_code"); + + b.Property("PersistentLocalId") + .IsRequired() + .HasColumnType("text") + .HasColumnName("persistent_local_id"); + + b.ToTable((string)null); + + b.ToView("view_buildings_longer_than_two_years_planned", "integration_suspicious_cases"); + + b.ToSqlQuery("\r\n SELECT\r\n persistent_local_id,\r\n building_persistent_local_id,\r\n nis_code,\r\n CONCAT('Gebouw-', building_persistent_local_id) as description\r\n FROM integration_suspicious_cases.view_buildings_longer_than_two_years_planned"); + }); + + modelBuilder.Entity("Basisregisters.IntegrationDb.SuspiciousCases.Views.BuildingUnitsLongerThanTwoYearsPlanned", b => + { + b.Property("BuildingUnitPersistentLocalId") + .HasColumnType("integer") + .HasColumnName("building_unit_persistent_local_id"); + + b.Property("Description") + .IsRequired() + .HasColumnType("text") + .HasColumnName("description"); + + b.Property("NisCode") + .IsRequired() + .HasColumnType("text") + .HasColumnName("nis_code"); + + b.Property("PersistentLocalId") + .IsRequired() + .HasColumnType("text") + .HasColumnName("persistent_local_id"); + + b.ToTable((string)null); + + b.ToView("view_building_unit_longer_than_two_years_planned", "integration_suspicious_cases"); + + b.ToSqlQuery("\r\n SELECT\r\n persistent_local_id,\r\n building_unit_persistent_local_id,\r\n nis_code,\r\n CONCAT('Gebouweenheden-', building_unit_persistent_local_id) as description\r\n FROM integration_suspicious_cases.view_building_unit_longer_than_two_years_planned"); + }); + + modelBuilder.Entity("Basisregisters.IntegrationDb.SuspiciousCases.Views.CurrentAddressLinkedWithBuildingUnitButNotWithParcel", b => + { + b.Property("AddressPersistentLocalId") + .HasColumnType("integer") + .HasColumnName("address_persistent_local_id"); + + b.Property("Description") + .IsRequired() + .HasColumnType("text") + .HasColumnName("description"); + + b.Property("NisCode") + .IsRequired() + .HasColumnType("text") + .HasColumnName("nis_code"); + + b.Property("PersistentLocalId") + .IsRequired() + .HasColumnType("text") + .HasColumnName("persistent_local_id"); + + b.ToTable((string)null); + + b.ToView("view_current_address_linked_with_building_unit_but_not_with_parcel", "integration_suspicious_cases"); + + b.ToSqlQuery("SELECT\r\n persistent_local_id,\r\n address_persistent_local_id,\r\n nis_code,\r\n description\r\n FROM integration_suspicious_cases.view_current_address_linked_with_building_unit_but_not_with_parcel"); + }); + + modelBuilder.Entity("Basisregisters.IntegrationDb.SuspiciousCases.Views.CurrentAddressWithSpecificationDerivedFromBuildingUnitWithoutLinkedBuildingUnit", b => + { + b.Property("AddressPersistentLocalId") + .HasColumnType("integer") + .HasColumnName("address_persistent_local_id"); + + b.Property("Description") + .IsRequired() + .HasColumnType("text") + .HasColumnName("description"); + + b.Property("NisCode") + .IsRequired() + .HasColumnType("text") + .HasColumnName("nis_code"); + + b.Property("PersistentLocalId") + .IsRequired() + .HasColumnType("text") + .HasColumnName("persistent_local_id"); + + b.ToTable((string)null); + + b.ToView("view_current_address_with_specification_derived_from_building_unit_without_linked_building_unit", "integration_suspicious_cases"); + + b.ToSqlQuery("\r\n SELECT\r\n persistent_local_id,\r\n address_persistent_local_id,\r\n nis_code,\r\n description\r\n FROM integration_suspicious_cases.view_current_address_with_specification_derived_from_building_unit_without_linked_building_unit"); + }); + + modelBuilder.Entity("Basisregisters.IntegrationDb.SuspiciousCases.Views.CurrentAddressWithoutLinkedParcelOrBuildingUnit", b => + { + b.Property("AddressPersistentLocalId") + .HasColumnType("integer") + .HasColumnName("address_persistent_local_id"); + + b.Property("Description") + .IsRequired() + .HasColumnType("text") + .HasColumnName("description"); + + b.Property("NisCode") + .IsRequired() + .HasColumnType("text") + .HasColumnName("nis_code"); + + b.Property("PersistentLocalId") + .IsRequired() + .HasColumnType("text") + .HasColumnName("persistent_local_id"); + + b.ToTable((string)null); + + b.ToView("view_current_address_without_linked_parcel_or_building_unit", "integration_suspicious_cases"); + + b.ToSqlQuery("SELECT\r\n persistent_local_id,\r\n address_persistent_local_id,\r\n nis_code,\r\n description\r\n FROM integration_suspicious_cases.view_current_address_without_linked_parcel_or_building_unit"); + }); + + modelBuilder.Entity("Basisregisters.IntegrationDb.SuspiciousCases.Views.CurrentStreetNameWithoutLinkedRoadSegments", b => + { + b.Property("Description") + .IsRequired() + .HasColumnType("text") + .HasColumnName("description"); + + b.Property("NisCode") + .IsRequired() + .HasColumnType("text") + .HasColumnName("nis_code"); + + b.Property("PersistentLocalId") + .IsRequired() + .HasColumnType("text") + .HasColumnName("persistent_local_id"); + + b.Property("StreetNamePersistentLocalId") + .HasColumnType("integer") + .HasColumnName("streetname_persistent_local_id"); + + b.ToTable((string)null); + + b.ToView("view_current_street_name_without_linked_road_segments", "integration_suspicious_cases"); + + b.ToSqlQuery("\r\n SELECT\r\n persistent_local_id,\r\n streetname_persistent_local_id,\r\n nis_code,\r\n description\r\n FROM integration_suspicious_cases.view_current_street_name_without_linked_road_segments"); + }); + + modelBuilder.Entity("Basisregisters.IntegrationDb.SuspiciousCases.Views.Internal.ActiveBuildingUnitWithoutAddress", b => + { + b.Property("BuildingUnitPersistentLocalId") + .HasColumnType("integer") + .HasColumnName("building_unit_persistent_local_id"); + + b.Property("Description") + .IsRequired() + .HasColumnType("text") + .HasColumnName("description"); + + b.Property("NisCode") + .IsRequired() + .HasColumnType("text") + .HasColumnName("nis_code"); + + b.Property("PersistentLocalId") + .IsRequired() + .HasColumnType("text") + .HasColumnName("persistent_local_id"); + + b.ToTable((string)null); + + b.ToView("view_active_building_unit_without_address", "integration_suspicious_cases"); + + b.ToSqlQuery("\r\n SELECT\r\n persistent_local_id,\r\n building_unit_persistent_local_id,\r\n nis_code,\r\n CONCAT('Gebouweenheid-', building_unit_persistent_local_id) as description\r\n FROM integration_suspicious_cases.view_active_building_unit_without_address"); + }); + + modelBuilder.Entity("Basisregisters.IntegrationDb.SuspiciousCases.Views.ProposedAddressWithoutLinkedParcelOrBuildingUnit", b => + { + b.Property("AddressPersistentLocalId") + .HasColumnType("integer") + .HasColumnName("address_persistent_local_id"); + + b.Property("Description") + .IsRequired() + .HasColumnType("text") + .HasColumnName("description"); + + b.Property("NisCode") + .IsRequired() + .HasColumnType("text") + .HasColumnName("nis_code"); + + b.Property("PersistentLocalId") + .IsRequired() + .HasColumnType("text") + .HasColumnName("persistent_local_id"); + + b.ToTable((string)null); + + b.ToView("view_proposed_address_without_linked_parcel_or_building_unit", "integration_suspicious_cases"); + + b.ToSqlQuery("SELECT\r\n persistent_local_id,\r\n address_persistent_local_id,\r\n nis_code,\r\n description\r\n FROM integration_suspicious_cases.view_proposed_address_without_linked_parcel_or_building_unit"); + }); + + modelBuilder.Entity("Basisregisters.IntegrationDb.SuspiciousCases.Views.RoadSegmentLongerThanTwoYearsWithPermit", b => + { + b.Property("Description") + .IsRequired() + .HasColumnType("text") + .HasColumnName("description"); + + b.Property("NisCode") + .IsRequired() + .HasColumnType("text") + .HasColumnName("nis_code"); + + b.Property("PersistentLocalId") + .IsRequired() + .HasColumnType("text") + .HasColumnName("persistent_local_id"); + + b.Property("RoadSegmentPersistentLocalId") + .HasColumnType("integer") + .HasColumnName("road_segment_persistent_local_id"); + + b.ToTable((string)null); + + b.ToView("view_road_segment_longer_than_two_years_with_permit", "integration_suspicious_cases"); + + b.ToSqlQuery("\r\n SELECT\r\n persistent_local_id,\r\n road_segment_persistent_local_id,\r\n nis_code,\r\n CONCAT('Wegsegment-', road_segment_persistent_local_id) as description\r\n FROM integration_suspicious_cases.view_road_segment_longer_than_two_years_with_permit"); + }); + + modelBuilder.Entity("Basisregisters.IntegrationDb.SuspiciousCases.Views.RoadSegmentWithSingleLinkedStreetName", b => + { + b.Property("Description") + .IsRequired() + .HasColumnType("text") + .HasColumnName("description"); + + b.Property("NisCode") + .IsRequired() + .HasColumnType("text") + .HasColumnName("nis_code"); + + b.Property("PersistentLocalId") + .IsRequired() + .HasColumnType("text") + .HasColumnName("persistent_local_id"); + + b.Property("RoadSegmentPersistentLocalId") + .HasColumnType("integer") + .HasColumnName("road_segment_persistent_local_id"); + + b.ToTable((string)null); + + b.ToView("view_road_segment_with_single_linked_streetname", "integration_suspicious_cases"); + + b.ToSqlQuery("\r\n SELECT\r\n persistent_local_id,\r\n road_segment_persistent_local_id,\r\n nis_code,\r\n CONCAT('Wegsegment-', road_segment_persistent_local_id) as description\r\n FROM integration_suspicious_cases.view_road_segment_with_single_linked_streetname"); + }); + + modelBuilder.Entity("Basisregisters.IntegrationDb.SuspiciousCases.Views.StreetNameLongerThanTwoYearsProposed", b => + { + b.Property("Description") + .IsRequired() + .HasColumnType("text") + .HasColumnName("description"); + + b.Property("NisCode") + .IsRequired() + .HasColumnType("text") + .HasColumnName("nis_code"); + + b.Property("PersistentLocalId") + .IsRequired() + .HasColumnType("text") + .HasColumnName("persistent_local_id"); + + b.Property("StreetNamePersistentLocalId") + .HasColumnType("integer") + .HasColumnName("streetname_persistent_local_id"); + + b.ToTable((string)null); + + b.ToView("view_streetname_longer_than_two_years_proposed", "integration_suspicious_cases"); + + b.ToSqlQuery("\r\n SELECT\r\n persistent_local_id,\r\n streetname_persistent_local_id,\r\n nis_code,\r\n description\r\n FROM integration_suspicious_cases.view_streetname_longer_than_two_years_proposed"); + }); + + modelBuilder.Entity("Basisregisters.IntegrationDb.SuspiciousCases.Views.SuspiciousCaseCount", b => + { + b.Property("Count") + .HasColumnType("integer") + .HasColumnName("count"); + + b.Property("NisCode") + .IsRequired() + .HasColumnType("text") + .HasColumnName("nis_code"); + + b.Property("Type") + .HasColumnType("integer") + .HasColumnName("type"); + + b.ToTable((string)null); + + b.ToView("view_suspicious_cases_counts", "integration_suspicious_cases"); + + b.ToSqlQuery("select\r\n nis_code,\r\n count,\r\n type\r\n FROM integration_suspicious_cases.view_suspicious_cases_counts"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/Basisregisters.IntegrationDb.SuspiciousCases/Migrations/20241112080757_RecreateParcelViews.cs b/src/Basisregisters.IntegrationDb.SuspiciousCases/Migrations/20241112080757_RecreateParcelViews.cs new file mode 100644 index 0000000..388e286 --- /dev/null +++ b/src/Basisregisters.IntegrationDb.SuspiciousCases/Migrations/20241112080757_RecreateParcelViews.cs @@ -0,0 +1,43 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Basisregisters.IntegrationDb.SuspiciousCases.Migrations +{ + using Infrastructure; + using Views; + using Views.Internal; + + /// + public partial class RecreateParcelViews : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.Sql($"DROP MATERIALIZED VIEW IF EXISTS {Schema.SuspiciousCases}.{SuspiciousCaseCountConfiguration.ViewName};"); + + migrationBuilder.Sql($"DROP VIEW IF EXISTS {Schema.SuspiciousCases}.{InactiveParcelLinkedToAddress.ViewName};"); + migrationBuilder.Sql(InactiveParcelLinkedToAddress.Create); + + migrationBuilder.Sql($"DROP VIEW IF EXISTS {Schema.SuspiciousCases}.{InactiveAddressLinkedToParcelOrBuildingUnit.ViewName};"); + migrationBuilder.Sql(InactiveAddressLinkedToParcelOrBuildingUnit.Create); + + migrationBuilder.Sql($"DROP VIEW IF EXISTS {Schema.SuspiciousCases}.{CurrentAddressLinkedWithBuildingUnitButNotWithParcelConfiguration.ViewName};"); + migrationBuilder.Sql(CurrentAddressLinkedWithBuildingUnitButNotWithParcelConfiguration.Create); + + migrationBuilder.Sql($"DROP VIEW IF EXISTS {Schema.SuspiciousCases}.{CurrentAddressWithoutLinkedParcelOrBuildingUnitConfiguration.ViewName};"); + migrationBuilder.Sql(CurrentAddressWithoutLinkedParcelOrBuildingUnitConfiguration.Create); + + migrationBuilder.Sql($"DROP VIEW IF EXISTS {Schema.SuspiciousCases}.{ProposedAddressWithoutLinkedParcelOrBuildingUnitConfiguration.ViewName};"); + migrationBuilder.Sql(ProposedAddressWithoutLinkedParcelOrBuildingUnitConfiguration.Create); + + migrationBuilder.Sql(SuspiciousCaseCountConfiguration.Create); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.Sql(SuspiciousCaseCountConfiguration.Create); + } + } +} diff --git a/src/Basisregisters.IntegrationDb.SuspiciousCases/Migrations/SuspiciousCasesContextModelSnapshot.cs b/src/Basisregisters.IntegrationDb.SuspiciousCases/Migrations/SuspiciousCasesContextModelSnapshot.cs index 2083119..8cabe1d 100644 --- a/src/Basisregisters.IntegrationDb.SuspiciousCases/Migrations/SuspiciousCasesContextModelSnapshot.cs +++ b/src/Basisregisters.IntegrationDb.SuspiciousCases/Migrations/SuspiciousCasesContextModelSnapshot.cs @@ -386,7 +386,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.ToSqlQuery("\r\n SELECT\r\n persistent_local_id,\r\n road_segment_persistent_local_id,\r\n nis_code,\r\n CONCAT('Wegsegment-', road_segment_persistent_local_id) as description\r\n FROM integration_suspicious_cases.view_road_segment_longer_than_two_years_with_permit"); }); - modelBuilder.Entity("Basisregisters.IntegrationDb.SuspiciousCases.Views.RoadSegmentSingleLinkedStreetName", b => + modelBuilder.Entity("Basisregisters.IntegrationDb.SuspiciousCases.Views.RoadSegmentWithSingleLinkedStreetName", b => { b.Property("Description") .IsRequired()