1
0
mirror of https://github.com/bitwarden/server.git synced 2025-04-05 05:00:19 -05:00
bitwarden/src/Sql/dbo/Tables/Transaction.sql
Alex Morask 9f7e05869e
[AC-1900] Update Vault DB to support provider billing (#3875)
* Add Gateway columns to Provider table

* Add ProviderId column to Transaction table

* Create ProviderPlan table

* Matt's feedback

* Rui's feedback

* Fixed Gateway parameter on Provider
2024-03-21 11:15:49 -04:00

29 lines
1.5 KiB
Transact-SQL

CREATE TABLE [dbo].[Transaction] (
[Id] UNIQUEIDENTIFIER NOT NULL,
[UserId] UNIQUEIDENTIFIER NULL,
[OrganizationId] UNIQUEIDENTIFIER NULL,
[Type] TINYINT NOT NULL,
[Amount] MONEY NOT NULL,
[Refunded] BIT NULL,
[RefundedAmount] MONEY NULL,
[Details] NVARCHAR(100) NULL,
[PaymentMethodType] TINYINT NULL,
[Gateway] TINYINT NULL,
[GatewayId] VARCHAR(50) NULL,
[CreationDate] DATETIME2 (7) NOT NULL,
[ProviderId] UNIQUEIDENTIFIER NULL,
CONSTRAINT [PK_Transaction] PRIMARY KEY CLUSTERED ([Id] ASC),
CONSTRAINT [FK_Transaction_User] FOREIGN KEY ([UserId]) REFERENCES [dbo].[User] ([Id]) ON DELETE CASCADE,
CONSTRAINT [FK_Transaction_Organization] FOREIGN KEY ([OrganizationId]) REFERENCES [dbo].[Organization] ([Id]) ON DELETE CASCADE,
CONSTRAINT [FK_Transaction_Provider] FOREIGN KEY ([ProviderId]) REFERENCES [dbo].[Provider] ([Id]) ON DELETE CASCADE
);
GO
CREATE UNIQUE NONCLUSTERED INDEX [IX_Transaction_Gateway_GatewayId]
ON [dbo].[Transaction]([Gateway] ASC, [GatewayId] ASC)
WHERE [Gateway] IS NOT NULL AND [GatewayId] IS NOT NULL;
GO
CREATE NONCLUSTERED INDEX [IX_Transaction_UserId_OrganizationId_CreationDate]
ON [dbo].[Transaction]([UserId] ASC, [OrganizationId] ASC, [CreationDate] ASC);