mirror of
https://github.com/bitwarden/server.git
synced 2024-12-26 17:37:36 +01:00
use completion table on login uris update
This commit is contained in:
parent
8d681738c8
commit
c37016e19e
@ -19,17 +19,41 @@
|
||||
}
|
||||
*/
|
||||
|
||||
SET NOCOUNT ON
|
||||
IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'CompletedIds')
|
||||
BEGIN
|
||||
CREATE TABLE [CompletedIds] ([Id] UNIQUEIDENTIFIER PRIMARY KEY)
|
||||
END
|
||||
GO
|
||||
|
||||
DECLARE @UriPath VARCHAR(50) = '$.Uri'
|
||||
DECLARE @UrisPath VARCHAR(50) = '$.Uris'
|
||||
DECLARE @BatchSize INT = 1000
|
||||
DECLARE @LastId UNIQUEIDENTIFIER = NULL
|
||||
|
||||
-- Step 1: Add new Uris property with data from Uri
|
||||
WHILE @BatchSize > 0
|
||||
BEGIN
|
||||
UPDATE TOP (@BatchSize)
|
||||
[Cipher]
|
||||
SELECT TOP 1
|
||||
@LastId = [Id]
|
||||
FROM
|
||||
[CompletedIds]
|
||||
ORDER BY
|
||||
[Id] DESC
|
||||
|
||||
;WITH [CTE] AS (
|
||||
SELECT TOP (@BatchSize)
|
||||
*
|
||||
FROM
|
||||
[Cipher]
|
||||
WHERE
|
||||
(@LastId IS NULL OR [Id] > @LastId)
|
||||
AND JSON_VALUE([Data], @UriPath) IS NOT NULL
|
||||
AND JSON_QUERY([Data], @UrisPath) IS NULL
|
||||
ORDER BY
|
||||
[Id] ASC
|
||||
)
|
||||
UPDATE
|
||||
[CTE]
|
||||
SET
|
||||
[Data] = JSON_MODIFY(
|
||||
[Data],
|
||||
@ -39,27 +63,51 @@ BEGIN
|
||||
'$'
|
||||
)
|
||||
)
|
||||
WHERE
|
||||
JSON_VALUE([Data], @UriPath) IS NOT NULL
|
||||
AND JSON_QUERY([Data], @UrisPath) IS NULL
|
||||
OUTPUT INSERTED.[Id] INTO [CompletedIds]
|
||||
|
||||
SET @BatchSize = @@ROWCOUNT
|
||||
RAISERROR('Updated %d ciphers with Uris', 0, 1, @BatchSize) WITH NOWAIT
|
||||
END
|
||||
|
||||
-- Step 2: Remove old Uri Property
|
||||
-- Reset
|
||||
TRUNCATE TABLE [CompletedIds]
|
||||
SET @BatchSize = 1000
|
||||
|
||||
-- Step 2: Remove old Uri Property
|
||||
WHILE @BatchSize > 0
|
||||
BEGIN
|
||||
UPDATE TOP (@BatchSize)
|
||||
[Cipher]
|
||||
SELECT TOP 1
|
||||
@LastId = [Id]
|
||||
FROM
|
||||
[CompletedIds]
|
||||
ORDER BY
|
||||
[Id] DESC
|
||||
|
||||
;WITH [CTE] AS (
|
||||
SELECT TOP (@BatchSize)
|
||||
*
|
||||
FROM
|
||||
[Cipher]
|
||||
WHERE
|
||||
(@LastId IS NULL OR [Id] > @LastId)
|
||||
AND JSON_VALUE([Data], @UriPath) IS NOT NULL
|
||||
AND JSON_QUERY([Data], @UrisPath) IS NOT NULL
|
||||
ORDER BY
|
||||
[Id] ASC
|
||||
)
|
||||
UPDATE
|
||||
[CTE]
|
||||
SET
|
||||
[Data] = JSON_MODIFY([Data], @UriPath, NULL)
|
||||
WHERE
|
||||
JSON_VALUE([Data], @UriPath) IS NOT NULL
|
||||
AND JSON_QUERY([Data], @UrisPath) IS NOT NULL
|
||||
OUTPUT INSERTED.[Id] INTO [CompletedIds]
|
||||
|
||||
SET @BatchSize = @@ROWCOUNT
|
||||
RAISERROR('Updated %d ciphers with Uri removal', 0, 1, @BatchSize) WITH NOWAIT
|
||||
END
|
||||
GO
|
||||
|
||||
IF EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'CompletedIds')
|
||||
BEGIN
|
||||
DROP TABLE [CompletedIds]
|
||||
END
|
||||
GO
|
||||
|
Loading…
Reference in New Issue
Block a user