mirror of
https://github.com/bitwarden/server.git
synced 2025-07-07 02:52:50 -05:00
Null out sponsorship values when foreign key deleted (#1733)
This allows us to maintain record of sponsorships up until they are explicitly removed. Fixes issues where removing sponsorships from organizations with invalid sponsorships would error
This commit is contained in:
@ -9,23 +9,13 @@ BEGIN
|
||||
SET
|
||||
[SponsoringOrganizationId] = NULL
|
||||
WHERE
|
||||
[SponsoringOrganizationId] = @OrganizationId AND
|
||||
[CloudSponsor] = 0
|
||||
[SponsoringOrganizationId] = @OrganizationId
|
||||
|
||||
UPDATE
|
||||
[dbo].[OrganizationSponsorship]
|
||||
SET
|
||||
[SponsoredOrganizationId] = NULL
|
||||
WHERE
|
||||
[SponsoredOrganizationId] = @OrganizationId AND
|
||||
[CloudSponsor] = 0
|
||||
|
||||
DELETE
|
||||
FROM
|
||||
[dbo].[OrganizationSponsorship]
|
||||
WHERE
|
||||
[CloudSponsor] = 1 AND
|
||||
([SponsoredOrganizationId] = @OrganizationId OR
|
||||
[SponsoringOrganizationId] = @OrganizationId)
|
||||
[SponsoredOrganizationId] = @OrganizationId
|
||||
END
|
||||
GO
|
||||
|
@ -4,9 +4,12 @@ AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
DELETE
|
||||
UPDATE
|
||||
OS
|
||||
SET
|
||||
[SponsoringOrganizationUserId] = NULL
|
||||
FROM
|
||||
[dbo].[OrganizationSponsorship]
|
||||
[dbo].[OrganizationSponsorship] OS
|
||||
WHERE
|
||||
[SponsoringOrganizationUserId] = @OrganizationUserId
|
||||
END
|
||||
|
@ -4,22 +4,13 @@ AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
DECLARE @BatchSize AS INT;
|
||||
SET @BatchSize = 100;
|
||||
|
||||
WHILE @BatchSize > 0
|
||||
BEGIN
|
||||
BEGIN TRANSACTION OrganizationSponsorship_DeleteOUs
|
||||
|
||||
DELETE TOP(@BatchSize) OS
|
||||
FROM
|
||||
[dbo].[OrganizationSponsorship] OS
|
||||
INNER JOIN
|
||||
@SponsoringOrganizationUserIds I ON I.Id = OS.SponsoringOrganizationUserId
|
||||
|
||||
SET @BatchSize = @@ROWCOUNT
|
||||
|
||||
COMMIT TRANSACTION OrganizationSponsorship_DeleteOUs
|
||||
END
|
||||
UPDATE
|
||||
OS
|
||||
SET
|
||||
[SponsoringOrganizationUserId] = NULL
|
||||
FROM
|
||||
[dbo].[OrganizationSponsorship] OS
|
||||
INNER JOIN
|
||||
@SponsoringOrganizationUserIds I ON I.Id = OS.SponsoringOrganizationUserId
|
||||
END
|
||||
GO
|
||||
|
Reference in New Issue
Block a user