Index: Riskeer/Migration/src/Riskeer.Migration.Core/EmbeddedResources/DatabaseStructure20.1.sql =================================================================== diff -u -r6a24a8b30379e9e43b1a110d75542e30b3928523 -r131d07faed45ea4eac3fd2f6780a7e49603db994 --- Riskeer/Migration/src/Riskeer.Migration.Core/EmbeddedResources/DatabaseStructure20.1.sql (.../DatabaseStructure20.1.sql) (revision 6a24a8b30379e9e43b1a110d75542e30b3928523) +++ Riskeer/Migration/src/Riskeer.Migration.Core/EmbeddedResources/DatabaseStructure20.1.sql (.../DatabaseStructure20.1.sql) (revision 131d07faed45ea4eac3fd2f6780a7e49603db994) @@ -1,6 +1,6 @@ /* ---------------------------------------------------- */ /* Generated by Enterprise Architect Version 14.1 */ -/* Created On : 25-mrt-2020 07:43:12 */ +/* Created On : 19-jun-2020 07:56:26 */ /* DBMS : SQLite */ /* ---------------------------------------------------- */ @@ -482,6 +482,8 @@ 'ShouldDikeHeightIllustrationPointsBeCalculated' TINYINT (1) NOT NULL, -- true or false 'ShouldOvertoppingRateIllustrationPointsBeCalculated' TINYINT (1) NOT NULL, -- true or false 'ShouldOvertoppingOutputIllustrationPointsBeCalculated' TINYINT (1) NOT NULL, -- true or false + 'RelevantForScenario' TINYINT (1) NOT NULL, -- true or false + 'ScenarioContribution' REAL NULL, CONSTRAINT 'FK_GrassCoverErosionInwardsCalculationEntity_CalculationGroupEntity' FOREIGN KEY ('CalculationGroupEntityId') REFERENCES 'CalculationGroupEntity' ('CalculationGroupEntityId') ON DELETE Cascade ON UPDATE Cascade, CONSTRAINT 'FK_GrassCoverErosionInwardsCalculationEntity_DikeProfileEntity' FOREIGN KEY ('DikeProfileEntityId') REFERENCES 'DikeProfileEntity' ('DikeProfileEntityId') ON DELETE Set Null ON UPDATE Cascade, CONSTRAINT 'FK_GrassCoverErosionInwardsCalculationEntity_HydraulicLocationEntity' FOREIGN KEY ('HydraulicLocationEntityId') REFERENCES 'HydraulicLocationEntity' ('HydraulicLocationEntityId') ON DELETE Set Null ON UPDATE Cascade @@ -993,15 +995,13 @@ ( 'GrassCoverErosionInwardsSectionResultEntityId' INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, 'FailureMechanismSectionEntityId' INTEGER NOT NULL, - 'GrassCoverErosionInwardsCalculationEntityId' INTEGER NULL, 'SimpleAssessmentResult' TINYINT (1) NOT NULL, -- Enum: 1 = None, 2 = NotApplicable, 3 = Applicable 'DetailedAssessmentResult' TINYINT (1) NOT NULL, -- Enum: 1 = Probability, 2 = NotAssessed 'TailorMadeAssessmentResult' TINYINT (1) NOT NULL, -- Enum: 1 = None, 2 = ProbabilityNegligible, 3 = Probability, 4 = NotAssessed 'TailorMadeAssessmentProbability' REAL NULL, 'UseManualAssembly' TINYINT (1) NOT NULL, -- true or false 'ManualAssemblyProbability' REAL NULL, - CONSTRAINT 'FK_GrassCoverErosionInwardsSectionResultEntity_FailureMechanismSectionEntity' FOREIGN KEY ('FailureMechanismSectionEntityId') REFERENCES 'FailureMechanismSectionEntity' ('FailureMechanismSectionEntityId') ON DELETE Cascade ON UPDATE Cascade, - CONSTRAINT 'FK_GrassCoverErosionInwardsSectionResultEntity_GrassCoverErosionInwardsCalculationEntity' FOREIGN KEY ('GrassCoverErosionInwardsCalculationEntityId') REFERENCES 'GrassCoverErosionInwardsCalculationEntity' ('GrassCoverErosionInwardsCalculationEntityId') ON DELETE Set Null ON UPDATE Cascade + CONSTRAINT 'FK_GrassCoverErosionInwardsSectionResultEntity_FailureMechanismSectionEntity' FOREIGN KEY ('FailureMechanismSectionEntityId') REFERENCES 'FailureMechanismSectionEntity' ('FailureMechanismSectionEntityId') ON DELETE Cascade ON UPDATE Cascade ) ; @@ -2479,10 +2479,6 @@ ON 'GrassCoverErosionInwardsSectionResultEntity' ('FailureMechanismSectionEntityId' ASC) ; -CREATE INDEX 'IXFK_GrassCoverErosionInwardsSectionResultEntity_GrassCoverErosionInwardsCalculationEntity' - ON 'GrassCoverErosionInwardsSectionResultEntity' ('GrassCoverErosionInwardsCalculationEntityId' ASC) -; - CREATE INDEX 'IXFK_GrassCoverErosionOutwardsSectionResultEntity_FailureMechanismSectionEntity' ON 'GrassCoverErosionOutwardsSectionResultEntity' ('FailureMechanismSectionEntityId' ASC) ; Index: Riskeer/Migration/src/Riskeer.Migration.Core/EmbeddedResources/Migration_19.1_20.1.sql =================================================================== diff -u -r852da94031c1de463cdd55865cb788ba7ced0e69 -r131d07faed45ea4eac3fd2f6780a7e49603db994 --- Riskeer/Migration/src/Riskeer.Migration.Core/EmbeddedResources/Migration_19.1_20.1.sql (.../Migration_19.1_20.1.sql) (revision 852da94031c1de463cdd55865cb788ba7ced0e69) +++ Riskeer/Migration/src/Riskeer.Migration.Core/EmbeddedResources/Migration_19.1_20.1.sql (.../Migration_19.1_20.1.sql) (revision 131d07faed45ea4eac3fd2f6780a7e49603db994) @@ -34,12 +34,94 @@ INSERT INTO GeneralResultFaultTreeIllustrationPointStochastEntity SELECT * FROM [SOURCEPROJECT].GeneralResultFaultTreeIllustrationPointStochastEntity; INSERT INTO GeneralResultSubMechanismIllustrationPointEntity SELECT * FROM [SOURCEPROJECT].GeneralResultSubMechanismIllustrationPointEntity; INSERT INTO GeneralResultSubMechanismIllustrationPointStochastEntity SELECT * FROM [SOURCEPROJECT].GeneralResultSubMechanismIllustrationPointStochastEntity; -INSERT INTO GrassCoverErosionInwardsCalculationEntity SELECT * FROM [SOURCEPROJECT].GrassCoverErosionInwardsCalculationEntity; +INSERT INTO GrassCoverErosionInwardsCalculationEntity( + [GrassCoverErosionInwardsCalculationEntityId], + [CalculationGroupEntityId], + [HydraulicLocationEntityId], + [DikeProfileEntityId], + [Order], + [Name], + [Comments], + [Orientation], + [CriticalFlowRateMean], + [CriticalFlowRateStandardDeviation], + [UseForeshore], + [DikeHeightCalculationType], + [DikeHeight], + [UseBreakWater], + [BreakWaterType], + [BreakWaterHeight], + [OvertoppingRateCalculationType], + [ShouldDikeHeightIllustrationPointsBeCalculated], + [ShouldOvertoppingRateIllustrationPointsBeCalculated], + [ShouldOvertoppingOutputIllustrationPointsBeCalculated], + [RelevantForScenario], + [ScenarioContribution]) +SELECT + [GrassCoverErosionInwardsCalculationEntityId], + [CalculationGroupEntityId], + [HydraulicLocationEntityId], + [DikeProfileEntityId], + [Order], + [Name], + [Comments], + [Orientation], + [CriticalFlowRateMean], + [CriticalFlowRateStandardDeviation], + [UseForeshore], + [DikeHeightCalculationType], + [DikeHeight], + [UseBreakWater], + [BreakWaterType], + [BreakWaterHeight], + [OvertoppingRateCalculationType], + [ShouldDikeHeightIllustrationPointsBeCalculated], + [ShouldOvertoppingRateIllustrationPointsBeCalculated], + [ShouldOvertoppingOutputIllustrationPointsBeCalculated], + CASE + WHEN IsLinkedToSectionResult IS NOT NULL + THEN 1 + ELSE 0 + END, + CASE + WHEN IsLinkedToSectionResult IS NOT NULL + THEN 1 + ELSE 0 + END +FROM [SOURCEPROJECT].GrassCoverErosionInwardsCalculationEntity +LEFT JOIN( + SELECT + GrassCoverErosionInwardsCalculationEntityId, + CASE + WHEN GrassCoverErosionInwardsSectionResultEntityId IS NOT NULL + THEN 1 + ELSE 0 + END AS IsLinkedToSectionResult + FROM [SOURCEPROJECT].GrassCoverErosionInwardsSectionResultEntity) +USING(GrassCoverErosionInwardsCalculationEntityId); INSERT INTO GrassCoverErosionInwardsDikeHeightOutputEntity SELECT * FROM [SOURCEPROJECT].GrassCoverErosionInwardsDikeHeightOutputEntity; INSERT INTO GrassCoverErosionInwardsFailureMechanismMetaEntity SELECT * FROM [SOURCEPROJECT].GrassCoverErosionInwardsFailureMechanismMetaEntity; INSERT INTO GrassCoverErosionInwardsOutputEntity SELECT * FROM [SOURCEPROJECT].GrassCoverErosionInwardsOutputEntity; INSERT INTO GrassCoverErosionInwardsOvertoppingRateOutputEntity SELECT * FROM [SOURCEPROJECT].GrassCoverErosionInwardsOvertoppingRateOutputEntity; -INSERT INTO GrassCoverErosionInwardsSectionResultEntity SELECT * FROM [SOURCEPROJECT].GrassCoverErosionInwardsSectionResultEntity; +INSERT INTO GrassCoverErosionInwardsSectionResultEntity ( + [GrassCoverErosionInwardsSectionResultEntityId], + [FailureMechanismSectionEntityId], + [SimpleAssessmentResult], + [DetailedAssessmentResult], + [TailorMadeAssessmentResult], + [TailorMadeAssessmentProbability], + [UseManualAssembly], + [ManualAssemblyProbability]) +SELECT + [GrassCoverErosionInwardsSectionResultEntityId], + [FailureMechanismSectionEntityId], + [SimpleAssessmentResult], + [DetailedAssessmentResult], + [TailorMadeAssessmentResult], + [TailorMadeAssessmentProbability], + [UseManualAssembly], + [ManualAssemblyProbability] +FROM [SOURCEPROJECT].GrassCoverErosionInwardsSectionResultEntity; INSERT INTO GrassCoverErosionOutwardsFailureMechanismMetaEntity SELECT * FROM [SOURCEPROJECT].GrassCoverErosionOutwardsFailureMechanismMetaEntity; INSERT INTO GrassCoverErosionOutwardsSectionResultEntity SELECT * FROM [SOURCEPROJECT].GrassCoverErosionOutwardsSectionResultEntity; INSERT INTO GrassCoverErosionOutwardsWaveConditionsCalculationEntity SELECT * FROM [SOURCEPROJECT].GrassCoverErosionOutwardsWaveConditionsCalculationEntity; Index: Riskeer/Migration/test/Riskeer.Migration.Core.Test/test-data/MigrationTestProject191.risk =================================================================== diff -u -r09a6345c35c5c851dfb153e73abd69aaf64c0ebd -r131d07faed45ea4eac3fd2f6780a7e49603db994 Binary files differ Index: Riskeer/Migration/test/Riskeer.Migration.Integration.Test/MigrationTo201IntegrationTest.cs =================================================================== diff -u -r852da94031c1de463cdd55865cb788ba7ced0e69 -r131d07faed45ea4eac3fd2f6780a7e49603db994 --- Riskeer/Migration/test/Riskeer.Migration.Integration.Test/MigrationTo201IntegrationTest.cs (.../MigrationTo201IntegrationTest.cs) (revision 852da94031c1de463cdd55865cb788ba7ced0e69) +++ Riskeer/Migration/test/Riskeer.Migration.Integration.Test/MigrationTo201IntegrationTest.cs (.../MigrationTo201IntegrationTest.cs) (revision 131d07faed45ea4eac3fd2f6780a7e49603db994) @@ -33,15 +33,15 @@ private const string newVersion = "20.1"; [Test] - public void Given181Project_WhenUpgradedTo191_ThenProjectAsExpected() + public void Given191Project_WhenUpgradedTo201_ThenProjectAsExpected() { // Given string sourceFilePath = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Migration.Core, "MigrationTestProject191.risk"); var fromVersionedFile = new ProjectVersionedFile(sourceFilePath); - string targetFilePath = TestHelper.GetScratchPadPath(nameof(Given181Project_WhenUpgradedTo191_ThenProjectAsExpected)); - string logFilePath = TestHelper.GetScratchPadPath(string.Concat(nameof(Given181Project_WhenUpgradedTo191_ThenProjectAsExpected), ".log")); + string targetFilePath = TestHelper.GetScratchPadPath(nameof(Given191Project_WhenUpgradedTo201_ThenProjectAsExpected)); + string logFilePath = TestHelper.GetScratchPadPath(string.Concat(nameof(Given191Project_WhenUpgradedTo201_ThenProjectAsExpected), ".log")); var migrator = new ProjectFileMigrator { LogPath = logFilePath @@ -60,12 +60,111 @@ AssertVersions(reader); AssertDatabase(reader); + + AssertGrassCoverErosionInwardsCalculation(reader, sourceFilePath); + AssertGrassCoverErosionInwardsSectionResult(reader, sourceFilePath); } AssertLogDatabase(logFilePath); } } + private static void AssertGrassCoverErosionInwardsCalculation(MigratedDatabaseReader reader, string sourceFilePath) + { + string validateCalculationLinkedToSectionResult = + $"ATTACH DATABASE \"{sourceFilePath}\" AS SOURCEPROJECT; " + + "SELECT COUNT() = " + + "(" + + "SELECT COUNT() " + + "FROM SOURCEPROJECT.GrassCoverErosionInwardsCalculationEntity " + + "JOIN SOURCEPROJECT.GrassCoverErosionInwardsSectionResultEntity USING(GrassCoverErosionInwardsCalculationEntityId) " + + ") " + + "FROM GrassCoverErosionInwardsCalculationEntity NEW " + + "JOIN SOURCEPROJECT.GrassCoverErosionInwardsCalculationEntity OLD USING(GrassCoverErosionInwardsCalculationEntityId) " + + "WHERE NEW.[CalculationGroupEntityId] = OLD.[CalculationGroupEntityId] " + + "AND NEW.[HydraulicLocationEntityId] IS OLD.[HydraulicLocationEntityId] " + + "AND NEW.[DikeProfileEntityId] IS OLD.[DikeProfileEntityId]" + + "AND NEW.\"Order\" = OLD.\"Order\" " + + "AND NEW.[Name] IS OLD.[Name] " + + "AND NEW.[Comments] IS OLD.[Comments] " + + "AND NEW.[Orientation] IS OLD.[Orientation] " + + "AND NEW.[CriticalFlowRateMean] IS OLD.[CriticalFlowRateMean] " + + "AND NEW.[CriticalFlowRateStandardDeviation] IS OLD.[CriticalFlowRateStandardDeviation] " + + "AND NEW.[UseForeshore] = OLD.[UseForeshore] " + + "AND NEW.[DikeHeightCalculationType] = OLD.[DikeHeightCalculationType] " + + "AND NEW.[DikeHeight] IS OLD.[DikeHeight] " + + "AND NEW.[UseBreakWater] = OLD.[UseBreakWater] " + + "AND NEW.[BreakWaterType] IS OLD.[BreakWaterType] " + + "AND NEW.[BreakWaterHeight] IS OLD.[BreakWaterHeight] " + + "AND NEW.[OvertoppingRateCalculationType] = OLD.[OvertoppingRateCalculationType] " + + "AND NEW.[ShouldDikeHeightIllustrationPointsBeCalculated] = OLD.[ShouldDikeHeightIllustrationPointsBeCalculated] " + + "AND NEW.[ShouldOvertoppingRateIllustrationPointsBeCalculated] = OLD.[ShouldOvertoppingRateIllustrationPointsBeCalculated] " + + "AND NEW.[ShouldOvertoppingOutputIllustrationPointsBeCalculated] = OLD.[ShouldOvertoppingOutputIllustrationPointsBeCalculated] " + + "AND NEW.[RelevantForScenario] = 1 " + + "AND NEW.[ScenarioContribution] = 1; " + + "DETACH SOURCEPROJECT;"; + reader.AssertReturnedDataIsValid(validateCalculationLinkedToSectionResult); + + string validateCalculationNotLinkedToSectionResult = + $"ATTACH DATABASE \"{sourceFilePath}\" AS SOURCEPROJECT; " + + "SELECT COUNT() = " + + "(" + + "SELECT COUNT() " + + "FROM SOURCEPROJECT.GrassCoverErosionInwardsCalculationEntity " + + "LEFT JOIN SOURCEPROJECT.GrassCoverErosionInwardsSectionResultEntity " + + "USING(GrassCoverErosionInwardsCalculationEntityId) " + + "WHERE GrassCoverErosionInwardsSectionResultEntityId IS NULL" + + ") " + + "FROM GrassCoverErosionInwardsCalculationEntity NEW " + + "JOIN SOURCEPROJECT.GrassCoverErosionInwardsCalculationEntity OLD USING(GrassCoverErosionInwardsCalculationEntityId) " + + "WHERE NEW.[CalculationGroupEntityId] = OLD.[CalculationGroupEntityId] " + + "AND NEW.[HydraulicLocationEntityId] IS OLD.[HydraulicLocationEntityId] " + + "AND NEW.[DikeProfileEntityId] IS OLD.[DikeProfileEntityId]" + + "AND NEW.\"Order\" = OLD.\"Order\" " + + "AND NEW.[Name] IS OLD.[Name] " + + "AND NEW.[Comments] IS OLD.[Comments] " + + "AND NEW.[Orientation] IS OLD.[Orientation] " + + "AND NEW.[CriticalFlowRateMean] IS OLD.[CriticalFlowRateMean] " + + "AND NEW.[CriticalFlowRateStandardDeviation] IS OLD.[CriticalFlowRateStandardDeviation] " + + "AND NEW.[UseForeshore] = OLD.[UseForeshore] " + + "AND NEW.[DikeHeightCalculationType] = OLD.[DikeHeightCalculationType] " + + "AND NEW.[DikeHeight] IS OLD.[DikeHeight] " + + "AND NEW.[UseBreakWater] = OLD.[UseBreakWater] " + + "AND NEW.[BreakWaterType] IS OLD.[BreakWaterType] " + + "AND NEW.[BreakWaterHeight] IS OLD.[BreakWaterHeight] " + + "AND NEW.[OvertoppingRateCalculationType] = OLD.[OvertoppingRateCalculationType] " + + "AND NEW.[ShouldDikeHeightIllustrationPointsBeCalculated] = OLD.[ShouldDikeHeightIllustrationPointsBeCalculated] " + + "AND NEW.[ShouldOvertoppingRateIllustrationPointsBeCalculated] = OLD.[ShouldOvertoppingRateIllustrationPointsBeCalculated] " + + "AND NEW.[ShouldOvertoppingOutputIllustrationPointsBeCalculated] = OLD.[ShouldOvertoppingOutputIllustrationPointsBeCalculated] " + + "AND NEW.[RelevantForScenario] = 0 " + + "AND NEW.[ScenarioContribution] = 0; " + + "DETACH SOURCEPROJECT;"; + reader.AssertReturnedDataIsValid(validateCalculationNotLinkedToSectionResult); + + } + + private static void AssertGrassCoverErosionInwardsSectionResult(MigratedDatabaseReader reader, string sourceFilePath) + { + string validateSectionResults = + $"ATTACH DATABASE \"{sourceFilePath}\" AS SOURCEPROJECT; " + + "SELECT COUNT() = " + + "(" + + "SELECT COUNT() " + + "FROM SOURCEPROJECT.GrassCoverErosionInwardsSectionResultEntity" + + ") " + + "FROM GrassCoverErosionInwardsSectionResultEntity NEW " + + "JOIN SOURCEPROJECT.GrassCoverErosionInwardsSectionResultEntity OLD USING(GrassCoverErosionInwardsSectionResultEntityId) " + + "WHERE NEW.[FailureMechanismSectionEntityId] = OLD.[FailureMechanismSectionEntityId] " + + "AND NEW.[SimpleAssessmentResult] = OLD.[SimpleAssessmentResult] " + + "AND NEW.[DetailedAssessmentResult] = OLD.[DetailedAssessmentResult] " + + "AND NEW.[TailorMadeAssessmentResult] = OLD.[TailorMadeAssessmentResult] " + + "AND NEW.[TailorMadeAssessmentProbability] IS OLD.[TailorMadeAssessmentProbability] " + + "AND NEW.[UseManualAssembly] = OLD.[UseManualAssembly] " + + "AND NEW.[ManualAssemblyProbability] IS OLD.[ManualAssemblyProbability]; " + + "DETACH SOURCEPROJECT;"; + reader.AssertReturnedDataIsValid(validateSectionResults); + } + private static void AssertTablesContentMigrated(MigratedDatabaseReader reader, string sourceFilePath) { string[] tables = @@ -96,12 +195,10 @@ "GeneralResultFaultTreeIllustrationPointStochastEntity", "GeneralResultSubMechanismIllustrationPointEntity", "GeneralResultSubMechanismIllustrationPointStochastEntity", - "GrassCoverErosionInwardsCalculationEntity", "GrassCoverErosionInwardsDikeHeightOutputEntity", "GrassCoverErosionInwardsFailureMechanismMetaEntity", "GrassCoverErosionInwardsOutputEntity", "GrassCoverErosionInwardsOvertoppingRateOutputEntity", - "GrassCoverErosionInwardsSectionResultEntity", "GrassCoverErosionOutwardsFailureMechanismMetaEntity", "GrassCoverErosionOutwardsSectionResultEntity", "GrassCoverErosionOutwardsWaveConditionsCalculationEntity",