1
0
mirror of https://github.com/bitwarden/server.git synced 2025-06-07 19:50:32 -05:00
bitwarden/util/Migrator/DbScripts/2025-05-30_00_Notification_MarkAsDeletedByTask.sql
Nick Krantz 06f9f156f6
omit userId from MarkTaskAsCompletedCommand query.
The userId from the notification will be used
2025-06-01 20:19:57 -05:00

36 lines
1.1 KiB
Transact-SQL

CREATE OR ALTER PROCEDURE [dbo].[Notification_MarkAsDeletedByTask]
@TaskId UNIQUEIDENTIFIER
AS
BEGIN
SET NOCOUNT ON;
-- Collect NotificationIds as they are altered
DECLARE @UserIdsForAlteredNotifications TABLE (
UserId UNIQUEIDENTIFIER
);
-- Update existing NotificationStatus as deleted
UPDATE ns
SET ns.DeletedDate = GETUTCDATE()
OUTPUT inserted.UserId INTO @UserIdsForAlteredNotifications
FROM NotificationStatus ns
INNER JOIN Notification n ON ns.NotificationId = n.Id
WHERE n.TaskId = @TaskId
AND ns.DeletedDate IS NULL;
-- Insert NotificationStatus records for notifications that don't have one yet
INSERT INTO NotificationStatus (NotificationId, UserId, DeletedDate)
OUTPUT inserted.UserId INTO @UserIdsForAlteredNotifications
SELECT n.Id, n.UserId, GETUTCDATE()
FROM Notification n
LEFT JOIN NotificationStatus ns
ON n.Id = ns.NotificationId
WHERE n.TaskId = @TaskId
AND ns.NotificationId IS NULL;
-- Return the user ids associated with the altered notifications
SELECT u.UserId
FROM @UserIdsForAlteredNotifications u;
END
GO