1
0
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:
Kyle Spearrin
2017-06-30 14:41:57 -04:00
parent 6cea556ae1
commit 284078e946
17 changed files with 178 additions and 23 deletions

View File

@ -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>

View File

@ -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

View File

@ -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,

View File

@ -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,

View 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

View File

@ -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
)

View File

@ -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

View 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

View File

@ -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,

View File

@ -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)