Index: Riskeer/Migration/src/Riskeer.Migration.Core/EmbeddedResources/Migration_18.1_19.1.sql =================================================================== diff -u -r12fd218d21497cff95fd9aa52539cee9ea426d31 -re465adce439e685e2349141ec6162af2c8865922 --- Riskeer/Migration/src/Riskeer.Migration.Core/EmbeddedResources/Migration_18.1_19.1.sql (.../Migration_18.1_19.1.sql) (revision 12fd218d21497cff95fd9aa52539cee9ea426d31) +++ Riskeer/Migration/src/Riskeer.Migration.Core/EmbeddedResources/Migration_18.1_19.1.sql (.../Migration_18.1_19.1.sql) (revision e465adce439e685e2349141ec6162af2c8865922) @@ -1755,6 +1755,26 @@ DETACH LOGDATABASE; -DETACH SOURCEPROJECT; +PRAGMA foreign_keys = ON; -PRAGMA foreign_keys = ON; \ No newline at end of file +/* + Delete all output entries that were calculated with invalid dikeprofiles or foreshoreprofiles + Deletion is performed at this stage to prevent orphaned entries in the database after migration +*/ +DELETE +FROM GrassCoverErosionInwardsOutputEntity +WHERE GrassCoverErosionInwardsOutputEntityId IN +( + SELECT + [GrassCoverErosionInwardsOutputEntityId] + FROM [SOURCEPROJECT].GrassCoverErosionInwardsOutputEntity + JOIN [SOURCEPROJECT].GrassCoverErosionInwardsCalculationEntity USING(GrassCoverErosionInwardsCalculationEntityId) + JOIN [SOURCEPROJECT].DikeProfileEntity USING(DikeProfileEntityId) + WHERE(LENGTH(DikeGeometryXml) - LENGTH(REPLACE(REPLACE(DikeGeometryXml, '', ''), '', ''))) / + (LENGTH('') + LENGTH('')) < 2 + OR (LENGTH(ForeshoreXML) - LENGTH(REPLACE(REPLACE(ForeshoreXML, '', ''), '', ''))) + / (LENGTH('') + LENGTH('')) != 1 +); + + +DETACH SOURCEPROJECT; \ No newline at end of file Index: Riskeer/Migration/test/Riskeer.Migration.Integration.Test/MigrationTo191IntegrationTest.cs =================================================================== diff -u -r12fd218d21497cff95fd9aa52539cee9ea426d31 -re465adce439e685e2349141ec6162af2c8865922 --- Riskeer/Migration/test/Riskeer.Migration.Integration.Test/MigrationTo191IntegrationTest.cs (.../MigrationTo191IntegrationTest.cs) (revision 12fd218d21497cff95fd9aa52539cee9ea426d31) +++ Riskeer/Migration/test/Riskeer.Migration.Integration.Test/MigrationTo191IntegrationTest.cs (.../MigrationTo191IntegrationTest.cs) (revision e465adce439e685e2349141ec6162af2c8865922) @@ -69,6 +69,7 @@ AssertPipingSoilLayers(reader); AssertGrassCoverErosionInwardsCalculation(reader, sourceFilePath); + AssertGrassCoverErosionInwardsOutput(reader, sourceFilePath); AssertGrassCoverErosionOutwardsWaveConditionsCalculations(reader, sourceFilePath); AssertGrassCoverErosionOutwardsWaveConditionsOutput(reader, sourceFilePath); @@ -326,6 +327,33 @@ reader.AssertReturnedDataIsValid(validateCalculationsWithValidDikeProfile); } + private static void AssertGrassCoverErosionInwardsOutput(MigratedDatabaseReader reader, string sourceFilePath) + { + string validateOutputs = + $"ATTACH DATABASE \"{sourceFilePath}\" AS SOURCEPROJECT;" + + "SELECT COUNT() = " + + "( " + + "SELECT COUNT() " + + "FROM [SOURCEPROJECT].GrassCoverErosionInwardsOutputEntity " + + "JOIN [SOURCEPROJECT].GrassCoverErosionInwardsCalculationEntity USING(GrassCoverErosionInwardsCalculationEntityId) " + + "JOIN [SOURCEPROJECT].DikeProfileEntity USING(DikeProfileEntityId) " + + "WHERE(LENGTH(DikeGeometryXml) - LENGTH(REPLACE(REPLACE(DikeGeometryXml, '', ''), '', ''))) / " + + "(LENGTH('') + LENGTH('')) > 1 " + + "AND (LENGTH(ForeshoreXML) - LENGTH(REPLACE(REPLACE(ForeshoreXML, '', ''), '', ''))) " + + "/ (LENGTH('') + LENGTH('')) != 1 " + + ") " + + "FROM GrassCoverErosionInwardsOutputEntity NEW " + + "JOIN [SOURCEPROJECT].GrassCoverErosionInwardsOutputEntity OLD USING(GrassCoverErosionInwardsOutputEntityId) " + + "WHERE NEW.[GrassCoverErosionInwardsCalculationEntityId] = OLD.[GrassCoverErosionInwardsCalculationEntityId] " + + "AND NEW.[GeneralResultFaultTreeIllustrationPointEntityId] IS OLD.[GeneralResultFaultTreeIllustrationPointEntityId] " + + "AND NEW.\"Order\" = OLD.\"Order\" " + + "AND NEW.[IsOvertoppingDominant] IS OLD.[IsOvertoppingDominant] " + + "AND NEW.[WaveHeight] IS OLD.[WaveHeight] " + + "AND NEW.[Reliability] IS OLD.[Reliability]; " + + "DETACH SOURCEPROJECT;"; + reader.AssertReturnedDataIsValid(validateOutputs); + } + private static void AssertGrassCoverErosionOutwardsWaveConditionsCalculations(MigratedDatabaseReader reader, string sourceFilePath) { string validateCalculationsWithoutForeshoreProfile = @@ -1064,7 +1092,6 @@ "GrassCoverErosionInwardsCalculationEntity", "GrassCoverErosionInwardsDikeHeightOutputEntity", "GrassCoverErosionInwardsFailureMechanismMetaEntity", - "GrassCoverErosionInwardsOutputEntity", "GrassCoverErosionInwardsOvertoppingRateOutputEntity", "GrassCoverErosionInwardsSectionResultEntity", "GrassCoverErosionOutwardsFailureMechanismMetaEntity",