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:
parent
0689e8617a
commit
03e7cf806a
util/Setup
65
util/Setup/DbScripts/2018-02-28_00_LoginUris.sql
Normal file
65
util/Setup/DbScripts/2018-02-28_00_LoginUris.sql
Normal 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
|
@ -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" />
|
||||
|
Loading…
Reference in New Issue
Block a user