1
0
mirror of https://github.com/bitwarden/server.git synced 2024-11-25 12:45:18 +01:00
bitwarden-server/util/Migrator/DbScripts/2017-09-08_00_OrgUserCounts.sql
2019-03-25 13:23:50 -04:00

49 lines
1.1 KiB
Transact-SQL

IF OBJECT_ID('[dbo].[OrganizationUser_ReadCountByFreeOrganizationAdminUser]') IS NOT NULL
BEGIN
DROP PROCEDURE [dbo].[OrganizationUser_ReadCountByFreeOrganizationAdminUser]
END
GO
CREATE PROCEDURE [dbo].[OrganizationUser_ReadCountByFreeOrganizationAdminUser]
@UserId UNIQUEIDENTIFIER
AS
BEGIN
SET NOCOUNT ON
SELECT
COUNT(1)
FROM
[dbo].[OrganizationUser] OU
INNER JOIN
[dbo].[Organization] O ON O.Id = OU.[OrganizationId]
WHERE
OU.[UserId] = @UserId
AND OU.[Type] < 2 -- Owner or Admin
AND O.[PlanType] = 0 -- Free
AND OU.[Status] = 2 -- 2 = Confirmed
END
GO
IF OBJECT_ID('[dbo].[OrganizationUser_ReadCountByOrganizationOwnerUser]') IS NOT NULL
BEGIN
DROP PROCEDURE [dbo].[OrganizationUser_ReadCountByOrganizationOwnerUser]
END
GO
CREATE PROCEDURE [dbo].[OrganizationUser_ReadCountByOrganizationOwnerUser]
@UserId UNIQUEIDENTIFIER
AS
BEGIN
SET NOCOUNT ON
SELECT
COUNT(1)
FROM
[dbo].[OrganizationUser] OU
WHERE
OU.[UserId] = @UserId
AND OU.[Type] = 0
AND OU.[Status] = 2 -- 2 = Confirmed
END
GO