From 1de0f32f6e55738d6186b261939df37c1cf5b339 Mon Sep 17 00:00:00 2001 From: Rui Tome Date: Mon, 25 Mar 2024 16:16:56 +0000 Subject: [PATCH] =?UTF-8?q?[AC-2323]=C2=A0Added=20script=20to=20migrate=20?= =?UTF-8?q?all=20sql=20organizations=20to=20use=20flexible=20collections?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ..._00_EnableAllOrgCollectionEnhancements.sql | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 util/Migrator/DbScripts/2024-03-25_00_EnableAllOrgCollectionEnhancements.sql diff --git a/util/Migrator/DbScripts/2024-03-25_00_EnableAllOrgCollectionEnhancements.sql b/util/Migrator/DbScripts/2024-03-25_00_EnableAllOrgCollectionEnhancements.sql new file mode 100644 index 0000000000..eb5b44c5d1 --- /dev/null +++ b/util/Migrator/DbScripts/2024-03-25_00_EnableAllOrgCollectionEnhancements.sql @@ -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;