1
0
mirror of https://github.com/bitwarden/server.git synced 2025-01-13 20:21:22 +01:00

update script for login uris

This commit is contained in:
Kyle Spearrin 2018-03-01 23:40:37 -05:00
parent 0689e8617a
commit 03e7cf806a
2 changed files with 70 additions and 0 deletions

View File

@ -0,0 +1,65 @@
/*
{
"Name":"2.xx",
"Uri":"2.yy",
"Username":"2.zz",
"Password":"2.aa"
}
=>
{
"Name":"2.xx",
"Username":"2.zz",
"Password":"2.aa",
"Uris": [
{
"Uri": "2.yy",
"Match": 0
}
]
}
*/
SET NOCOUNT ON
DECLARE @UriPath VARCHAR(50) = '$.Uri'
DECLARE @UrisPath VARCHAR(50) = '$.Uris'
DECLARE @BatchSize INT = 1000
-- Step 1: Add new Uris property with data from Uri
WHILE @BatchSize > 0
BEGIN
UPDATE TOP (@BatchSize)
[Cipher]
SET
[Data] = JSON_MODIFY(
[Data],
@UrisPath,
JSON_QUERY(
'[{"Uri":"' + JSON_VALUE([Data], @UriPath) + '"}]',
'$'
)
)
WHERE
JSON_VALUE([Data], @UriPath) IS NOT NULL
AND JSON_QUERY([Data], @UrisPath) IS NULL
SET @BatchSize = @@ROWCOUNT
RAISERROR('Updated %d ciphers with Uris', 0, 1, @BatchSize) WITH NOWAIT
END
-- Step 2: Remove old Uri Property
SET @BatchSize = 1000
WHILE @BatchSize > 0
BEGIN
UPDATE TOP (@BatchSize)
[Cipher]
SET
[Data] = JSON_MODIFY([Data], @UriPath, NULL)
WHERE
JSON_VALUE([Data], @UriPath) IS NOT NULL
AND JSON_QUERY([Data], @UrisPath) IS NOT NULL
SET @BatchSize = @@ROWCOUNT
RAISERROR('Updated %d ciphers with Uri removal', 0, 1, @BatchSize) WITH NOWAIT
END

View File

@ -8,6 +8,11 @@
</PropertyGroup>
<ItemGroup>
<None Remove="DbScripts\2018-02-28_00_LoginUris.sql" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="DbScripts\2018-02-28_00_LoginUris.sql" />
<EmbeddedResource Include="DbScripts\2017-12-12_00_Events.sql" />
<EmbeddedResource Include="DbScripts\2017-11-24_00_UpdateProcs.sql" />
<EmbeddedResource Include="DbScripts\2017-11-13_00_IndexTuning.sql" />