mirror of
https://github.com/bitwarden/server.git
synced 2025-05-22 12:04:27 -05:00
[PM-4767] Update Grant_Save procedure (#3641)
* modify grant_save sql script to migration and Auth SQL scripts to not use merge * Update formatting for sql files * Fix formatting for sql files * Format using Prettier * Rename 2024-01-03_00_FixGrantSave.sql to 2024-02-12_00_FixGrantSave.sql --------- Co-authored-by: Matt Bishop <mbishop@bitwarden.com>
This commit is contained in:
parent
4830a352e8
commit
744d21ec5e
@ -13,10 +13,37 @@ AS
|
|||||||
BEGIN
|
BEGIN
|
||||||
SET NOCOUNT ON
|
SET NOCOUNT ON
|
||||||
|
|
||||||
MERGE
|
-- First, try to update the existing row
|
||||||
[dbo].[Grant] AS [Target]
|
UPDATE [dbo].[Grant]
|
||||||
USING
|
SET
|
||||||
|
[Type] = @Type,
|
||||||
|
[SubjectId] = @SubjectId,
|
||||||
|
[SessionId] = @SessionId,
|
||||||
|
[ClientId] = @ClientId,
|
||||||
|
[Description] = @Description,
|
||||||
|
[CreationDate] = @CreationDate,
|
||||||
|
[ExpirationDate] = @ExpirationDate,
|
||||||
|
[ConsumedDate] = @ConsumedDate,
|
||||||
|
[Data] = @Data
|
||||||
|
WHERE
|
||||||
|
[Key] = @Key
|
||||||
|
|
||||||
|
-- If no row was updated, insert a new one
|
||||||
|
IF @@ROWCOUNT = 0
|
||||||
|
BEGIN
|
||||||
|
INSERT INTO [dbo].[Grant]
|
||||||
(
|
(
|
||||||
|
[Key],
|
||||||
|
[Type],
|
||||||
|
[SubjectId],
|
||||||
|
[SessionId],
|
||||||
|
[ClientId],
|
||||||
|
[Description],
|
||||||
|
[CreationDate],
|
||||||
|
[ExpirationDate],
|
||||||
|
[ConsumedDate],
|
||||||
|
[Data]
|
||||||
|
)
|
||||||
VALUES
|
VALUES
|
||||||
(
|
(
|
||||||
@Key,
|
@Key,
|
||||||
@ -30,59 +57,5 @@ BEGIN
|
|||||||
@ConsumedDate,
|
@ConsumedDate,
|
||||||
@Data
|
@Data
|
||||||
)
|
)
|
||||||
) AS [Source]
|
END
|
||||||
(
|
|
||||||
[Key],
|
|
||||||
[Type],
|
|
||||||
[SubjectId],
|
|
||||||
[SessionId],
|
|
||||||
[ClientId],
|
|
||||||
[Description],
|
|
||||||
[CreationDate],
|
|
||||||
[ExpirationDate],
|
|
||||||
[ConsumedDate],
|
|
||||||
[Data]
|
|
||||||
)
|
|
||||||
ON
|
|
||||||
[Target].[Key] = [Source].[Key]
|
|
||||||
WHEN MATCHED THEN
|
|
||||||
UPDATE
|
|
||||||
SET
|
|
||||||
[Type] = [Source].[Type],
|
|
||||||
[SubjectId] = [Source].[SubjectId],
|
|
||||||
[SessionId] = [Source].[SessionId],
|
|
||||||
[ClientId] = [Source].[ClientId],
|
|
||||||
[Description] = [Source].[Description],
|
|
||||||
[CreationDate] = [Source].[CreationDate],
|
|
||||||
[ExpirationDate] = [Source].[ExpirationDate],
|
|
||||||
[ConsumedDate] = [Source].[ConsumedDate],
|
|
||||||
[Data] = [Source].[Data]
|
|
||||||
WHEN NOT MATCHED THEN
|
|
||||||
INSERT
|
|
||||||
(
|
|
||||||
[Key],
|
|
||||||
[Type],
|
|
||||||
[SubjectId],
|
|
||||||
[SessionId],
|
|
||||||
[ClientId],
|
|
||||||
[Description],
|
|
||||||
[CreationDate],
|
|
||||||
[ExpirationDate],
|
|
||||||
[ConsumedDate],
|
|
||||||
[Data]
|
|
||||||
)
|
|
||||||
VALUES
|
|
||||||
(
|
|
||||||
[Source].[Key],
|
|
||||||
[Source].[Type],
|
|
||||||
[Source].[SubjectId],
|
|
||||||
[Source].[SessionId],
|
|
||||||
[Source].[ClientId],
|
|
||||||
[Source].[Description],
|
|
||||||
[Source].[CreationDate],
|
|
||||||
[Source].[ExpirationDate],
|
|
||||||
[Source].[ConsumedDate],
|
|
||||||
[Source].[Data]
|
|
||||||
)
|
|
||||||
;
|
|
||||||
END
|
END
|
||||||
|
61
util/Migrator/DbScripts/2024-02-12_00_FixGrantSave.sql
Normal file
61
util/Migrator/DbScripts/2024-02-12_00_FixGrantSave.sql
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
CREATE OR ALTER PROCEDURE [dbo].[Grant_Save]
|
||||||
|
@Key NVARCHAR(200),
|
||||||
|
@Type NVARCHAR(50),
|
||||||
|
@SubjectId NVARCHAR(200),
|
||||||
|
@SessionId NVARCHAR(100),
|
||||||
|
@ClientId NVARCHAR(200),
|
||||||
|
@Description NVARCHAR(200),
|
||||||
|
@CreationDate DATETIME2,
|
||||||
|
@ExpirationDate DATETIME2,
|
||||||
|
@ConsumedDate DATETIME2,
|
||||||
|
@Data NVARCHAR(MAX)
|
||||||
|
AS
|
||||||
|
BEGIN
|
||||||
|
SET NOCOUNT ON
|
||||||
|
|
||||||
|
-- First, try to update the existing row
|
||||||
|
UPDATE [dbo].[Grant]
|
||||||
|
SET
|
||||||
|
[Type] = @Type,
|
||||||
|
[SubjectId] = @SubjectId,
|
||||||
|
[SessionId] = @SessionId,
|
||||||
|
[ClientId] = @ClientId,
|
||||||
|
[Description] = @Description,
|
||||||
|
[CreationDate] = @CreationDate,
|
||||||
|
[ExpirationDate] = @ExpirationDate,
|
||||||
|
[ConsumedDate] = @ConsumedDate,
|
||||||
|
[Data] = @Data
|
||||||
|
WHERE
|
||||||
|
[Key] = @Key
|
||||||
|
|
||||||
|
-- If no row was updated, insert a new one
|
||||||
|
IF @@ROWCOUNT = 0
|
||||||
|
BEGIN
|
||||||
|
INSERT INTO [dbo].[Grant]
|
||||||
|
(
|
||||||
|
[Key],
|
||||||
|
[Type],
|
||||||
|
[SubjectId],
|
||||||
|
[SessionId],
|
||||||
|
[ClientId],
|
||||||
|
[Description],
|
||||||
|
[CreationDate],
|
||||||
|
[ExpirationDate],
|
||||||
|
[ConsumedDate],
|
||||||
|
[Data]
|
||||||
|
)
|
||||||
|
VALUES
|
||||||
|
(
|
||||||
|
@Key,
|
||||||
|
@Type,
|
||||||
|
@SubjectId,
|
||||||
|
@SessionId,
|
||||||
|
@ClientId,
|
||||||
|
@Description,
|
||||||
|
@CreationDate,
|
||||||
|
@ExpirationDate,
|
||||||
|
@ConsumedDate,
|
||||||
|
@Data
|
||||||
|
)
|
||||||
|
END
|
||||||
|
END
|
Loading…
x
Reference in New Issue
Block a user