1
0
mirror of https://github.com/bitwarden/server synced 2026-01-03 09:03:44 +00:00

[PM-20452] - Offloading Stripe Update (#6034)

* Adding job to update stripe subscriptions and increment seat count  when inviting a user.

* Updating name

* Added ef migrations

* Fixing script

* Fixing procedures. Added repo tests.

* Fixed set stored procedure. Fixed parameter name.

* Added tests for database calls and updated stored procedures

* Fixed build for sql file.

* fixing sproc

* File is nullsafe

* Adding view to select from instead of table.

* Updating UpdateSubscriptionStatus to use a CTE and do all the updates in 1 statement.

* Setting revision date when incrementing seat count

* Added feature flag check for the background job.

* Fixing nullable property.

* Removing new table and just adding the column to org. Updating to query and command. Updated tests.

* Adding migration script rename

* Add SyncSeats to Org.sql def

* Adding contraint name

* Removing old table files.

* Added tests

* Upped the frequency to be at the top of every 3rd hour.

* Updating error message.

* Removing extension method

* Changed to GuidIdArray

* Added xml doc and switched class to record
This commit is contained in:
Jared McCannon
2025-07-31 07:54:51 -05:00
committed by GitHub
parent 88dd977848
commit 86ce3a86e9
38 changed files with 10968 additions and 43 deletions

View File

@@ -57,7 +57,8 @@ CREATE PROCEDURE [dbo].[Organization_Create]
@UseRiskInsights BIT = 0,
@LimitItemDeletion BIT = 0,
@UseOrganizationDomains BIT = 0,
@UseAdminSponsoredFamilies BIT = 0
@UseAdminSponsoredFamilies BIT = 0,
@SyncSeats BIT = 0
AS
BEGIN
SET NOCOUNT ON
@@ -122,7 +123,8 @@ BEGIN
[UseRiskInsights],
[LimitItemDeletion],
[UseOrganizationDomains],
[UseAdminSponsoredFamilies]
[UseAdminSponsoredFamilies],
[SyncSeats]
)
VALUES
(
@@ -184,6 +186,7 @@ BEGIN
@UseRiskInsights,
@LimitItemDeletion,
@UseOrganizationDomains,
@UseAdminSponsoredFamilies
@UseAdminSponsoredFamilies,
@SyncSeats
)
END

View File

@@ -0,0 +1,7 @@
CREATE PROCEDURE [dbo].[Organization_GetOrganizationsForSubscriptionSync]
AS
BEGIN
SELECT *
FROM [dbo].[OrganizationView]
WHERE [Seats] IS NOT NULL AND [SyncSeats] = 1
END

View File

@@ -0,0 +1,15 @@
CREATE PROCEDURE [dbo].[Organization_IncrementSeatCount]
@OrganizationId UNIQUEIDENTIFIER,
@SeatsToAdd INT,
@RequestDate DATETIME2
AS
BEGIN
SET NOCOUNT ON
UPDATE [dbo].[Organization]
SET
[Seats] = [Seats] + @SeatsToAdd,
[SyncSeats] = 1,
[RevisionDate] = @RequestDate
WHERE [Id] = @OrganizationId
END

View File

@@ -57,7 +57,8 @@ CREATE PROCEDURE [dbo].[Organization_Update]
@UseRiskInsights BIT = 0,
@LimitItemDeletion BIT = 0,
@UseOrganizationDomains BIT = 0,
@UseAdminSponsoredFamilies BIT = 0
@UseAdminSponsoredFamilies BIT = 0,
@SyncSeats BIT = 0
AS
BEGIN
SET NOCOUNT ON
@@ -122,7 +123,8 @@ BEGIN
[UseRiskInsights] = @UseRiskInsights,
[LimitItemDeletion] = @LimitItemDeletion,
[UseOrganizationDomains] = @UseOrganizationDomains,
[UseAdminSponsoredFamilies] = @UseAdminSponsoredFamilies
[UseAdminSponsoredFamilies] = @UseAdminSponsoredFamilies,
[SyncSeats] = @SyncSeats
WHERE
[Id] = @Id
END

View File

@@ -0,0 +1,14 @@
CREATE PROCEDURE [dbo].[Organization_UpdateSubscriptionStatus]
@SuccessfulOrganizations AS [dbo].[GuidIdArray] READONLY,
@SyncDate DATETIME2
AS
BEGIN
SET NOCOUNT ON
UPDATE o
SET
[SyncSeats] = 0,
[RevisionDate] = @SyncDate
FROM [dbo].[Organization] o
INNER JOIN @SuccessfulOrganizations success on success.Id = o.Id
END

View File

@@ -58,6 +58,7 @@ CREATE TABLE [dbo].[Organization] (
[UseRiskInsights] BIT NOT NULL CONSTRAINT [DF_Organization_UseRiskInsights] DEFAULT (0),
[UseOrganizationDomains] BIT NOT NULL CONSTRAINT [DF_Organization_UseOrganizationDomains] DEFAULT (0),
[UseAdminSponsoredFamilies] BIT NOT NULL CONSTRAINT [DF_Organization_UseAdminSponsoredFamilies] DEFAULT (0),
[SyncSeats] BIT NOT NULL CONSTRAINT [DF_Organization_SyncSeats] DEFAULT (0),
CONSTRAINT [PK_Organization] PRIMARY KEY CLUSTERED ([Id] ASC)
);