From 96b5278d7cf658114d0b1e5a19c2edd55719bddc Mon Sep 17 00:00:00 2001 From: Rui Tome Date: Thu, 11 Jan 2024 18:31:47 +0000 Subject: [PATCH] [AC-1682] Removed batching from AllOrgsEnableCollectionEnhancements script --- ...00_AllOrgsEnableCollectionEnhancements.sql | 58 ++++++++----------- 1 file changed, 23 insertions(+), 35 deletions(-) diff --git a/util/Migrator/DbScripts_transition/2024-01-10_00_AllOrgsEnableCollectionEnhancements.sql b/util/Migrator/DbScripts_transition/2024-01-10_00_AllOrgsEnableCollectionEnhancements.sql index 1df22f2b26..e13232f7e4 100644 --- a/util/Migrator/DbScripts_transition/2024-01-10_00_AllOrgsEnableCollectionEnhancements.sql +++ b/util/Migrator/DbScripts_transition/2024-01-10_00_AllOrgsEnableCollectionEnhancements.sql @@ -1,49 +1,37 @@ -- This script will enable collection enhancements for all organizations that have not yet migrated. --- Step 1: Insert into a temporary table with an additional column for batch processing, update 50 k at a time -SELECT [Id] AS [OrganizationId], CAST(ROW_NUMBER() OVER(ORDER BY [Id]) / 50000 AS INT) AS Batch +-- Step 1: Insert into a temporary table +SELECT [Id] AS [OrganizationId] INTO #TempOrg FROM [dbo].[Organization] WHERE [FlexibleCollections] = 0; --- Step 2: Get the maximum batch number -DECLARE @MaxBatch INT = (SELECT MAX(Batch) FROM #TempOrg); -DECLARE @CurrentBatch INT = 0; +-- Step 2: Execute the stored procedure for each OrganizationId +DECLARE @OrganizationId UNIQUEIDENTIFIER; --- Step 3: Process each batch -WHILE @CurrentBatch <= @MaxBatch +DECLARE OrgCursor CURSOR FOR +SELECT [OrganizationId] +FROM #TempOrg; + +OPEN OrgCursor; + +FETCH NEXT FROM OrgCursor INTO @OrganizationId; + +WHILE (@@FETCH_STATUS = 0) BEGIN - -- Execute the stored procedure for each OrganizationId in the current batch - DECLARE @OrganizationId UNIQUEIDENTIFIER; + -- Execute the stored procedure for the current OrganizationId + EXEC [dbo].[Organization_EnableCollectionEnhancements] @OrganizationId; - DECLARE OrgCursor CURSOR FOR - SELECT [OrganizationId] - FROM #TempOrg - WHERE [Batch] = @CurrentBatch; - - OPEN OrgCursor; + -- Update the Organization to set FlexibleCollections = 1 + UPDATE [dbo].[Organization] + SET [FlexibleCollections] = 1 + WHERE [Id] = @OrganizationId; FETCH NEXT FROM OrgCursor INTO @OrganizationId; - - WHILE (@@FETCH_STATUS = 0) - BEGIN - -- Execute the stored procedure for the current OrganizationId - EXEC [dbo].[Organization_EnableCollectionEnhancements] @OrganizationId; - - -- Update the Organization to set FlexibleCollections = 1 - UPDATE [dbo].[Organization] - SET [FlexibleCollections] = 1 - WHERE [Id] = @OrganizationId; - - FETCH NEXT FROM OrgCursor INTO @OrganizationId; - END; - - CLOSE OrgCursor; - DEALLOCATE OrgCursor; - - -- Move to the next batch - SET @CurrentBatch = @CurrentBatch + 1; END; --- Step 4: Drop the temporary table +CLOSE OrgCursor; +DEALLOCATE OrgCursor; + +-- Step 3: Drop the temporary table DROP TABLE #TempOrg;