1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-01 16:12:49 -05:00

[AC-2323] Added script to migrate all sql organizations to use flexible collections

This commit is contained in:
Rui Tome
2024-03-25 16:16:56 +00:00
parent 1a066d886c
commit 1de0f32f6e

View File

@ -0,0 +1,37 @@
-- This script will enable collection enhancements for organizations that don't have Collection Enhancements enabled.
-- Step 1: Insert into a temporary table, selecting a percentage of the rows for each distinct PlanType
SELECT [Id] AS [OrganizationId]
INTO #TempOrg
FROM [dbo].[Organization]
WHERE [FlexibleCollections] = 0
-- Step 2: Execute the stored procedure for each OrganizationId
DECLARE @OrganizationId UNIQUEIDENTIFIER;
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 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;
-- Step 3: Drop the temporary table
DROP TABLE #TempOrg;