mirror of
https://github.com/bitwarden/server.git
synced 2025-07-02 16:42:50 -05:00
database adjustments and storage for attachments
This commit is contained in:
@ -201,5 +201,10 @@
|
||||
<Build Include="dbo\User Defined Types\GuidIdArray.sql" />
|
||||
<Build Include="dbo\User Defined Types\SelectionReadOnlyArray.sql" />
|
||||
<Build Include="dbo\Stored Procedures\Cipher_UpdateAttachment.sql" />
|
||||
<Build Include="dbo\Stored Procedures\Organization_UpdateStorage.sql" />
|
||||
<Build Include="dbo\Stored Procedures\User_UpdateStorage.sql" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<RefactorLog Include="Sql.refactorlog" />
|
||||
</ItemGroup>
|
||||
</Project>
|
@ -10,6 +10,7 @@ BEGIN
|
||||
|
||||
DECLARE @AttachmentIdKey VARCHAR(50) = CONCAT('"', @AttachmentId, '"')
|
||||
DECLARE @AttachmentIdPath VARCHAR(50) = CONCAT('$.', @AttachmentIdKey)
|
||||
DECLARE @Size BIGINT = CAST(JSON_VALUE(@AttachmentData, '$.Size') AS BIGINT)
|
||||
|
||||
UPDATE
|
||||
[dbo].[Cipher]
|
||||
@ -26,10 +27,12 @@ BEGIN
|
||||
|
||||
IF @OrganizationId IS NOT NULL
|
||||
BEGIN
|
||||
EXEC [dbo].[Organization_UpdateStorage] @OrganizationId, @Size
|
||||
EXEC [dbo].[User_BumpAccountRevisionDateByOrganizationId] @OrganizationId
|
||||
END
|
||||
ELSE IF @UserId IS NOT NULL
|
||||
BEGIN
|
||||
EXEC [dbo].[User_UpdateStorage] @UserId, @Size
|
||||
EXEC [dbo].[User_BumpAccountRevisionDate] @UserId
|
||||
END
|
||||
END
|
@ -9,6 +9,8 @@
|
||||
@MaxCollections SMALLINT,
|
||||
@UseGroups BIT,
|
||||
@UseDirectory BIT,
|
||||
@Storage BIGINT,
|
||||
@MaxStorageGb SMALLINT,
|
||||
@StripeCustomerId VARCHAR(50),
|
||||
@StripeSubscriptionId VARCHAR(50),
|
||||
@Enabled BIT,
|
||||
@ -30,6 +32,8 @@ BEGIN
|
||||
[MaxCollections],
|
||||
[UseGroups],
|
||||
[UseDirectory],
|
||||
[Storage],
|
||||
[MaxStorageGb],
|
||||
[StripeCustomerId],
|
||||
[StripeSubscriptionId],
|
||||
[Enabled],
|
||||
@ -48,6 +52,8 @@ BEGIN
|
||||
@MaxCollections,
|
||||
@UseGroups,
|
||||
@UseDirectory,
|
||||
@Storage,
|
||||
@MaxStorageGb,
|
||||
@StripeCustomerId,
|
||||
@StripeSubscriptionId,
|
||||
@Enabled,
|
||||
|
@ -9,6 +9,8 @@
|
||||
@MaxCollections SMALLINT,
|
||||
@UseGroups BIT,
|
||||
@UseDirectory BIT,
|
||||
@Storage BIGINT,
|
||||
@MaxStorageGb SMALLINT,
|
||||
@StripeCustomerId VARCHAR(50),
|
||||
@StripeSubscriptionId VARCHAR(50),
|
||||
@Enabled BIT,
|
||||
@ -31,6 +33,8 @@ BEGIN
|
||||
[MaxCollections] = @MaxCollections,
|
||||
[UseGroups] = @UseGroups,
|
||||
[UseDirectory] = @UseDirectory,
|
||||
[Storage] = @Storage,
|
||||
[MaxStorageGb] = @MaxStorageGb,
|
||||
[StripeCustomerId] = @StripeCustomerId,
|
||||
[StripeSubscriptionId] = @StripeSubscriptionId,
|
||||
[Enabled] = @Enabled,
|
||||
|
16
src/Sql/dbo/Stored Procedures/Organization_UpdateStorage.sql
Normal file
16
src/Sql/dbo/Stored Procedures/Organization_UpdateStorage.sql
Normal file
@ -0,0 +1,16 @@
|
||||
CREATE PROCEDURE [dbo].[Organization_UpdateStorage]
|
||||
@Id UNIQUEIDENTIFIER,
|
||||
@StorageIncrease BIGINT
|
||||
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
UPDATE
|
||||
[dbo].[Organization]
|
||||
SET
|
||||
[Storage] = ISNULL([Storage], 0) + @StorageIncrease,
|
||||
[RevisionDate] = GETUTCDATE()
|
||||
WHERE
|
||||
[Id] = @Id
|
||||
END
|
@ -15,6 +15,9 @@
|
||||
@Key NVARCHAR(MAX),
|
||||
@PublicKey NVARCHAR(MAX),
|
||||
@PrivateKey NVARCHAR(MAX),
|
||||
@Premium BIT,
|
||||
@Storage BIGINT,
|
||||
@MaxStorageGb SMALLINT,
|
||||
@CreationDate DATETIME2(7),
|
||||
@RevisionDate DATETIME2(7)
|
||||
AS
|
||||
@ -39,6 +42,9 @@ BEGIN
|
||||
[Key],
|
||||
[PublicKey],
|
||||
[PrivateKey],
|
||||
[Premium],
|
||||
[Storage],
|
||||
[MaxStorageGb],
|
||||
[CreationDate],
|
||||
[RevisionDate]
|
||||
)
|
||||
@ -60,6 +66,9 @@ BEGIN
|
||||
@Key,
|
||||
@PublicKey,
|
||||
@PrivateKey,
|
||||
@Premium,
|
||||
@Storage,
|
||||
@MaxStorageGb,
|
||||
@CreationDate,
|
||||
@RevisionDate
|
||||
)
|
||||
|
@ -15,6 +15,9 @@
|
||||
@Key NVARCHAR(MAX),
|
||||
@PublicKey NVARCHAR(MAX),
|
||||
@PrivateKey NVARCHAR(MAX),
|
||||
@Premium BIT,
|
||||
@Storage BIGINT,
|
||||
@MaxStorageGb SMALLINT,
|
||||
@CreationDate DATETIME2(7),
|
||||
@RevisionDate DATETIME2(7)
|
||||
AS
|
||||
@ -39,6 +42,9 @@ BEGIN
|
||||
[Key] = @Key,
|
||||
[PublicKey] = @PublicKey,
|
||||
[PrivateKey] = @PrivateKey,
|
||||
[Premium] = @Premium,
|
||||
[Storage] = @Storage,
|
||||
[MaxStorageGb] = @MaxStorageGb,
|
||||
[CreationDate] = @CreationDate,
|
||||
[RevisionDate] = @RevisionDate
|
||||
WHERE
|
||||
|
16
src/Sql/dbo/Stored Procedures/User_UpdateStorage.sql
Normal file
16
src/Sql/dbo/Stored Procedures/User_UpdateStorage.sql
Normal file
@ -0,0 +1,16 @@
|
||||
CREATE PROCEDURE [dbo].[User_UpdateStorage]
|
||||
@Id UNIQUEIDENTIFIER,
|
||||
@StorageIncrease BIGINT
|
||||
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
UPDATE
|
||||
[dbo].[User]
|
||||
SET
|
||||
[Storage] = ISNULL([Storage], 0) + @StorageIncrease,
|
||||
[RevisionDate] = GETUTCDATE()
|
||||
WHERE
|
||||
[Id] = @Id
|
||||
END
|
@ -9,6 +9,8 @@
|
||||
[MaxCollections] SMALLINT NULL,
|
||||
[UseGroups] BIT NOT NULL,
|
||||
[UseDirectory] BIT NOT NULL,
|
||||
[Storage] BIGINT NULL,
|
||||
[MaxStorageGb] SMALLINT NULL,
|
||||
[StripeCustomerId] VARCHAR (50) NULL,
|
||||
[StripeSubscriptionId] VARCHAR (50) NULL,
|
||||
[Enabled] BIT NOT NULL,
|
||||
|
@ -15,6 +15,9 @@
|
||||
[Key] VARCHAR (MAX) NULL,
|
||||
[PublicKey] VARCHAR (MAX) NULL,
|
||||
[PrivateKey] VARCHAR (MAX) NULL,
|
||||
[Premium] BIT NOT NULL,
|
||||
[Storage] BIGINT NULL,
|
||||
[MaxStorageGb] SMALLINT NULL,
|
||||
[CreationDate] DATETIME2 (7) NOT NULL,
|
||||
[RevisionDate] DATETIME2 (7) NOT NULL,
|
||||
CONSTRAINT [PK_User] PRIMARY KEY CLUSTERED ([Id] ASC)
|
||||
|
Reference in New Issue
Block a user