mirror of
https://github.com/bitwarden/server.git
synced 2025-07-01 16:12:49 -05:00
[AC-1682] Removed batching from AllOrgsEnableCollectionEnhancements script
This commit is contained in:
@ -1,49 +1,37 @@
|
|||||||
-- This script will enable collection enhancements for all organizations that have not yet migrated.
|
-- 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
|
-- Step 1: Insert into a temporary table
|
||||||
SELECT [Id] AS [OrganizationId], CAST(ROW_NUMBER() OVER(ORDER BY [Id]) / 50000 AS INT) AS Batch
|
SELECT [Id] AS [OrganizationId]
|
||||||
INTO #TempOrg
|
INTO #TempOrg
|
||||||
FROM [dbo].[Organization]
|
FROM [dbo].[Organization]
|
||||||
WHERE [FlexibleCollections] = 0;
|
WHERE [FlexibleCollections] = 0;
|
||||||
|
|
||||||
-- Step 2: Get the maximum batch number
|
-- Step 2: Execute the stored procedure for each OrganizationId
|
||||||
DECLARE @MaxBatch INT = (SELECT MAX(Batch) FROM #TempOrg);
|
DECLARE @OrganizationId UNIQUEIDENTIFIER;
|
||||||
DECLARE @CurrentBatch INT = 0;
|
|
||||||
|
|
||||||
-- Step 3: Process each batch
|
DECLARE OrgCursor CURSOR FOR
|
||||||
WHILE @CurrentBatch <= @MaxBatch
|
SELECT [OrganizationId]
|
||||||
|
FROM #TempOrg;
|
||||||
|
|
||||||
|
OPEN OrgCursor;
|
||||||
|
|
||||||
|
FETCH NEXT FROM OrgCursor INTO @OrganizationId;
|
||||||
|
|
||||||
|
WHILE (@@FETCH_STATUS = 0)
|
||||||
BEGIN
|
BEGIN
|
||||||
-- Execute the stored procedure for each OrganizationId in the current batch
|
-- Execute the stored procedure for the current OrganizationId
|
||||||
DECLARE @OrganizationId UNIQUEIDENTIFIER;
|
EXEC [dbo].[Organization_EnableCollectionEnhancements] @OrganizationId;
|
||||||
|
|
||||||
DECLARE OrgCursor CURSOR FOR
|
-- Update the Organization to set FlexibleCollections = 1
|
||||||
SELECT [OrganizationId]
|
UPDATE [dbo].[Organization]
|
||||||
FROM #TempOrg
|
SET [FlexibleCollections] = 1
|
||||||
WHERE [Batch] = @CurrentBatch;
|
WHERE [Id] = @OrganizationId;
|
||||||
|
|
||||||
OPEN OrgCursor;
|
|
||||||
|
|
||||||
FETCH NEXT FROM OrgCursor INTO @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;
|
END;
|
||||||
|
|
||||||
-- Step 4: Drop the temporary table
|
CLOSE OrgCursor;
|
||||||
|
DEALLOCATE OrgCursor;
|
||||||
|
|
||||||
|
-- Step 3: Drop the temporary table
|
||||||
DROP TABLE #TempOrg;
|
DROP TABLE #TempOrg;
|
||||||
|
Reference in New Issue
Block a user