From 29596ffc0e6dbea49ae65bf534ba32526f108a26 Mon Sep 17 00:00:00 2001 From: ArneD Date: Thu, 28 Nov 2024 10:12:57 +0100 Subject: [PATCH] feat: switch wms/wfs views V3 GAWR-6685 --- ...41128083931_SwitchWmsViewsToV3.Designer.cs | 216 ++++++++++++++++++ .../20241128083931_SwitchWmsViewsToV3.cs | 56 +++++ ...41128081919_SwitchWmsViewsToV3.Designer.cs | 178 +++++++++++++++ .../20241128081919_SwitchWmsViewsToV3.cs | 114 +++++++++ 4 files changed, 564 insertions(+) create mode 100644 src/BuildingRegistry.Projections.Wfs/Migrations/20241128083931_SwitchWmsViewsToV3.Designer.cs create mode 100644 src/BuildingRegistry.Projections.Wfs/Migrations/20241128083931_SwitchWmsViewsToV3.cs create mode 100644 src/BuildingRegistry.Projections.Wms/Migrations/20241128081919_SwitchWmsViewsToV3.Designer.cs create mode 100644 src/BuildingRegistry.Projections.Wms/Migrations/20241128081919_SwitchWmsViewsToV3.cs diff --git a/src/BuildingRegistry.Projections.Wfs/Migrations/20241128083931_SwitchWmsViewsToV3.Designer.cs b/src/BuildingRegistry.Projections.Wfs/Migrations/20241128083931_SwitchWmsViewsToV3.Designer.cs new file mode 100644 index 000000000..0c08fa659 --- /dev/null +++ b/src/BuildingRegistry.Projections.Wfs/Migrations/20241128083931_SwitchWmsViewsToV3.Designer.cs @@ -0,0 +1,216 @@ +// +using System; +using BuildingRegistry.Projections.Wfs; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using NetTopologySuite.Geometries; + +#nullable disable + +namespace BuildingRegistry.Projections.Wfs.Migrations +{ + [DbContext(typeof(WfsContext))] + [Migration("20241128083931_SwitchWmsViewsToV3")] + partial class SwitchWmsViewsToV3 + { + /// + 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", "wfs"); + }); + + modelBuilder.Entity("BuildingRegistry.Projections.Wfs.BuildingUnitV2.BuildingUnitV2", b => + { + b.Property("BuildingUnitPersistentLocalId") + .HasColumnType("int"); + + b.Property("BuildingPersistentLocalId") + .HasColumnType("int"); + + b.Property("Function") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.Property("HasDeviation") + .ValueGeneratedOnAdd() + .HasColumnType("bit") + .HasDefaultValue(false); + + b.Property("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("IsRemoved") + .HasColumnType("bit"); + + b.Property("Position") + .IsRequired() + .HasColumnType("sys.geometry"); + + b.Property("PositionMethod") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.Property("Status") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.Property("VersionAsString") + .HasColumnType("nvarchar(450)"); + + b.Property("VersionTimestampAsDateTimeOffset") + .HasColumnType("datetimeoffset") + .HasColumnName("Version"); + + b.HasKey("BuildingUnitPersistentLocalId"); + + SqlServerKeyBuilderExtensions.IsClustered(b.HasKey("BuildingUnitPersistentLocalId")); + + b.HasIndex("BuildingPersistentLocalId"); + + b.HasIndex("BuildingUnitPersistentLocalId"); + + b.HasIndex("Function"); + + b.HasIndex("Id"); + + b.HasIndex("IsRemoved"); + + b.HasIndex("PositionMethod"); + + b.HasIndex("Status"); + + b.HasIndex("VersionAsString"); + + b.ToTable("BuildingUnitsV2", "wfs"); + }); + + modelBuilder.Entity("BuildingRegistry.Projections.Wfs.BuildingV2.BuildingV2", b => + { + b.Property("PersistentLocalId") + .HasColumnType("int"); + + b.Property("Geometry") + .HasColumnType("sys.geometry"); + + b.Property("GeometryMethod") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.Property("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("IsRemoved") + .HasColumnType("bit"); + + b.Property("Status") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.Property("VersionAsString") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.Property("VersionTimestampAsDateTimeOffset") + .HasColumnType("datetimeoffset") + .HasColumnName("Version"); + + b.HasKey("PersistentLocalId"); + + SqlServerKeyBuilderExtensions.IsClustered(b.HasKey("PersistentLocalId")); + + b.HasIndex("GeometryMethod"); + + b.HasIndex("Id"); + + b.HasIndex("IsRemoved"); + + b.HasIndex("PersistentLocalId"); + + b.HasIndex("Status"); + + b.HasIndex("VersionAsString"); + + b.ToTable("BuildingsV2", "wfs"); + }); + + modelBuilder.Entity("BuildingRegistry.Projections.Wfs.BuildingV3.BuildingV3", b => + { + b.Property("PersistentLocalId") + .HasColumnType("int"); + + b.Property("Geometry") + .HasColumnType("sys.geometry"); + + b.Property("GeometryMethod") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.Property("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("IsRemoved") + .HasColumnType("bit"); + + b.Property("Status") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.Property("VersionAsString") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.Property("VersionTimestampAsDateTimeOffset") + .HasColumnType("datetimeoffset") + .HasColumnName("Version"); + + b.HasKey("PersistentLocalId"); + + SqlServerKeyBuilderExtensions.IsClustered(b.HasKey("PersistentLocalId")); + + b.HasIndex("GeometryMethod"); + + b.HasIndex("Id"); + + b.HasIndex("IsRemoved"); + + b.HasIndex("PersistentLocalId"); + + b.HasIndex("Status"); + + b.HasIndex("VersionAsString"); + + b.ToTable("BuildingsV3", "wfs"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/BuildingRegistry.Projections.Wfs/Migrations/20241128083931_SwitchWmsViewsToV3.cs b/src/BuildingRegistry.Projections.Wfs/Migrations/20241128083931_SwitchWmsViewsToV3.cs new file mode 100644 index 000000000..8257ba693 --- /dev/null +++ b/src/BuildingRegistry.Projections.Wfs/Migrations/20241128083931_SwitchWmsViewsToV3.cs @@ -0,0 +1,56 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace BuildingRegistry.Projections.Wfs.Migrations +{ + using Infrastructure; + + /// + public partial class SwitchWmsViewsToV3 : Migration + { + private const string BuildingViewName = "GebouwView"; + + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.Sql($@"DROP VIEW [{Schema.Wfs}].[{BuildingViewName}]"); + + migrationBuilder.Sql($@" + CREATE VIEW [{Schema.Wfs}].[{BuildingViewName}] + WITH SCHEMABINDING + AS + SELECT + [PersistentLocalId] AS [MyId], + [Id], + [PersistentLocalId] AS [ObjectId], + [VersionAsString] AS [VersieId], + [Geometry] AS [Geometrie], + [GeometryMethod] AS [GeometrieMethode], + [Status] AS [GebouwStatus] + FROM [{Schema.Wfs}].[{BuildingV3.BuildingConfiguration.TableName}] + WHERE [IsRemoved] = 0 and Geometry is not null"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.Sql($@"DROP VIEW [{Schema.Wfs}].[{BuildingViewName}]"); + + migrationBuilder.Sql($@" + CREATE VIEW [{Schema.Wfs}].[{BuildingViewName}] + WITH SCHEMABINDING + AS + SELECT + [PersistentLocalId] AS [MyId], + [Id], + [PersistentLocalId] AS [ObjectId], + [VersionAsString] AS [VersieId], + [Geometry] AS [Geometrie], + [GeometryMethod] AS [GeometrieMethode], + [Status] AS [GebouwStatus] + FROM [{Schema.Wfs}].[{BuildingV2.BuildingConfiguration.TableName}] + WHERE [IsRemoved] = 0 and Geometry is not null"); + } + } +} diff --git a/src/BuildingRegistry.Projections.Wms/Migrations/20241128081919_SwitchWmsViewsToV3.Designer.cs b/src/BuildingRegistry.Projections.Wms/Migrations/20241128081919_SwitchWmsViewsToV3.Designer.cs new file mode 100644 index 000000000..ffb732edc --- /dev/null +++ b/src/BuildingRegistry.Projections.Wms/Migrations/20241128081919_SwitchWmsViewsToV3.Designer.cs @@ -0,0 +1,178 @@ +// +using System; +using BuildingRegistry.Projections.Wms; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace BuildingRegistry.Projections.Wms.Migrations +{ + [DbContext(typeof(WmsContext))] + [Migration("20241128081919_SwitchWmsViewsToV3")] + partial class SwitchWmsViewsToV3 + { + /// + 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", "wms"); + }); + + modelBuilder.Entity("BuildingRegistry.Projections.Wms.BuildingUnitV2.BuildingUnitV2", b => + { + b.Property("BuildingUnitPersistentLocalId") + .HasColumnType("int"); + + b.Property("BuildingPersistentLocalId") + .HasColumnType("int"); + + b.Property("Function") + .IsRequired() + .HasMaxLength(21) + .HasColumnType("varchar(21)"); + + b.Property("HasDeviation") + .ValueGeneratedOnAdd() + .HasColumnType("bit") + .HasDefaultValue(false); + + b.Property("Id") + .HasMaxLength(53) + .HasColumnType("varchar(53)"); + + b.Property("Position") + .HasColumnType("varbinary(max)"); + + b.Property("PositionMethod") + .IsRequired() + .HasMaxLength(22) + .HasColumnType("varchar(22)"); + + b.Property("Status") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.Property("VersionAsString") + .HasColumnType("nvarchar(max)"); + + b.Property("VersionTimestampAsDateTimeOffset") + .HasColumnType("datetimeoffset") + .HasColumnName("Version"); + + b.HasKey("BuildingUnitPersistentLocalId"); + + SqlServerKeyBuilderExtensions.IsClustered(b.HasKey("BuildingUnitPersistentLocalId")); + + b.HasIndex("BuildingPersistentLocalId"); + + b.HasIndex("Status"); + + b.ToTable("BuildingUnitsV2", "wms"); + }); + + modelBuilder.Entity("BuildingRegistry.Projections.Wms.BuildingV2.BuildingV2", b => + { + b.Property("PersistentLocalId") + .HasColumnType("int"); + + b.Property("Geometry") + .HasColumnType("varbinary(max)"); + + b.Property("GeometryMethod") + .IsRequired() + .HasMaxLength(12) + .HasColumnType("varchar(12)"); + + b.Property("Id") + .HasMaxLength(46) + .HasColumnType("varchar(46)"); + + b.Property("Status") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.Property("VersionAsString") + .HasColumnType("nvarchar(max)"); + + b.Property("VersionTimestampAsDateTimeOffset") + .HasColumnType("datetimeoffset") + .HasColumnName("Version"); + + b.HasKey("PersistentLocalId"); + + SqlServerKeyBuilderExtensions.IsClustered(b.HasKey("PersistentLocalId")); + + b.HasIndex("Status"); + + b.ToTable("BuildingsV2", "wms"); + }); + + modelBuilder.Entity("BuildingRegistry.Projections.Wms.BuildingV3.BuildingV3", b => + { + b.Property("PersistentLocalId") + .HasColumnType("int"); + + b.Property("Geometry") + .HasColumnType("varbinary(max)"); + + b.Property("GeometryMethod") + .IsRequired() + .HasMaxLength(12) + .HasColumnType("varchar(12)"); + + b.Property("Id") + .HasMaxLength(46) + .HasColumnType("varchar(46)"); + + b.Property("Status") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.Property("VersionAsString") + .HasColumnType("nvarchar(max)"); + + b.Property("VersionTimestampAsDateTimeOffset") + .HasColumnType("datetimeoffset") + .HasColumnName("Version"); + + b.HasKey("PersistentLocalId"); + + SqlServerKeyBuilderExtensions.IsClustered(b.HasKey("PersistentLocalId")); + + b.HasIndex("Status"); + + b.ToTable("BuildingsV3", "wms"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/BuildingRegistry.Projections.Wms/Migrations/20241128081919_SwitchWmsViewsToV3.cs b/src/BuildingRegistry.Projections.Wms/Migrations/20241128081919_SwitchWmsViewsToV3.cs new file mode 100644 index 000000000..68d327a7b --- /dev/null +++ b/src/BuildingRegistry.Projections.Wms/Migrations/20241128081919_SwitchWmsViewsToV3.cs @@ -0,0 +1,114 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace BuildingRegistry.Projections.Wms.Migrations +{ + /// + public partial class SwitchWmsViewsToV3 : Migration + { + private readonly AddViews.StatusViews _buildingUpViews = new AddViews.StatusViews( + "GebouwView", + new AddViews.StatusView { Name = "GebouwGepland", DisplayedStatus = "Gepland", Criteria = "Planned" }, + new AddViews.StatusView { Name = "GebouwGehistoreerd", DisplayedStatus = "Gehistoreerd", Criteria = "Retired" }, + new AddViews.StatusView { Name = "GebouwGerealiseerd", DisplayedStatus = "Gerealiseerd", Criteria = "Realized" }, + new AddViews.StatusView { Name = "GebouwNietGerealiseerd", DisplayedStatus = "NietGerealiseerd", Criteria = "NotRealized" }, + new AddViews.StatusView { Name = "GebouwInAanbouw", DisplayedStatus = "InAanbouw", Criteria = "UnderConstruction" } + ); + + private readonly AddViews.StatusViews _buildingDownViews = new AddViews.StatusViews( + "GebouwView", + new AddViews.StatusView { Name = "GebouwGepland", DisplayedStatus = "Gepland", Criteria = "Planned" }, + new AddViews.StatusView { Name = "GebouwGehistoreerd", DisplayedStatus = "Gehistoreerd", Criteria = "Retired" }, + new AddViews.StatusView { Name = "GebouwGerealiseerd", DisplayedStatus = "Gerealiseerd", Criteria = "Realized" }, + new AddViews.StatusView { Name = "GebouwNietGerealiseerd", DisplayedStatus = "NietGerealiseerd", Criteria = "NotRealized" }, + new AddViews.StatusView { Name = "GebouwInAanbouw", DisplayedStatus = "InAanbouw", Criteria = "UnderConstruction" } + ); + + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.Sql("DROP VIEW [wms].[GebouwGehistoreerd]"); + migrationBuilder.Sql("DROP VIEW [wms].[GebouwInAanbouw]"); + migrationBuilder.Sql("DROP VIEW [wms].[GebouwGepland]"); + migrationBuilder.Sql("DROP VIEW [wms].[GebouwGerealiseerd]"); + migrationBuilder.Sql("DROP VIEW [wms].[GebouwNietGerealiseerd]"); + migrationBuilder.Sql("DROP VIEW [wms].[GebouwView]"); + + migrationBuilder.Sql($@" + CREATE VIEW [wms].[{_buildingUpViews.SourceViewName}] + WITH SCHEMABINDING + AS + SELECT + [PersistentLocalId] AS [ObjectId], + [Id], + [VersionAsString] AS [VersieId], + [CalculatedGeometry] AS [Geometry], + [GeometryMethod] AS [GeometrieMethode], + [Status], + [Version] AS RawVersion + FROM [wms].[{BuildingV3.BuildingConfiguration.TableName}] + WHERE ([CalculatedGeometry] IS NOT NULL) + GO"); + + foreach (var view in _buildingUpViews.Views) + migrationBuilder.Sql($@" + CREATE VIEW [wms].[{view.Name}] + WITH SCHEMABINDING + AS + SELECT + [ObjectId], + [Id], + [VersieId], + [Geometry], + [GeometrieMethode], + '{view.DisplayedStatus}' as [GebouwStatus] + FROM [wms].[{_buildingUpViews.SourceViewName}] + WHERE Status = '{view.Criteria}' + GO"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.Sql("DROP VIEW [wms].[GebouwGehistoreerd]"); + migrationBuilder.Sql("DROP VIEW [wms].[GebouwInAanbouw]"); + migrationBuilder.Sql("DROP VIEW [wms].[GebouwGepland]"); + migrationBuilder.Sql("DROP VIEW [wms].[GebouwGerealiseerd]"); + migrationBuilder.Sql("DROP VIEW [wms].[GebouwNietGerealiseerd]"); + migrationBuilder.Sql("DROP VIEW [wms].[GebouwView]"); + + migrationBuilder.Sql($@" + CREATE VIEW [wms].[{_buildingDownViews.SourceViewName}] + WITH SCHEMABINDING + AS + SELECT + [PersistentLocalId] AS [ObjectId], + [Id], + [VersionAsString] AS [VersieId], + [CalculatedGeometry] AS [Geometry], + [GeometryMethod] AS [GeometrieMethode], + [Status], + [Version] AS RawVersion + FROM [wms].[{BuildingV2.BuildingConfiguration.TableName}] + WHERE ([CalculatedGeometry] IS NOT NULL) + GO"); + + foreach (var view in _buildingDownViews.Views) + migrationBuilder.Sql($@" + CREATE VIEW [wms].[{view.Name}] + WITH SCHEMABINDING + AS + SELECT + [ObjectId], + [Id], + [VersieId], + [Geometry], + [GeometrieMethode], + '{view.DisplayedStatus}' as [GebouwStatus] + FROM [wms].[{_buildingDownViews.SourceViewName}] + WHERE Status = '{view.Criteria}' + GO"); + } + } +}