mirror of
https://github.com/bitwarden/server.git
synced 2026-02-10 19:03:18 +08:00
Resolve competing cascade action: manually set FKID to null
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
-- Update OrganizationUser_MigrateDefaultCollection to set DefaultCollectionOwner = NULL
|
||||
-- when migrating default collections to shared collections during OrganizationUser deletion
|
||||
|
||||
CREATE OR ALTER PROCEDURE [dbo].[OrganizationUser_MigrateDefaultCollection]
|
||||
@Ids [dbo].[GuidIdArray] READONLY
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
DECLARE @UtcNow DATETIME2(7) = GETUTCDATE();
|
||||
|
||||
UPDATE c
|
||||
SET
|
||||
[DefaultUserCollectionEmail] = CASE WHEN c.[DefaultUserCollectionEmail] IS NULL THEN u.[Email] ELSE c.[DefaultUserCollectionEmail] END,
|
||||
[RevisionDate] = @UtcNow,
|
||||
[Type] = 0,
|
||||
[DefaultCollectionOwner] = NULL
|
||||
FROM
|
||||
[dbo].[Collection] c
|
||||
INNER JOIN [dbo].[CollectionUser] cu ON c.[Id] = cu.[CollectionId]
|
||||
INNER JOIN [dbo].[OrganizationUser] ou ON cu.[OrganizationUserId] = ou.[Id]
|
||||
INNER JOIN [dbo].[User] u ON ou.[UserId] = u.[Id]
|
||||
INNER JOIN @Ids i ON ou.[Id] = i.[Id]
|
||||
WHERE
|
||||
c.[Type] = 1
|
||||
END
|
||||
GO
|
||||
Reference in New Issue
Block a user