1
0
mirror of https://github.com/bitwarden/server.git synced 2024-11-22 12:15:36 +01:00
bitwarden-server/util/Migrator/DbScripts/2020-07-21_00_BulkDeleteCiphersAsOrgAdmin.sql
Kyle Spearrin 68915a452e missing go
2020-07-28 21:53:12 -04:00

57 lines
1.4 KiB
Transact-SQL

IF OBJECT_ID('[dbo].[Cipher_DeleteByIdsOrganizationId]') IS NOT NULL
BEGIN
DROP PROCEDURE [dbo].[Cipher_DeleteByIdsOrganizationId];
END
GO
IF OBJECT_ID('[dbo].[Cipher_SoftDeleteByIdsOrganizationId]') IS NOT NULL
BEGIN
DROP PROCEDURE [dbo].[Cipher_SoftDeleteByIdsOrganizationId];
END
GO
CREATE PROCEDURE [dbo].[Cipher_DeleteByIdsOrganizationId]
@Ids AS [dbo].[GuidIdArray] READONLY,
@OrganizationId AS UNIQUEIDENTIFIER
AS
BEGIN
SET NOCOUNT ON
-- Delete ciphers
DELETE
FROM
[dbo].[Cipher]
WHERE
[Id] IN (SELECT * FROM @Ids)
AND OrganizationId = @OrganizationId
-- Cleanup organization
EXEC [dbo].[Organization_UpdateStorage] @OrganizationId
EXEC [dbo].[User_BumpAccountRevisionDateByOrganizationId] @OrganizationId
END
GO
CREATE PROCEDURE [dbo].[Cipher_SoftDeleteByIdsOrganizationId]
@Ids AS [dbo].[GuidIdArray] READONLY,
@OrganizationId AS UNIQUEIDENTIFIER
AS
BEGIN
SET NOCOUNT ON
-- Delete ciphers
DECLARE @UtcNow DATETIME2(7) = GETUTCDATE();
UPDATE
[dbo].[Cipher]
SET
[DeletedDate] = @UtcNow,
[RevisionDate] = @UtcNow
WHERE
[Id] IN (SELECT * FROM @Ids)
AND OrganizationId = @OrganizationId
-- Cleanup organization
EXEC [dbo].[Organization_UpdateStorage] @OrganizationId
EXEC [dbo].[User_BumpAccountRevisionDateByOrganizationId] @OrganizationId
END
GO