From 3e732f728c606cd4d1e2b3687400484a502aa1e0 Mon Sep 17 00:00:00 2001 From: Eric Sibly Date: Wed, 4 Oct 2023 08:32:46 -0700 Subject: [PATCH] Fix setting of completed date on reset. --- CHANGELOG.md | 3 +++ Common.targets | 2 +- .../Stored Procedures/Generated/spContactBatchReset.sql | 9 ++++++--- .../Stored Procedures/Generated/spContactBatchReset.sql | 9 ++++++--- .../Stored Procedures/Generated/spCustomerBatchReset.sql | 9 ++++++--- .../Stored Procedures/Generated/spPostsBatchReset.sql | 9 ++++++--- tools/NTangle.CodeGen/Templates/SpResetBatch_sql.hbs | 9 ++++++--- 7 files changed, 34 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e2339af..e6e6575 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ Represents the **NuGet** versions. +## v2.3.3 +- *Fixed:* Stored procedure `spXxxBatchReset` updated to correctly set the completed date within the batch tracking table. + ## v2.3.2 - *Enhancement:* Added new `spXxxBatchReset` stored procedure to reset the bacth tracking to the latest lsn. Can be used to fix data loss batch by completing with the latest lsn. Also useful to support unit testing. - *Fixed:* Updated `DbEx` (`v2.3.11`) and `CoreEx` (`v3.3.1`). diff --git a/Common.targets b/Common.targets index 459246d..a14403d 100644 --- a/Common.targets +++ b/Common.targets @@ -1,6 +1,6 @@ - 2.3.2 + 2.3.3 true NTangle Developers Avanade diff --git a/samples/ContactSync/ContactSync.OldApp/ContactSync.OldApp.Database/Schema/NTangle/Stored Procedures/Generated/spContactBatchReset.sql b/samples/ContactSync/ContactSync.OldApp/ContactSync.OldApp.Database/Schema/NTangle/Stored Procedures/Generated/spContactBatchReset.sql index 0afcae5..d75661f 100644 --- a/samples/ContactSync/ContactSync.OldApp/ContactSync.OldApp.Database/Schema/NTangle/Stored Procedures/Generated/spContactBatchReset.sql +++ b/samples/ContactSync/ContactSync.OldApp/ContactSync.OldApp.Database/Schema/NTangle/Stored Procedures/Generated/spContactBatchReset.sql @@ -12,15 +12,16 @@ BEGIN BEGIN TRANSACTION -- Get the maximum lsn. - DECLARE @MaxLsn BINARY(10) + DECLARE @MaxLsn BINARY(10), @CompletedDate DATETIME2; SET @MaxLsn = sys.fn_cdc_get_max_lsn(); + SET @CompletedDate = GETUTCDATE(); -- Complete any incomplete batch (with data loss) with max lsn. UPDATE [_batch] SET [_batch].[ContactMaxLsn] = @MaxLsn, [_batch].[AddressMaxLsn] = @MaxLsn, [_batch].[IsComplete] = 1, - [_batch].[CompletedDate] = GETUTCDATE(), + [_batch].[CompletedDate] = @CompletedDate, [_batch].[HasDataLoss] = 1 FROM [NTangle].[ContactBatchTracking] AS [_batch] WHERE [_batch].[IsComplete] = 0; @@ -34,6 +35,7 @@ BEGIN [AddressMinLsn], [AddressMaxLsn], [CreatedDate], + [CompletedDate], [IsComplete], [CorrelationId], [HasDataLoss] @@ -43,7 +45,8 @@ BEGIN @MaxLsn, @MaxLsn, @MaxLsn, - GETUTCDATE(), + @CompletedDate, + @CompletedDate, 1, LOWER(CONVERT(NVARCHAR(64), NEWID())), 1 diff --git a/samples/SqlServerDemo/SqlServerDemo.Database/Schema/NTangle/Stored Procedures/Generated/spContactBatchReset.sql b/samples/SqlServerDemo/SqlServerDemo.Database/Schema/NTangle/Stored Procedures/Generated/spContactBatchReset.sql index 0afcae5..d75661f 100644 --- a/samples/SqlServerDemo/SqlServerDemo.Database/Schema/NTangle/Stored Procedures/Generated/spContactBatchReset.sql +++ b/samples/SqlServerDemo/SqlServerDemo.Database/Schema/NTangle/Stored Procedures/Generated/spContactBatchReset.sql @@ -12,15 +12,16 @@ BEGIN BEGIN TRANSACTION -- Get the maximum lsn. - DECLARE @MaxLsn BINARY(10) + DECLARE @MaxLsn BINARY(10), @CompletedDate DATETIME2; SET @MaxLsn = sys.fn_cdc_get_max_lsn(); + SET @CompletedDate = GETUTCDATE(); -- Complete any incomplete batch (with data loss) with max lsn. UPDATE [_batch] SET [_batch].[ContactMaxLsn] = @MaxLsn, [_batch].[AddressMaxLsn] = @MaxLsn, [_batch].[IsComplete] = 1, - [_batch].[CompletedDate] = GETUTCDATE(), + [_batch].[CompletedDate] = @CompletedDate, [_batch].[HasDataLoss] = 1 FROM [NTangle].[ContactBatchTracking] AS [_batch] WHERE [_batch].[IsComplete] = 0; @@ -34,6 +35,7 @@ BEGIN [AddressMinLsn], [AddressMaxLsn], [CreatedDate], + [CompletedDate], [IsComplete], [CorrelationId], [HasDataLoss] @@ -43,7 +45,8 @@ BEGIN @MaxLsn, @MaxLsn, @MaxLsn, - GETUTCDATE(), + @CompletedDate, + @CompletedDate, 1, LOWER(CONVERT(NVARCHAR(64), NEWID())), 1 diff --git a/samples/SqlServerDemo/SqlServerDemo.Database/Schema/NTangle/Stored Procedures/Generated/spCustomerBatchReset.sql b/samples/SqlServerDemo/SqlServerDemo.Database/Schema/NTangle/Stored Procedures/Generated/spCustomerBatchReset.sql index 83786b0..f1751a8 100644 --- a/samples/SqlServerDemo/SqlServerDemo.Database/Schema/NTangle/Stored Procedures/Generated/spCustomerBatchReset.sql +++ b/samples/SqlServerDemo/SqlServerDemo.Database/Schema/NTangle/Stored Procedures/Generated/spCustomerBatchReset.sql @@ -12,14 +12,15 @@ BEGIN BEGIN TRANSACTION -- Get the maximum lsn. - DECLARE @MaxLsn BINARY(10) + DECLARE @MaxLsn BINARY(10), @CompletedDate DATETIME2; SET @MaxLsn = sys.fn_cdc_get_max_lsn(); + SET @CompletedDate = GETUTCDATE(); -- Complete any incomplete batch (with data loss) with max lsn. UPDATE [_batch] SET [_batch].[CustomerMaxLsn] = @MaxLsn, [_batch].[IsComplete] = 1, - [_batch].[CompletedDate] = GETUTCDATE(), + [_batch].[CompletedDate] = @CompletedDate, [_batch].[HasDataLoss] = 1 FROM [NTangle].[CustomerBatchTracking] AS [_batch] WHERE [_batch].[IsComplete] = 0; @@ -31,6 +32,7 @@ BEGIN [CustomerMinLsn], [CustomerMaxLsn], [CreatedDate], + [CompletedDate], [IsComplete], [CorrelationId], [HasDataLoss] @@ -38,7 +40,8 @@ BEGIN VALUES ( @MaxLsn, @MaxLsn, - GETUTCDATE(), + @CompletedDate, + @CompletedDate, 1, LOWER(CONVERT(NVARCHAR(64), NEWID())), 1 diff --git a/samples/SqlServerDemo/SqlServerDemo.Database/Schema/NTangle/Stored Procedures/Generated/spPostsBatchReset.sql b/samples/SqlServerDemo/SqlServerDemo.Database/Schema/NTangle/Stored Procedures/Generated/spPostsBatchReset.sql index db91bb7..9e26f16 100644 --- a/samples/SqlServerDemo/SqlServerDemo.Database/Schema/NTangle/Stored Procedures/Generated/spPostsBatchReset.sql +++ b/samples/SqlServerDemo/SqlServerDemo.Database/Schema/NTangle/Stored Procedures/Generated/spPostsBatchReset.sql @@ -12,8 +12,9 @@ BEGIN BEGIN TRANSACTION -- Get the maximum lsn. - DECLARE @MaxLsn BINARY(10) + DECLARE @MaxLsn BINARY(10), @CompletedDate DATETIME2; SET @MaxLsn = sys.fn_cdc_get_max_lsn(); + SET @CompletedDate = GETUTCDATE(); -- Complete any incomplete batch (with data loss) with max lsn. UPDATE [_batch] SET @@ -22,7 +23,7 @@ BEGIN [_batch].[CommentsTagsMaxLsn] = @MaxLsn, [_batch].[PostsTagsMaxLsn] = @MaxLsn, [_batch].[IsComplete] = 1, - [_batch].[CompletedDate] = GETUTCDATE(), + [_batch].[CompletedDate] = @CompletedDate, [_batch].[HasDataLoss] = 1 FROM [NTangle].[PostsBatchTracking] AS [_batch] WHERE [_batch].[IsComplete] = 0; @@ -40,6 +41,7 @@ BEGIN [PostsTagsMinLsn], [PostsTagsMaxLsn], [CreatedDate], + [CompletedDate], [IsComplete], [CorrelationId], [HasDataLoss] @@ -53,7 +55,8 @@ BEGIN @MaxLsn, @MaxLsn, @MaxLsn, - GETUTCDATE(), + @CompletedDate, + @CompletedDate, 1, LOWER(CONVERT(NVARCHAR(64), NEWID())), 1 diff --git a/tools/NTangle.CodeGen/Templates/SpResetBatch_sql.hbs b/tools/NTangle.CodeGen/Templates/SpResetBatch_sql.hbs index 7c11336..8e6745a 100644 --- a/tools/NTangle.CodeGen/Templates/SpResetBatch_sql.hbs +++ b/tools/NTangle.CodeGen/Templates/SpResetBatch_sql.hbs @@ -13,8 +13,9 @@ BEGIN BEGIN TRANSACTION -- Get the maximum lsn. - DECLARE @MaxLsn BINARY(10) + DECLARE @MaxLsn BINARY(10), @CompletedDate DATETIME2; SET @MaxLsn = sys.fn_cdc_get_max_lsn(); + SET @CompletedDate = GETUTCDATE(); -- Complete any incomplete batch (with data loss) with max lsn. UPDATE [_batch] SET @@ -23,7 +24,7 @@ BEGIN [_batch].[{{pascal Name}}MaxLsn] = @MaxLsn, {{/each}} [_batch].[IsComplete] = 1, - [_batch].[CompletedDate] = GETUTCDATE(), + [_batch].[CompletedDate] = @CompletedDate, [_batch].[HasDataLoss] = 1 FROM [{{CdcSchema}}].[{{BatchTrackingTable}}] AS [_batch] WHERE [_batch].[IsComplete] = 0; @@ -39,6 +40,7 @@ BEGIN [{{pascal Name}}MaxLsn], {{/each}} [CreatedDate], + [CompletedDate], [IsComplete], [CorrelationId], [HasDataLoss] @@ -50,7 +52,8 @@ BEGIN @MaxLsn, @MaxLsn, {{/each}} - GETUTCDATE(), + @CompletedDate, + @CompletedDate, 1, LOWER(CONVERT(NVARCHAR(64), NEWID())), 1