mirror of
https://github.com/bitwarden/server.git
synced 2025-06-30 15:42:48 -05:00
job to delete trashed ciphers nightly (#1243)
* job to delete trashed items nightly * remove script from migration project file * admin setting for controlling trash deleting dates
This commit is contained in:
36
util/Migrator/DbScripts/2021-03-26_00_CipherDeletedIndex.sql
Normal file
36
util/Migrator/DbScripts/2021-03-26_00_CipherDeletedIndex.sql
Normal file
@ -0,0 +1,36 @@
|
||||
IF OBJECT_ID('[dbo].[Cipher_DeleteDeleted]') IS NOT NULL
|
||||
BEGIN
|
||||
DROP PROCEDURE [dbo].[Cipher_DeleteDeleted]
|
||||
END
|
||||
GO
|
||||
|
||||
CREATE PROCEDURE [dbo].[Cipher_DeleteDeleted]
|
||||
@DeletedDateBefore DATETIME2 (7)
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
DECLARE @BatchSize INT = 100
|
||||
|
||||
WHILE @BatchSize > 0
|
||||
BEGIN
|
||||
DELETE TOP(@BatchSize)
|
||||
FROM
|
||||
[dbo].[Cipher]
|
||||
WHERE
|
||||
[DeletedDate] < @DeletedDateBefore
|
||||
|
||||
SET @BatchSize = @@ROWCOUNT
|
||||
END
|
||||
END
|
||||
GO
|
||||
|
||||
IF NOT EXISTS (
|
||||
SELECT * FROM sys.indexes WHERE [Name]='IX_Cipher_DeletedDate'
|
||||
AND object_id = OBJECT_ID('[dbo].[Cipher]')
|
||||
)
|
||||
BEGIN
|
||||
CREATE NONCLUSTERED INDEX [IX_Cipher_DeletedDate]
|
||||
ON [dbo].[Cipher]([DeletedDate] ASC)
|
||||
END
|
||||
GO
|
Reference in New Issue
Block a user