mirror of
https://github.com/bitwarden/server.git
synced 2025-07-04 01:22:50 -05:00
[AC-1682] Placed temp tables outside transactions
This commit is contained in:
@ -5,8 +5,6 @@ BEGIN
|
|||||||
SET NOCOUNT ON
|
SET NOCOUNT ON
|
||||||
|
|
||||||
-- Step 1: AccessAll migration for Groups
|
-- Step 1: AccessAll migration for Groups
|
||||||
BEGIN TRY
|
|
||||||
BEGIN TRANSACTION;
|
|
||||||
-- Create a temporary table to store the groups with AccessAll = 1
|
-- Create a temporary table to store the groups with AccessAll = 1
|
||||||
SELECT [Id] AS [GroupId], [OrganizationId]
|
SELECT [Id] AS [GroupId], [OrganizationId]
|
||||||
INTO #TempGroup
|
INTO #TempGroup
|
||||||
@ -14,6 +12,14 @@ BEGIN
|
|||||||
WHERE [AccessAll] = 1
|
WHERE [AccessAll] = 1
|
||||||
AND [OrganizationId] = @OrganizationId;
|
AND [OrganizationId] = @OrganizationId;
|
||||||
|
|
||||||
|
-- Create a temporary table to store distinct OrganizationUserIds
|
||||||
|
SELECT DISTINCT GU.[OrganizationUserId]
|
||||||
|
INTO #TempOrganizationUsers
|
||||||
|
FROM [dbo].[GroupUser] GU
|
||||||
|
JOIN #TempGroup TG ON GU.[GroupId] = TG.[GroupId];
|
||||||
|
|
||||||
|
BEGIN TRY
|
||||||
|
BEGIN TRANSACTION;
|
||||||
-- Update existing rows in [dbo].[CollectionGroup]
|
-- Update existing rows in [dbo].[CollectionGroup]
|
||||||
UPDATE CG
|
UPDATE CG
|
||||||
SET
|
SET
|
||||||
@ -39,12 +45,6 @@ BEGIN
|
|||||||
FROM [dbo].[Group] G
|
FROM [dbo].[Group] G
|
||||||
INNER JOIN #TempGroup TG ON G.[Id] = TG.[GroupId]
|
INNER JOIN #TempGroup TG ON G.[Id] = TG.[GroupId]
|
||||||
|
|
||||||
-- Create a temporary table to store distinct OrganizationUserIds
|
|
||||||
SELECT DISTINCT GU.[OrganizationUserId]
|
|
||||||
INTO #TempOrganizationUsers
|
|
||||||
FROM [dbo].[GroupUser] GU
|
|
||||||
JOIN #TempGroup TG ON GU.[GroupId] = TG.[GroupId];
|
|
||||||
|
|
||||||
-- Execute User_BumpAccountRevisionDateByOrganizationUserId for each unique OrganizationUserId
|
-- Execute User_BumpAccountRevisionDateByOrganizationUserId for each unique OrganizationUserId
|
||||||
DECLARE @Step1OrganizationUserId UNIQUEIDENTIFIER
|
DECLARE @Step1OrganizationUserId UNIQUEIDENTIFIER
|
||||||
|
|
||||||
@ -66,10 +66,6 @@ BEGIN
|
|||||||
|
|
||||||
CLOSE UniqueOrgUserIdCursor
|
CLOSE UniqueOrgUserIdCursor
|
||||||
DEALLOCATE UniqueOrgUserIdCursor;
|
DEALLOCATE UniqueOrgUserIdCursor;
|
||||||
|
|
||||||
-- Drop the temporary table
|
|
||||||
DROP TABLE #TempGroup;
|
|
||||||
DROP TABLE #TempOrganizationUsers;
|
|
||||||
COMMIT TRANSACTION;
|
COMMIT TRANSACTION;
|
||||||
END TRY
|
END TRY
|
||||||
BEGIN CATCH
|
BEGIN CATCH
|
||||||
@ -77,9 +73,11 @@ BEGIN
|
|||||||
THROW;
|
THROW;
|
||||||
END CATCH;
|
END CATCH;
|
||||||
|
|
||||||
|
-- Drop the temporary table
|
||||||
|
DROP TABLE #TempGroup;
|
||||||
|
DROP TABLE #TempOrganizationUsers;
|
||||||
|
|
||||||
-- Step 2: AccessAll migration for users
|
-- Step 2: AccessAll migration for users
|
||||||
BEGIN TRY
|
|
||||||
BEGIN TRANSACTION;
|
|
||||||
-- Create a temporary table to store the OrganizationUsers with AccessAll = 1
|
-- Create a temporary table to store the OrganizationUsers with AccessAll = 1
|
||||||
SELECT [Id] AS [OrganizationUserId], [OrganizationId]
|
SELECT [Id] AS [OrganizationUserId], [OrganizationId]
|
||||||
INTO #TempOrgUser
|
INTO #TempOrgUser
|
||||||
@ -87,6 +85,8 @@ BEGIN
|
|||||||
WHERE [AccessAll] = 1
|
WHERE [AccessAll] = 1
|
||||||
AND [OrganizationId] = @OrganizationId;
|
AND [OrganizationId] = @OrganizationId;
|
||||||
|
|
||||||
|
BEGIN TRY
|
||||||
|
BEGIN TRANSACTION;
|
||||||
-- Update existing rows in [dbo].[CollectionUser]
|
-- Update existing rows in [dbo].[CollectionUser]
|
||||||
UPDATE target
|
UPDATE target
|
||||||
SET
|
SET
|
||||||
@ -140,9 +140,6 @@ BEGIN
|
|||||||
|
|
||||||
CLOSE UniqueOrgUserIdCursor
|
CLOSE UniqueOrgUserIdCursor
|
||||||
DEALLOCATE UniqueOrgUserIdCursor;
|
DEALLOCATE UniqueOrgUserIdCursor;
|
||||||
|
|
||||||
-- Drop the temporary table
|
|
||||||
DROP TABLE #TempOrgUser;
|
|
||||||
COMMIT TRANSACTION;
|
COMMIT TRANSACTION;
|
||||||
END TRY
|
END TRY
|
||||||
BEGIN CATCH
|
BEGIN CATCH
|
||||||
@ -150,9 +147,10 @@ BEGIN
|
|||||||
THROW;
|
THROW;
|
||||||
END CATCH;
|
END CATCH;
|
||||||
|
|
||||||
|
-- Drop the temporary table
|
||||||
|
DROP TABLE #TempOrgUser;
|
||||||
|
|
||||||
-- Step 3: Update [dbo].[CollectionUser] with [Manage] = 1 for all users with Manager role or 'EditAssignedCollections' permission
|
-- Step 3: Update [dbo].[CollectionUser] with [Manage] = 1 for all users with Manager role or 'EditAssignedCollections' permission
|
||||||
BEGIN TRY
|
|
||||||
BEGIN TRANSACTION;
|
|
||||||
-- Store the results in a temporary table
|
-- Store the results in a temporary table
|
||||||
SELECT ou.[Id] AS [OrganizationUserId]
|
SELECT ou.[Id] AS [OrganizationUserId]
|
||||||
INTO #TempStep3
|
INTO #TempStep3
|
||||||
@ -160,6 +158,8 @@ BEGIN
|
|||||||
WHERE (ou.[Type] = 3 OR (ou.[Permissions] IS NOT NULL AND
|
WHERE (ou.[Type] = 3 OR (ou.[Permissions] IS NOT NULL AND
|
||||||
ISJSON(ou.[Permissions]) > 0 AND JSON_VALUE(ou.[Permissions], '$.editAssignedCollections') = 'true'));
|
ISJSON(ou.[Permissions]) > 0 AND JSON_VALUE(ou.[Permissions], '$.editAssignedCollections') = 'true'));
|
||||||
|
|
||||||
|
BEGIN TRY
|
||||||
|
BEGIN TRANSACTION;
|
||||||
-- Update [dbo].[CollectionUser] with [Manage] = 1 using the temporary table
|
-- Update [dbo].[CollectionUser] with [Manage] = 1 using the temporary table
|
||||||
UPDATE cu
|
UPDATE cu
|
||||||
SET cu.[ReadOnly] = 0,
|
SET cu.[ReadOnly] = 0,
|
||||||
@ -189,9 +189,6 @@ BEGIN
|
|||||||
|
|
||||||
CLOSE UniqueOrgUserIdCursor
|
CLOSE UniqueOrgUserIdCursor
|
||||||
DEALLOCATE UniqueOrgUserIdCursor;
|
DEALLOCATE UniqueOrgUserIdCursor;
|
||||||
|
|
||||||
-- Drop the temporary table
|
|
||||||
DROP TABLE #TempStep3;
|
|
||||||
COMMIT TRANSACTION;
|
COMMIT TRANSACTION;
|
||||||
END TRY
|
END TRY
|
||||||
BEGIN CATCH
|
BEGIN CATCH
|
||||||
@ -199,9 +196,10 @@ BEGIN
|
|||||||
THROW;
|
THROW;
|
||||||
END CATCH;
|
END CATCH;
|
||||||
|
|
||||||
|
-- Drop the temporary table
|
||||||
|
DROP TABLE #TempStep3;
|
||||||
|
|
||||||
-- Step 4: Insert rows to [dbo].[CollectionUser] for Managers and users with 'EditAssignedCollections' permission assigned to groups with collection access
|
-- Step 4: Insert rows to [dbo].[CollectionUser] for Managers and users with 'EditAssignedCollections' permission assigned to groups with collection access
|
||||||
BEGIN TRY
|
|
||||||
BEGIN TRANSACTION;
|
|
||||||
-- Store the results in a temporary table
|
-- Store the results in a temporary table
|
||||||
SELECT cg.[CollectionId], ou.[Id] AS [OrganizationUserId]
|
SELECT cg.[CollectionId], ou.[Id] AS [OrganizationUserId]
|
||||||
INTO #TempStep4
|
INTO #TempStep4
|
||||||
@ -214,6 +212,8 @@ BEGIN
|
|||||||
WHERE cu.[CollectionId] = cg.[CollectionId] AND cu.[OrganizationUserId] = ou.[Id]
|
WHERE cu.[CollectionId] = cg.[CollectionId] AND cu.[OrganizationUserId] = ou.[Id]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
BEGIN TRY
|
||||||
|
BEGIN TRANSACTION;
|
||||||
-- Insert rows into [dbo].[CollectionUser] using the temporary table
|
-- Insert rows into [dbo].[CollectionUser] using the temporary table
|
||||||
INSERT INTO [dbo].[CollectionUser] ([CollectionId], [OrganizationUserId], [ReadOnly], [HidePasswords], [Manage])
|
INSERT INTO [dbo].[CollectionUser] ([CollectionId], [OrganizationUserId], [ReadOnly], [HidePasswords], [Manage])
|
||||||
SELECT [CollectionId], [OrganizationUserId], 0, 0, 1
|
SELECT [CollectionId], [OrganizationUserId], 0, 0, 1
|
||||||
@ -240,9 +240,6 @@ BEGIN
|
|||||||
|
|
||||||
CLOSE UniqueOrgUserIdCursor
|
CLOSE UniqueOrgUserIdCursor
|
||||||
DEALLOCATE UniqueOrgUserIdCursor;
|
DEALLOCATE UniqueOrgUserIdCursor;
|
||||||
|
|
||||||
-- Drop the temporary table
|
|
||||||
DROP TABLE #TempStep4;
|
|
||||||
COMMIT TRANSACTION;
|
COMMIT TRANSACTION;
|
||||||
END TRY
|
END TRY
|
||||||
BEGIN CATCH
|
BEGIN CATCH
|
||||||
@ -250,15 +247,18 @@ BEGIN
|
|||||||
THROW;
|
THROW;
|
||||||
END CATCH;
|
END CATCH;
|
||||||
|
|
||||||
|
-- Drop the temporary table
|
||||||
|
DROP TABLE #TempStep4;
|
||||||
|
|
||||||
-- Step 5: Set all Managers to Users
|
-- Step 5: Set all Managers to Users
|
||||||
BEGIN TRY
|
|
||||||
BEGIN TRANSACTION;
|
|
||||||
-- Store the results in a temporary table
|
-- Store the results in a temporary table
|
||||||
SELECT [Id] AS [OrganizationUserId]
|
SELECT [Id] AS [OrganizationUserId]
|
||||||
INTO #TempStep5
|
INTO #TempStep5
|
||||||
FROM [dbo].[OrganizationUser]
|
FROM [dbo].[OrganizationUser]
|
||||||
WHERE [Type] = 3; -- Manager
|
WHERE [Type] = 3; -- Manager
|
||||||
|
|
||||||
|
BEGIN TRY
|
||||||
|
BEGIN TRANSACTION;
|
||||||
-- Update [dbo].[OrganizationUser] based on the temporary table
|
-- Update [dbo].[OrganizationUser] based on the temporary table
|
||||||
UPDATE ou
|
UPDATE ou
|
||||||
SET ou.[Type] = 2 -- User
|
SET ou.[Type] = 2 -- User
|
||||||
@ -286,14 +286,14 @@ BEGIN
|
|||||||
|
|
||||||
CLOSE UniqueOrgUserIdCursor
|
CLOSE UniqueOrgUserIdCursor
|
||||||
DEALLOCATE UniqueOrgUserIdCursor;
|
DEALLOCATE UniqueOrgUserIdCursor;
|
||||||
|
|
||||||
-- Drop the temporary table
|
|
||||||
DROP TABLE #TempStep5;
|
|
||||||
COMMIT TRANSACTION;
|
COMMIT TRANSACTION;
|
||||||
END TRY
|
END TRY
|
||||||
BEGIN CATCH
|
BEGIN CATCH
|
||||||
ROLLBACK TRANSACTION;
|
ROLLBACK TRANSACTION;
|
||||||
THROW;
|
THROW;
|
||||||
END CATCH;
|
END CATCH;
|
||||||
|
|
||||||
|
-- Drop the temporary table
|
||||||
|
DROP TABLE #TempStep5;
|
||||||
END
|
END
|
||||||
GO
|
GO
|
||||||
|
@ -5,8 +5,6 @@ BEGIN
|
|||||||
SET NOCOUNT ON
|
SET NOCOUNT ON
|
||||||
|
|
||||||
-- Step 1: AccessAll migration for Groups
|
-- Step 1: AccessAll migration for Groups
|
||||||
BEGIN TRY
|
|
||||||
BEGIN TRANSACTION;
|
|
||||||
-- Create a temporary table to store the groups with AccessAll = 1
|
-- Create a temporary table to store the groups with AccessAll = 1
|
||||||
SELECT [Id] AS [GroupId], [OrganizationId]
|
SELECT [Id] AS [GroupId], [OrganizationId]
|
||||||
INTO #TempGroup
|
INTO #TempGroup
|
||||||
@ -14,6 +12,14 @@ BEGIN
|
|||||||
WHERE [AccessAll] = 1
|
WHERE [AccessAll] = 1
|
||||||
AND [OrganizationId] = @OrganizationId;
|
AND [OrganizationId] = @OrganizationId;
|
||||||
|
|
||||||
|
-- Create a temporary table to store distinct OrganizationUserIds
|
||||||
|
SELECT DISTINCT GU.[OrganizationUserId]
|
||||||
|
INTO #TempOrganizationUsers
|
||||||
|
FROM [dbo].[GroupUser] GU
|
||||||
|
JOIN #TempGroup TG ON GU.[GroupId] = TG.[GroupId];
|
||||||
|
|
||||||
|
BEGIN TRY
|
||||||
|
BEGIN TRANSACTION;
|
||||||
-- Update existing rows in [dbo].[CollectionGroup]
|
-- Update existing rows in [dbo].[CollectionGroup]
|
||||||
UPDATE CG
|
UPDATE CG
|
||||||
SET
|
SET
|
||||||
@ -39,12 +45,6 @@ BEGIN
|
|||||||
FROM [dbo].[Group] G
|
FROM [dbo].[Group] G
|
||||||
INNER JOIN #TempGroup TG ON G.[Id] = TG.[GroupId]
|
INNER JOIN #TempGroup TG ON G.[Id] = TG.[GroupId]
|
||||||
|
|
||||||
-- Create a temporary table to store distinct OrganizationUserIds
|
|
||||||
SELECT DISTINCT GU.[OrganizationUserId]
|
|
||||||
INTO #TempOrganizationUsers
|
|
||||||
FROM [dbo].[GroupUser] GU
|
|
||||||
JOIN #TempGroup TG ON GU.[GroupId] = TG.[GroupId];
|
|
||||||
|
|
||||||
-- Execute User_BumpAccountRevisionDateByOrganizationUserId for each unique OrganizationUserId
|
-- Execute User_BumpAccountRevisionDateByOrganizationUserId for each unique OrganizationUserId
|
||||||
DECLARE @Step1OrganizationUserId UNIQUEIDENTIFIER
|
DECLARE @Step1OrganizationUserId UNIQUEIDENTIFIER
|
||||||
|
|
||||||
@ -66,10 +66,6 @@ BEGIN
|
|||||||
|
|
||||||
CLOSE UniqueOrgUserIdCursor
|
CLOSE UniqueOrgUserIdCursor
|
||||||
DEALLOCATE UniqueOrgUserIdCursor;
|
DEALLOCATE UniqueOrgUserIdCursor;
|
||||||
|
|
||||||
-- Drop the temporary table
|
|
||||||
DROP TABLE #TempGroup;
|
|
||||||
DROP TABLE #TempOrganizationUsers;
|
|
||||||
COMMIT TRANSACTION;
|
COMMIT TRANSACTION;
|
||||||
END TRY
|
END TRY
|
||||||
BEGIN CATCH
|
BEGIN CATCH
|
||||||
@ -77,9 +73,11 @@ BEGIN
|
|||||||
THROW;
|
THROW;
|
||||||
END CATCH;
|
END CATCH;
|
||||||
|
|
||||||
|
-- Drop the temporary table
|
||||||
|
DROP TABLE #TempGroup;
|
||||||
|
DROP TABLE #TempOrganizationUsers;
|
||||||
|
|
||||||
-- Step 2: AccessAll migration for users
|
-- Step 2: AccessAll migration for users
|
||||||
BEGIN TRY
|
|
||||||
BEGIN TRANSACTION;
|
|
||||||
-- Create a temporary table to store the OrganizationUsers with AccessAll = 1
|
-- Create a temporary table to store the OrganizationUsers with AccessAll = 1
|
||||||
SELECT [Id] AS [OrganizationUserId], [OrganizationId]
|
SELECT [Id] AS [OrganizationUserId], [OrganizationId]
|
||||||
INTO #TempOrgUser
|
INTO #TempOrgUser
|
||||||
@ -87,6 +85,8 @@ BEGIN
|
|||||||
WHERE [AccessAll] = 1
|
WHERE [AccessAll] = 1
|
||||||
AND [OrganizationId] = @OrganizationId;
|
AND [OrganizationId] = @OrganizationId;
|
||||||
|
|
||||||
|
BEGIN TRY
|
||||||
|
BEGIN TRANSACTION;
|
||||||
-- Update existing rows in [dbo].[CollectionUser]
|
-- Update existing rows in [dbo].[CollectionUser]
|
||||||
UPDATE target
|
UPDATE target
|
||||||
SET
|
SET
|
||||||
@ -140,9 +140,6 @@ BEGIN
|
|||||||
|
|
||||||
CLOSE UniqueOrgUserIdCursor
|
CLOSE UniqueOrgUserIdCursor
|
||||||
DEALLOCATE UniqueOrgUserIdCursor;
|
DEALLOCATE UniqueOrgUserIdCursor;
|
||||||
|
|
||||||
-- Drop the temporary table
|
|
||||||
DROP TABLE #TempOrgUser;
|
|
||||||
COMMIT TRANSACTION;
|
COMMIT TRANSACTION;
|
||||||
END TRY
|
END TRY
|
||||||
BEGIN CATCH
|
BEGIN CATCH
|
||||||
@ -150,9 +147,10 @@ BEGIN
|
|||||||
THROW;
|
THROW;
|
||||||
END CATCH;
|
END CATCH;
|
||||||
|
|
||||||
|
-- Drop the temporary table
|
||||||
|
DROP TABLE #TempOrgUser;
|
||||||
|
|
||||||
-- Step 3: Update [dbo].[CollectionUser] with [Manage] = 1 for all users with Manager role or 'EditAssignedCollections' permission
|
-- Step 3: Update [dbo].[CollectionUser] with [Manage] = 1 for all users with Manager role or 'EditAssignedCollections' permission
|
||||||
BEGIN TRY
|
|
||||||
BEGIN TRANSACTION;
|
|
||||||
-- Store the results in a temporary table
|
-- Store the results in a temporary table
|
||||||
SELECT ou.[Id] AS [OrganizationUserId]
|
SELECT ou.[Id] AS [OrganizationUserId]
|
||||||
INTO #TempStep3
|
INTO #TempStep3
|
||||||
@ -160,6 +158,8 @@ BEGIN
|
|||||||
WHERE (ou.[Type] = 3 OR (ou.[Permissions] IS NOT NULL AND
|
WHERE (ou.[Type] = 3 OR (ou.[Permissions] IS NOT NULL AND
|
||||||
ISJSON(ou.[Permissions]) > 0 AND JSON_VALUE(ou.[Permissions], '$.editAssignedCollections') = 'true'));
|
ISJSON(ou.[Permissions]) > 0 AND JSON_VALUE(ou.[Permissions], '$.editAssignedCollections') = 'true'));
|
||||||
|
|
||||||
|
BEGIN TRY
|
||||||
|
BEGIN TRANSACTION;
|
||||||
-- Update [dbo].[CollectionUser] with [Manage] = 1 using the temporary table
|
-- Update [dbo].[CollectionUser] with [Manage] = 1 using the temporary table
|
||||||
UPDATE cu
|
UPDATE cu
|
||||||
SET cu.[ReadOnly] = 0,
|
SET cu.[ReadOnly] = 0,
|
||||||
@ -189,9 +189,6 @@ BEGIN
|
|||||||
|
|
||||||
CLOSE UniqueOrgUserIdCursor
|
CLOSE UniqueOrgUserIdCursor
|
||||||
DEALLOCATE UniqueOrgUserIdCursor;
|
DEALLOCATE UniqueOrgUserIdCursor;
|
||||||
|
|
||||||
-- Drop the temporary table
|
|
||||||
DROP TABLE #TempStep3;
|
|
||||||
COMMIT TRANSACTION;
|
COMMIT TRANSACTION;
|
||||||
END TRY
|
END TRY
|
||||||
BEGIN CATCH
|
BEGIN CATCH
|
||||||
@ -199,9 +196,10 @@ BEGIN
|
|||||||
THROW;
|
THROW;
|
||||||
END CATCH;
|
END CATCH;
|
||||||
|
|
||||||
|
-- Drop the temporary table
|
||||||
|
DROP TABLE #TempStep3;
|
||||||
|
|
||||||
-- Step 4: Insert rows to [dbo].[CollectionUser] for Managers and users with 'EditAssignedCollections' permission assigned to groups with collection access
|
-- Step 4: Insert rows to [dbo].[CollectionUser] for Managers and users with 'EditAssignedCollections' permission assigned to groups with collection access
|
||||||
BEGIN TRY
|
|
||||||
BEGIN TRANSACTION;
|
|
||||||
-- Store the results in a temporary table
|
-- Store the results in a temporary table
|
||||||
SELECT cg.[CollectionId], ou.[Id] AS [OrganizationUserId]
|
SELECT cg.[CollectionId], ou.[Id] AS [OrganizationUserId]
|
||||||
INTO #TempStep4
|
INTO #TempStep4
|
||||||
@ -214,6 +212,8 @@ BEGIN
|
|||||||
WHERE cu.[CollectionId] = cg.[CollectionId] AND cu.[OrganizationUserId] = ou.[Id]
|
WHERE cu.[CollectionId] = cg.[CollectionId] AND cu.[OrganizationUserId] = ou.[Id]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
BEGIN TRY
|
||||||
|
BEGIN TRANSACTION;
|
||||||
-- Insert rows into [dbo].[CollectionUser] using the temporary table
|
-- Insert rows into [dbo].[CollectionUser] using the temporary table
|
||||||
INSERT INTO [dbo].[CollectionUser] ([CollectionId], [OrganizationUserId], [ReadOnly], [HidePasswords], [Manage])
|
INSERT INTO [dbo].[CollectionUser] ([CollectionId], [OrganizationUserId], [ReadOnly], [HidePasswords], [Manage])
|
||||||
SELECT [CollectionId], [OrganizationUserId], 0, 0, 1
|
SELECT [CollectionId], [OrganizationUserId], 0, 0, 1
|
||||||
@ -240,9 +240,6 @@ BEGIN
|
|||||||
|
|
||||||
CLOSE UniqueOrgUserIdCursor
|
CLOSE UniqueOrgUserIdCursor
|
||||||
DEALLOCATE UniqueOrgUserIdCursor;
|
DEALLOCATE UniqueOrgUserIdCursor;
|
||||||
|
|
||||||
-- Drop the temporary table
|
|
||||||
DROP TABLE #TempStep4;
|
|
||||||
COMMIT TRANSACTION;
|
COMMIT TRANSACTION;
|
||||||
END TRY
|
END TRY
|
||||||
BEGIN CATCH
|
BEGIN CATCH
|
||||||
@ -250,15 +247,18 @@ BEGIN
|
|||||||
THROW;
|
THROW;
|
||||||
END CATCH;
|
END CATCH;
|
||||||
|
|
||||||
|
-- Drop the temporary table
|
||||||
|
DROP TABLE #TempStep4;
|
||||||
|
|
||||||
-- Step 5: Set all Managers to Users
|
-- Step 5: Set all Managers to Users
|
||||||
BEGIN TRY
|
|
||||||
BEGIN TRANSACTION;
|
|
||||||
-- Store the results in a temporary table
|
-- Store the results in a temporary table
|
||||||
SELECT [Id] AS [OrganizationUserId]
|
SELECT [Id] AS [OrganizationUserId]
|
||||||
INTO #TempStep5
|
INTO #TempStep5
|
||||||
FROM [dbo].[OrganizationUser]
|
FROM [dbo].[OrganizationUser]
|
||||||
WHERE [Type] = 3; -- Manager
|
WHERE [Type] = 3; -- Manager
|
||||||
|
|
||||||
|
BEGIN TRY
|
||||||
|
BEGIN TRANSACTION;
|
||||||
-- Update [dbo].[OrganizationUser] based on the temporary table
|
-- Update [dbo].[OrganizationUser] based on the temporary table
|
||||||
UPDATE ou
|
UPDATE ou
|
||||||
SET ou.[Type] = 2 -- User
|
SET ou.[Type] = 2 -- User
|
||||||
@ -286,14 +286,14 @@ BEGIN
|
|||||||
|
|
||||||
CLOSE UniqueOrgUserIdCursor
|
CLOSE UniqueOrgUserIdCursor
|
||||||
DEALLOCATE UniqueOrgUserIdCursor;
|
DEALLOCATE UniqueOrgUserIdCursor;
|
||||||
|
|
||||||
-- Drop the temporary table
|
|
||||||
DROP TABLE #TempStep5;
|
|
||||||
COMMIT TRANSACTION;
|
COMMIT TRANSACTION;
|
||||||
END TRY
|
END TRY
|
||||||
BEGIN CATCH
|
BEGIN CATCH
|
||||||
ROLLBACK TRANSACTION;
|
ROLLBACK TRANSACTION;
|
||||||
THROW;
|
THROW;
|
||||||
END CATCH;
|
END CATCH;
|
||||||
|
|
||||||
|
-- Drop the temporary table
|
||||||
|
DROP TABLE #TempStep5;
|
||||||
END
|
END
|
||||||
GO
|
GO
|
||||||
|
Reference in New Issue
Block a user