mirror of
https://github.com/bitwarden/server.git
synced 2025-04-17 11:08:16 -05:00
new grant cleanup sproc
This commit is contained in:
parent
c227beb510
commit
4c399aaf0d
@ -228,5 +228,6 @@
|
|||||||
<Build Include="dbo\Stored Procedures\CollectionCipher_UpdateCollectionsForCiphers.sql" />
|
<Build Include="dbo\Stored Procedures\CollectionCipher_UpdateCollectionsForCiphers.sql" />
|
||||||
<Build Include="dbo\Stored Procedures\User_ReadByPremiumRenewal.sql" />
|
<Build Include="dbo\Stored Procedures\User_ReadByPremiumRenewal.sql" />
|
||||||
<Build Include="dbo\Stored Procedures\User_UpdateRenewalReminderDate.sql" />
|
<Build Include="dbo\Stored Procedures\User_UpdateRenewalReminderDate.sql" />
|
||||||
|
<Build Include="dbo\Stored Procedures\Grant_DeleteExpired.sql" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
19
src/Sql/dbo/Stored Procedures/Grant_DeleteExpired.sql
Normal file
19
src/Sql/dbo/Stored Procedures/Grant_DeleteExpired.sql
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
CREATE PROCEDURE [dbo].[Grant_DeleteExpired]
|
||||||
|
AS
|
||||||
|
BEGIN
|
||||||
|
SET NOCOUNT ON
|
||||||
|
|
||||||
|
DECLARE @BatchSize INT = 100
|
||||||
|
DECLARE @Now DATETIME2(7) = GETUTCDATE()
|
||||||
|
|
||||||
|
WHILE @BatchSize > 0
|
||||||
|
BEGIN
|
||||||
|
DELETE TOP(@BatchSize)
|
||||||
|
FROM
|
||||||
|
[dbo].[Grant]
|
||||||
|
WHERE
|
||||||
|
[ExpirationDate] < @Now
|
||||||
|
|
||||||
|
SET @BatchSize = @@ROWCOUNT
|
||||||
|
END
|
||||||
|
END
|
@ -14,3 +14,7 @@ GO
|
|||||||
CREATE NONCLUSTERED INDEX [IX_Grant_SubjectId_ClientId_Type]
|
CREATE NONCLUSTERED INDEX [IX_Grant_SubjectId_ClientId_Type]
|
||||||
ON [dbo].[Grant]([SubjectId] ASC, [ClientId] ASC, [Type] ASC);
|
ON [dbo].[Grant]([SubjectId] ASC, [ClientId] ASC, [Type] ASC);
|
||||||
|
|
||||||
|
GO
|
||||||
|
CREATE NONCLUSTERED INDEX [IX_Grant_ExpirationDate]
|
||||||
|
ON [dbo].[Grant]([ExpirationDate] ASC);
|
||||||
|
|
||||||
|
@ -17,6 +17,16 @@ BEGIN
|
|||||||
END
|
END
|
||||||
GO
|
GO
|
||||||
|
|
||||||
|
IF NOT EXISTS (
|
||||||
|
SELECT * FROM sys.indexes WHERE [Name]='IX_Grant_ExpirationDate'
|
||||||
|
AND object_id = OBJECT_ID('[dbo].[Grant]')
|
||||||
|
)
|
||||||
|
BEGIN
|
||||||
|
CREATE NONCLUSTERED INDEX [IX_Grant_ExpirationDate]
|
||||||
|
ON [dbo].[Grant]([ExpirationDate] ASC)
|
||||||
|
END
|
||||||
|
GO
|
||||||
|
|
||||||
IF EXISTS(SELECT * FROM sys.views WHERE [Name] = 'UserView')
|
IF EXISTS(SELECT * FROM sys.views WHERE [Name] = 'UserView')
|
||||||
BEGIN
|
BEGIN
|
||||||
DROP VIEW [dbo].[UserView]
|
DROP VIEW [dbo].[UserView]
|
||||||
@ -31,6 +41,33 @@ FROM
|
|||||||
[dbo].[User]
|
[dbo].[User]
|
||||||
GO
|
GO
|
||||||
|
|
||||||
|
IF OBJECT_ID('[dbo].[Grant_DeleteExpired]') IS NOT NULL
|
||||||
|
BEGIN
|
||||||
|
DROP PROCEDURE [dbo].[Grant_DeleteExpired]
|
||||||
|
END
|
||||||
|
GO
|
||||||
|
|
||||||
|
CREATE PROCEDURE [dbo].[Grant_DeleteExpired]
|
||||||
|
AS
|
||||||
|
BEGIN
|
||||||
|
SET NOCOUNT ON
|
||||||
|
|
||||||
|
DECLARE @BatchSize INT = 100
|
||||||
|
DECLARE @Now DATETIME2(7) = GETUTCDATE()
|
||||||
|
|
||||||
|
WHILE @BatchSize > 0
|
||||||
|
BEGIN
|
||||||
|
DELETE TOP(@BatchSize)
|
||||||
|
FROM
|
||||||
|
[dbo].[Grant]
|
||||||
|
WHERE
|
||||||
|
[ExpirationDate] < @Now
|
||||||
|
|
||||||
|
SET @BatchSize = @@ROWCOUNT
|
||||||
|
END
|
||||||
|
END
|
||||||
|
GO
|
||||||
|
|
||||||
IF OBJECT_ID('[dbo].[User_Create]') IS NOT NULL
|
IF OBJECT_ID('[dbo].[User_Create]') IS NOT NULL
|
||||||
BEGIN
|
BEGIN
|
||||||
DROP PROCEDURE [dbo].[User_Create]
|
DROP PROCEDURE [dbo].[User_Create]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user