diff --git a/util/Setup/DbScripts/2018-02-28_00_LoginUris.sql b/util/Setup/DbScripts/2018-02-28_00_LoginUris.sql new file mode 100644 index 0000000000..12e0b08c96 --- /dev/null +++ b/util/Setup/DbScripts/2018-02-28_00_LoginUris.sql @@ -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 diff --git a/util/Setup/Setup.csproj b/util/Setup/Setup.csproj index 88b2f0de50..73c2104d2b 100644 --- a/util/Setup/Setup.csproj +++ b/util/Setup/Setup.csproj @@ -8,6 +8,11 @@ + + + + +