From a1cb980bac4790d5b80d43c1142c7b2b1627a22d Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Tue, 28 Nov 2017 22:58:26 -0500 Subject: [PATCH] make bump sprocs first --- .../DbScripts/2017-11-24_00_UpdateProcs.sql | 186 +++++++++--------- 1 file changed, 93 insertions(+), 93 deletions(-) diff --git a/util/Setup/DbScripts/2017-11-24_00_UpdateProcs.sql b/util/Setup/DbScripts/2017-11-24_00_UpdateProcs.sql index 96f8695932..1ac38dbcbc 100644 --- a/util/Setup/DbScripts/2017-11-24_00_UpdateProcs.sql +++ b/util/Setup/DbScripts/2017-11-24_00_UpdateProcs.sql @@ -1,4 +1,96 @@ -IF OBJECT_ID('[dbo].[Cipher_DeleteByUserId]') IS NOT NULL +IF OBJECT_ID('[dbo].[User_BumpAccountRevisionDateByCipherId]') IS NOT NULL +BEGIN + DROP PROCEDURE [dbo].[User_BumpAccountRevisionDateByCipherId] +END +GO + +CREATE PROCEDURE [dbo].[User_BumpAccountRevisionDateByCipherId] + @CipherId UNIQUEIDENTIFIER, + @OrganizationId UNIQUEIDENTIFIER +AS +BEGIN + SET NOCOUNT ON + + UPDATE + U + SET + U.[AccountRevisionDate] = GETUTCDATE() + FROM + [dbo].[User] U + LEFT JOIN + [dbo].[OrganizationUser] OU ON OU.[UserId] = U.[Id] + LEFT JOIN + [dbo].[CollectionCipher] CC ON CC.[CipherId] = @CipherId + LEFT JOIN + [dbo].[CollectionUser] CU ON OU.[AccessAll] = 0 AND CU.[OrganizationUserId] = OU.[Id] AND CU.[CollectionId] = CC.[CollectionId] + LEFT JOIN + [dbo].[GroupUser] GU ON CU.[CollectionId] IS NULL AND OU.[AccessAll] = 0 AND GU.[OrganizationUserId] = OU.[Id] + LEFT JOIN + [dbo].[Group] G ON G.[Id] = GU.[GroupId] + LEFT JOIN + [dbo].[CollectionGroup] CG ON G.[AccessAll] = 0 AND CG.[GroupId] = GU.[GroupId] AND CG.[CollectionId] = CC.[CollectionId] + WHERE + OU.[Status] = 2 -- 2 = Confirmed + AND ( + CU.[CollectionId] IS NOT NULL + OR CG.[CollectionId] IS NOT NULL + OR ( + OU.[OrganizationId] = @OrganizationId + AND ( + OU.[AccessAll] = 1 + OR G.[AccessAll] = 1 + ) + ) + ) +END +GO + +IF OBJECT_ID('[dbo].[User_BumpAccountRevisionDateByCollectionId]') IS NOT NULL +BEGIN + DROP PROCEDURE [dbo].[User_BumpAccountRevisionDateByCollectionId] +END +GO + +CREATE PROCEDURE [dbo].[User_BumpAccountRevisionDateByCollectionId] + @CollectionId UNIQUEIDENTIFIER, + @OrganizationId UNIQUEIDENTIFIER +AS +BEGIN + SET NOCOUNT ON + + UPDATE + U + SET + U.[AccountRevisionDate] = GETUTCDATE() + FROM + [dbo].[User] U + LEFT JOIN + [dbo].[OrganizationUser] OU ON OU.[UserId] = U.[Id] + LEFT JOIN + [dbo].[CollectionUser] CU ON OU.[AccessAll] = 0 AND CU.[OrganizationUserId] = OU.[Id] AND CU.[CollectionId] = @CollectionId + LEFT JOIN + [dbo].[GroupUser] GU ON CU.[CollectionId] IS NULL AND OU.[AccessAll] = 0 AND GU.[OrganizationUserId] = OU.[Id] + LEFT JOIN + [dbo].[Group] G ON G.[Id] = GU.[GroupId] + LEFT JOIN + [dbo].[CollectionGroup] CG ON G.[AccessAll] = 0 AND CG.[GroupId] = GU.[GroupId] AND CG.[CollectionId] = @CollectionId + WHERE + OU.[Status] = 2 -- 2 = Confirmed + AND ( + CU.[CollectionId] IS NOT NULL + OR CG.[CollectionId] IS NOT NULL + OR ( + OU.[OrganizationId] = @OrganizationId + AND ( + OU.[AccessAll] = 1 + OR G.[AccessAll] = 1 + ) + ) + ) +END +GO + +IF OBJECT_ID('[dbo].[Cipher_DeleteByUserId]') IS NOT NULL BEGIN DROP PROCEDURE [dbo].[Cipher_DeleteByUserId] END @@ -1130,95 +1222,3 @@ BEGIN [Id] = @Id END GO - -IF OBJECT_ID('[dbo].[User_BumpAccountRevisionDateByCipherId]') IS NOT NULL -BEGIN - DROP PROCEDURE [dbo].[User_BumpAccountRevisionDateByCipherId] -END -GO - -CREATE PROCEDURE [dbo].[User_BumpAccountRevisionDateByCipherId] - @CipherId UNIQUEIDENTIFIER, - @OrganizationId UNIQUEIDENTIFIER -AS -BEGIN - SET NOCOUNT ON - - UPDATE - U - SET - U.[AccountRevisionDate] = GETUTCDATE() - FROM - [dbo].[User] U - LEFT JOIN - [dbo].[OrganizationUser] OU ON OU.[UserId] = U.[Id] - LEFT JOIN - [dbo].[CollectionCipher] CC ON CC.[CipherId] = @CipherId - LEFT JOIN - [dbo].[CollectionUser] CU ON OU.[AccessAll] = 0 AND CU.[OrganizationUserId] = OU.[Id] AND CU.[CollectionId] = CC.[CollectionId] - LEFT JOIN - [dbo].[GroupUser] GU ON CU.[CollectionId] IS NULL AND OU.[AccessAll] = 0 AND GU.[OrganizationUserId] = OU.[Id] - LEFT JOIN - [dbo].[Group] G ON G.[Id] = GU.[GroupId] - LEFT JOIN - [dbo].[CollectionGroup] CG ON G.[AccessAll] = 0 AND CG.[GroupId] = GU.[GroupId] AND CG.[CollectionId] = CC.[CollectionId] - WHERE - OU.[Status] = 2 -- 2 = Confirmed - AND ( - CU.[CollectionId] IS NOT NULL - OR CG.[CollectionId] IS NOT NULL - OR ( - OU.[OrganizationId] = @OrganizationId - AND ( - OU.[AccessAll] = 1 - OR G.[AccessAll] = 1 - ) - ) - ) -END -GO - -IF OBJECT_ID('[dbo].[User_BumpAccountRevisionDateByCollectionId]') IS NOT NULL -BEGIN - DROP PROCEDURE [dbo].[User_BumpAccountRevisionDateByCollectionId] -END -GO - -CREATE PROCEDURE [dbo].[User_BumpAccountRevisionDateByCollectionId] - @CollectionId UNIQUEIDENTIFIER, - @OrganizationId UNIQUEIDENTIFIER -AS -BEGIN - SET NOCOUNT ON - - UPDATE - U - SET - U.[AccountRevisionDate] = GETUTCDATE() - FROM - [dbo].[User] U - LEFT JOIN - [dbo].[OrganizationUser] OU ON OU.[UserId] = U.[Id] - LEFT JOIN - [dbo].[CollectionUser] CU ON OU.[AccessAll] = 0 AND CU.[OrganizationUserId] = OU.[Id] AND CU.[CollectionId] = @CollectionId - LEFT JOIN - [dbo].[GroupUser] GU ON CU.[CollectionId] IS NULL AND OU.[AccessAll] = 0 AND GU.[OrganizationUserId] = OU.[Id] - LEFT JOIN - [dbo].[Group] G ON G.[Id] = GU.[GroupId] - LEFT JOIN - [dbo].[CollectionGroup] CG ON G.[AccessAll] = 0 AND CG.[GroupId] = GU.[GroupId] AND CG.[CollectionId] = @CollectionId - WHERE - OU.[Status] = 2 -- 2 = Confirmed - AND ( - CU.[CollectionId] IS NOT NULL - OR CG.[CollectionId] IS NOT NULL - OR ( - OU.[OrganizationId] = @OrganizationId - AND ( - OU.[AccessAll] = 1 - OR G.[AccessAll] = 1 - ) - ) - ) -END -GO