1
0
mirror of https://github.com/bitwarden/server.git synced 2025-06-30 15:42:48 -05:00

[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
This commit is contained in:
Alex Morask
2024-03-21 11:15:49 -04:00
committed by GitHub
parent 43ee5a24ec
commit 9f7e05869e
44 changed files with 9139 additions and 45 deletions

View File

@ -0,0 +1,513 @@
-- Provider
-- Add 'Gateway' column to 'Provider' table.
IF COL_LENGTH('[dbo].[Provider]', 'Gateway') IS NULL
BEGIN
ALTER TABLE
[dbo].[Provider]
ADD
[Gateway] TINYINT NULL;
END
GO
-- Add 'GatewayCustomerId' column to 'Provider' table
IF COL_LENGTH('[dbo].[Provider]', 'GatewayCustomerId') IS NULL
BEGIN
ALTER TABLE
[dbo].[Provider]
ADD
[GatewayCustomerId] VARCHAR (50) NULL;
END
GO
-- Add 'GatewaySubscriptionId' column to 'Provider' table
IF COL_LENGTH('[dbo].[Provider]', 'GatewaySubscriptionId') IS NULL
BEGIN
ALTER TABLE
[dbo].[Provider]
ADD
[GatewaySubscriptionId] VARCHAR (50) NULL;
END
GO
-- Recreate 'ProviderView' so that it includes the 'Gateway', 'GatewayCustomerId' and 'GatewaySubscriptionId' columns.
CREATE OR ALTER VIEW [dbo].[ProviderView]
AS
SELECT
*
FROM
[dbo].[Provider]
GO
-- Alter 'Provider_Create' SPROC to add 'Gateway', 'GatewayCustomerId' and 'GatewaySubscriptionId' columns.
CREATE OR ALTER PROCEDURE [dbo].[Provider_Create]
@Id UNIQUEIDENTIFIER OUTPUT,
@Name NVARCHAR(50),
@BusinessName NVARCHAR(50),
@BusinessAddress1 NVARCHAR(50),
@BusinessAddress2 NVARCHAR(50),
@BusinessAddress3 NVARCHAR(50),
@BusinessCountry VARCHAR(2),
@BusinessTaxNumber NVARCHAR(30),
@BillingEmail NVARCHAR(256),
@BillingPhone NVARCHAR(50) = NULL,
@Status TINYINT,
@Type TINYINT = 0,
@UseEvents BIT,
@Enabled BIT,
@CreationDate DATETIME2(7),
@RevisionDate DATETIME2(7),
@Gateway TINYINT = 0,
@GatewayCustomerId VARCHAR(50) = NULL,
@GatewaySubscriptionId VARCHAR(50) = NULL
AS
BEGIN
SET NOCOUNT ON
INSERT INTO [dbo].[Provider]
(
[Id],
[Name],
[BusinessName],
[BusinessAddress1],
[BusinessAddress2],
[BusinessAddress3],
[BusinessCountry],
[BusinessTaxNumber],
[BillingEmail],
[BillingPhone],
[Status],
[Type],
[UseEvents],
[Enabled],
[CreationDate],
[RevisionDate],
[Gateway],
[GatewayCustomerId],
[GatewaySubscriptionId]
)
VALUES
(
@Id,
@Name,
@BusinessName,
@BusinessAddress1,
@BusinessAddress2,
@BusinessAddress3,
@BusinessCountry,
@BusinessTaxNumber,
@BillingEmail,
@BillingPhone,
@Status,
@Type,
@UseEvents,
@Enabled,
@CreationDate,
@RevisionDate,
@Gateway,
@GatewayCustomerId,
@GatewaySubscriptionId
)
END
GO
-- Alter 'Provider_Update' SPROC to add 'Gateway', 'GatewayCustomerId' and 'GatewaySubscriptionId' columns.
CREATE OR ALTER PROCEDURE [dbo].[Provider_Update]
@Id UNIQUEIDENTIFIER,
@Name NVARCHAR(50),
@BusinessName NVARCHAR(50),
@BusinessAddress1 NVARCHAR(50),
@BusinessAddress2 NVARCHAR(50),
@BusinessAddress3 NVARCHAR(50),
@BusinessCountry VARCHAR(2),
@BusinessTaxNumber NVARCHAR(30),
@BillingEmail NVARCHAR(256),
@BillingPhone NVARCHAR(50) = NULL,
@Status TINYINT,
@Type TINYINT = 0,
@UseEvents BIT,
@Enabled BIT,
@CreationDate DATETIME2(7),
@RevisionDate DATETIME2(7),
@Gateway TINYINT = 0,
@GatewayCustomerId VARCHAR(50) = NULL,
@GatewaySubscriptionId VARCHAR(50) = NULL
AS
BEGIN
SET NOCOUNT ON
UPDATE
[dbo].[Provider]
SET
[Name] = @Name,
[BusinessName] = @BusinessName,
[BusinessAddress1] = @BusinessAddress1,
[BusinessAddress2] = @BusinessAddress2,
[BusinessAddress3] = @BusinessAddress3,
[BusinessCountry] = @BusinessCountry,
[BusinessTaxNumber] = @BusinessTaxNumber,
[BillingEmail] = @BillingEmail,
[BillingPhone] = @BillingPhone,
[Status] = @Status,
[Type] = @Type,
[UseEvents] = @UseEvents,
[Enabled] = @Enabled,
[CreationDate] = @CreationDate,
[RevisionDate] = @RevisionDate,
[Gateway] = @Gateway,
[GatewayCustomerId] = @GatewayCustomerId,
[GatewaySubscriptionId] = @GatewaySubscriptionId
WHERE
[Id] = @Id
END
GO
-- Refresh modules for SPROCs reliant on 'Provider' table/view.
IF OBJECT_ID('[dbo].[Provider_ReadAbilities]') IS NOT NULL
BEGIN
EXECUTE sp_refreshsqlmodule N'[dbo].[Provider_ReadAbilities]';
END
GO
IF OBJECT_ID('[dbo].[Provider_ReadById]') IS NOT NULL
BEGIN
EXECUTE sp_refreshsqlmodule N'[dbo].[Provider_ReadById]';
END
GO
IF OBJECT_ID('[dbo].[Provider_ReadByOrganizationId]') IS NOT NULL
BEGIN
EXECUTE sp_refreshsqlmodule N'[dbo].[Provider_ReadByOrganizationId]';
END
GO
IF OBJECT_ID('[dbo].[Provider_Search]') IS NOT NULL
BEGIN
EXECUTE sp_refreshsqlmodule N'[dbo].[Provider_Search]';
END
GO
-- Transaction
-- Add 'ProviderId' column to 'Transaction' table.
IF COL_LENGTH('[dbo].[Transaction]', 'ProviderId') IS NULL
BEGIN
ALTER TABLE
[dbo].[Transaction]
ADD
[ProviderId] UNIQUEIDENTIFIER NULL,
CONSTRAINT
[FK_Transaction_Provider] FOREIGN KEY ([ProviderId]) REFERENCES [dbo].[Provider] ([Id]) ON DELETE CASCADE;
END
GO
-- Recreate 'TransactionView' so that it includes the 'ProviderId' column.
CREATE OR ALTER VIEW [dbo].[TransactionView]
AS
SELECT
*
FROM
[dbo].[Transaction]
GO
-- Alter 'Transaction_Create' SPROC to add 'ProviderId' column.
CREATE OR ALTER PROCEDURE [dbo].[Transaction_Create]
@Id UNIQUEIDENTIFIER OUTPUT,
@UserId UNIQUEIDENTIFIER,
@OrganizationId UNIQUEIDENTIFIER,
@Type TINYINT,
@Amount MONEY,
@Refunded BIT,
@RefundedAmount MONEY,
@Details NVARCHAR(100),
@PaymentMethodType TINYINT,
@Gateway TINYINT,
@GatewayId VARCHAR(50),
@CreationDate DATETIME2(7),
@ProviderId UNIQUEIDENTIFIER = NULL
AS
BEGIN
SET NOCOUNT ON
INSERT INTO [dbo].[Transaction]
(
[Id],
[UserId],
[OrganizationId],
[Type],
[Amount],
[Refunded],
[RefundedAmount],
[Details],
[PaymentMethodType],
[Gateway],
[GatewayId],
[CreationDate],
[ProviderId]
)
VALUES
(
@Id,
@UserId,
@OrganizationId,
@Type,
@Amount,
@Refunded,
@RefundedAmount,
@Details,
@PaymentMethodType,
@Gateway,
@GatewayId,
@CreationDate,
@ProviderId
)
END
GO
-- Alter 'Transaction_Update' SPROC to add 'ProviderId' column.
CREATE OR ALTER PROCEDURE [dbo].[Transaction_Update]
@Id UNIQUEIDENTIFIER,
@UserId UNIQUEIDENTIFIER,
@OrganizationId UNIQUEIDENTIFIER,
@Type TINYINT,
@Amount MONEY,
@Refunded BIT,
@RefundedAmount MONEY,
@Details NVARCHAR(100),
@PaymentMethodType TINYINT,
@Gateway TINYINT,
@GatewayId VARCHAR(50),
@CreationDate DATETIME2(7),
@ProviderId UNIQUEIDENTIFIER = NULL
AS
BEGIN
SET NOCOUNT ON
UPDATE
[dbo].[Transaction]
SET
[UserId] = @UserId,
[OrganizationId] = @OrganizationId,
[Type] = @Type,
[Amount] = @Amount,
[Refunded] = @Refunded,
[RefundedAmount] = @RefundedAmount,
[Details] = @Details,
[PaymentMethodType] = @PaymentMethodType,
[Gateway] = @Gateway,
[GatewayId] = @GatewayId,
[CreationDate] = @CreationDate,
[ProviderId] = @ProviderId
WHERE
[Id] = @Id
END
GO
-- Add ReadByProviderId SPROC
IF OBJECT_ID('[dbo].[Transaction_ReadByProviderId]') IS NOT NULL
BEGIN
DROP PROCEDURE [dbo].[Transaction_ReadByProviderId]
END
GO
CREATE PROCEDURE [dbo].[Transaction_ReadByProviderId]
@ProviderId UNIQUEIDENTIFIER
AS
BEGIN
SET NOCOUNT ON
SELECT
*
FROM
[dbo].[TransactionView]
WHERE
[ProviderId] = @ProviderId
END
GO
-- Refresh modules for SPROCs reliant on 'Transaction' table/view.
IF OBJECT_ID('[dbo].[Transaction_ReadByGatewayId]') IS NOT NULL
BEGIN
EXECUTE sp_refreshsqlmodule N'[dbo].[Transaction_ReadByGatewayId]';
END
GO
IF OBJECT_ID('[dbo].[Transaction_ReadById]') IS NOT NULL
BEGIN
EXECUTE sp_refreshsqlmodule N'[dbo].[Transaction_ReadById]';
END
GO
IF OBJECT_ID('[dbo].[Transaction_ReadByOrganizationId]') IS NOT NULL
BEGIN
EXECUTE sp_refreshsqlmodule N'[dbo].[Transaction_ReadByOrganizationId]';
END
GO
IF OBJECT_ID('[dbo].[Transaction_ReadByUserId]') IS NOT NULL
BEGIN
EXECUTE sp_refreshsqlmodule N'[dbo].[Transaction_ReadByUserId]';
END
GO
-- Provider Plan
-- Table
IF OBJECT_ID('[dbo].[ProviderPlan]') IS NULL
BEGIN
CREATE TABLE [dbo].[ProviderPlan] (
[Id] UNIQUEIDENTIFIER NOT NULL,
[ProviderId] UNIQUEIDENTIFIER NOT NULL,
[PlanType] TINYINT NOT NULL,
[SeatMinimum] INT NULL,
[PurchasedSeats] INT NULL,
[AllocatedSeats] INT NULL,
CONSTRAINT [PK_ProviderPlan] PRIMARY KEY CLUSTERED ([Id] ASC),
CONSTRAINT [FK_ProviderPlan_Provider] FOREIGN KEY ([ProviderId]) REFERENCES [dbo].[Provider] ([Id]) ON DELETE CASCADE,
CONSTRAINT [PK_ProviderPlanType] UNIQUE ([ProviderId], [PlanType])
);
END
GO
-- View
IF EXISTS(SELECT * FROM sys.views WHERE [Name] = 'ProviderPlanView')
BEGIN
DROP VIEW [dbo].[ProviderPlanView]
END
GO
CREATE VIEW [dbo].[ProviderPlanView]
AS
SELECT
*
FROM
[dbo].[ProviderPlan]
GO
CREATE PROCEDURE [dbo].[ProviderPlan_Create]
@Id UNIQUEIDENTIFIER OUTPUT,
@ProviderId UNIQUEIDENTIFIER,
@PlanType TINYINT,
@SeatMinimum INT,
@PurchasedSeats INT,
@AllocatedSeats INT
AS
BEGIN
SET NOCOUNT ON
INSERT INTO [dbo].[ProviderPlan]
(
[Id],
[ProviderId],
[PlanType],
[SeatMinimum],
[PurchasedSeats],
[AllocatedSeats]
)
VALUES
(
@Id,
@ProviderId,
@PlanType,
@SeatMinimum,
@PurchasedSeats,
@AllocatedSeats
)
END
GO
-- DeleteById SPROC
IF OBJECT_ID('[dbo].[ProviderPlan_DeleteById]') IS NOT NULL
BEGIN
DROP PROCEDURE [dbo].[ProviderPlan_DeleteById]
END
GO
CREATE PROCEDURE [dbo].[ProviderPlan_DeleteById]
@Id UNIQUEIDENTIFIER
AS
BEGIN
SET NOCOUNT ON
DELETE
FROM
[dbo].[ProviderPlan]
WHERE
[Id] = @Id
END
GO
-- ReadById SPROC
IF OBJECT_ID('[dbo].[ProviderPlan_ReadById]') IS NOT NULL
BEGIN
DROP PROCEDURE [dbo].[ProviderPlan_ReadById]
END
GO
CREATE PROCEDURE [dbo].[ProviderPlan_ReadById]
@Id UNIQUEIDENTIFIER
AS
BEGIN
SET NOCOUNT ON
SELECT
*
FROM
[dbo].[ProviderPlanView]
WHERE
[Id] = @Id
END
GO
-- ReadByProviderId SPROC
IF OBJECT_ID('[dbo].[ProviderPlan_ReadByProviderId]') IS NOT NULL
BEGIN
DROP PROCEDURE [dbo].[ProviderPlan_ReadByProviderId]
END
GO
CREATE PROCEDURE [dbo].[ProviderPlan_ReadByProviderId]
@ProviderId UNIQUEIDENTIFIER
AS
BEGIN
SET NOCOUNT ON
SELECT
*
FROM
[dbo].[ProviderPlanView]
WHERE
[ProviderId] = @ProviderId
END
GO
-- Update SPROC
IF OBJECT_ID('[dbo].[ProviderPlan_Update]') IS NOT NULL
BEGIN
DROP PROCEDURE [dbo].[ProviderPlan_Update]
END
GO
CREATE PROCEDURE [dbo].[ProviderPlan_Update]
@Id UNIQUEIDENTIFIER,
@ProviderId UNIQUEIDENTIFIER,
@PlanType TINYINT,
@SeatMinimum INT,
@PurchasedSeats INT,
@AllocatedSeats INT
AS
BEGIN
SET NOCOUNT ON
UPDATE
[dbo].[ProviderPlan]
SET
[ProviderId] = @ProviderId,
[PlanType] = @PlanType,
[SeatMinimum] = @SeatMinimum,
[PurchasedSeats] = @PurchasedSeats,
[AllocatedSeats] = @AllocatedSeats
WHERE
[Id] = @Id
END
GO

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,117 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Bit.MySqlMigrations.Migrations;
/// <inheritdoc />
public partial class SetupProviderBilling : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<Guid>(
name: "ProviderId",
table: "Transaction",
type: "char(36)",
nullable: true,
collation: "ascii_general_ci");
migrationBuilder.AddColumn<string>(
name: "GatewayCustomerId",
table: "Provider",
type: "longtext",
nullable: true)
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<string>(
name: "GatewaySubscriptionId",
table: "Provider",
type: "longtext",
nullable: true)
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<byte>(
name: "GatewayType",
table: "Provider",
type: "tinyint unsigned",
nullable: true);
migrationBuilder.CreateTable(
name: "ProviderPlan",
columns: table => new
{
Id = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
ProviderId = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
PlanType = table.Column<byte>(type: "tinyint unsigned", nullable: false),
SeatMinimum = table.Column<int>(type: "int", nullable: true),
PurchasedSeats = table.Column<int>(type: "int", nullable: true),
AllocatedSeats = table.Column<int>(type: "int", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_ProviderPlan", x => x.Id);
table.ForeignKey(
name: "FK_ProviderPlan_Provider_ProviderId",
column: x => x.ProviderId,
principalTable: "Provider",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateIndex(
name: "IX_Transaction_ProviderId",
table: "Transaction",
column: "ProviderId");
migrationBuilder.CreateIndex(
name: "IX_ProviderPlan_Id_PlanType",
table: "ProviderPlan",
columns: new[] { "Id", "PlanType" },
unique: true);
migrationBuilder.CreateIndex(
name: "IX_ProviderPlan_ProviderId",
table: "ProviderPlan",
column: "ProviderId");
migrationBuilder.AddForeignKey(
name: "FK_Transaction_Provider_ProviderId",
table: "Transaction",
column: "ProviderId",
principalTable: "Provider",
principalColumn: "Id");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Transaction_Provider_ProviderId",
table: "Transaction");
migrationBuilder.DropTable(
name: "ProviderPlan");
migrationBuilder.DropIndex(
name: "IX_Transaction_ProviderId",
table: "Transaction");
migrationBuilder.DropColumn(
name: "ProviderId",
table: "Transaction");
migrationBuilder.DropColumn(
name: "GatewayCustomerId",
table: "Provider");
migrationBuilder.DropColumn(
name: "GatewaySubscriptionId",
table: "Provider");
migrationBuilder.DropColumn(
name: "GatewayType",
table: "Provider");
}
}

View File

@ -4,7 +4,6 @@ using Bit.Infrastructure.EntityFramework.Repositories;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
@ -17,7 +16,7 @@ namespace Bit.MySqlMigrations.Migrations
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.15")
.HasAnnotation("ProductVersion", "7.0.16")
.HasAnnotation("Relational:MaxIdentifierLength", 64);
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.AdminConsole.Models.Organization", b =>
@ -277,6 +276,15 @@ namespace Bit.MySqlMigrations.Migrations
b.Property<bool>("Enabled")
.HasColumnType("tinyint(1)");
b.Property<string>("GatewayCustomerId")
.HasColumnType("longtext");
b.Property<string>("GatewaySubscriptionId")
.HasColumnType("longtext");
b.Property<byte?>("GatewayType")
.HasColumnType("tinyint unsigned");
b.Property<string>("Name")
.HasColumnType("longtext");
@ -486,8 +494,7 @@ namespace Bit.MySqlMigrations.Migrations
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
.HasColumnType("int");
b.Property<string>("ClientId")
.IsRequired()
@ -666,6 +673,36 @@ namespace Bit.MySqlMigrations.Migrations
b.ToTable("WebAuthnCredential", (string)null);
});
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Billing.Models.ProviderPlan", b =>
{
b.Property<Guid>("Id")
.HasColumnType("char(36)");
b.Property<int?>("AllocatedSeats")
.HasColumnType("int");
b.Property<byte>("PlanType")
.HasColumnType("tinyint unsigned");
b.Property<Guid>("ProviderId")
.HasColumnType("char(36)");
b.Property<int?>("PurchasedSeats")
.HasColumnType("int");
b.Property<int?>("SeatMinimum")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("ProviderId");
b.HasIndex("Id", "PlanType")
.IsUnique();
b.ToTable("ProviderPlan", (string)null);
});
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Models.Collection", b =>
{
b.Property<Guid>("Id")
@ -1273,6 +1310,9 @@ namespace Bit.MySqlMigrations.Migrations
b.Property<byte?>("PaymentMethodType")
.HasColumnType("tinyint unsigned");
b.Property<Guid?>("ProviderId")
.HasColumnType("char(36)");
b.Property<bool?>("Refunded")
.HasColumnType("tinyint(1)");
@ -1289,6 +1329,8 @@ namespace Bit.MySqlMigrations.Migrations
b.HasIndex("OrganizationId");
b.HasIndex("ProviderId");
b.HasIndex("UserId")
.HasAnnotation("SqlServer:Clustered", false);
@ -2008,6 +2050,17 @@ namespace Bit.MySqlMigrations.Migrations
b.Navigation("User");
});
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Billing.Models.ProviderPlan", b =>
{
b.HasOne("Bit.Infrastructure.EntityFramework.AdminConsole.Models.Provider.Provider", "Provider")
.WithMany()
.HasForeignKey("ProviderId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Provider");
});
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Models.Collection", b =>
{
b.HasOne("Bit.Infrastructure.EntityFramework.AdminConsole.Models.Organization", "Organization")
@ -2203,12 +2256,18 @@ namespace Bit.MySqlMigrations.Migrations
.WithMany("Transactions")
.HasForeignKey("OrganizationId");
b.HasOne("Bit.Infrastructure.EntityFramework.AdminConsole.Models.Provider.Provider", "Provider")
.WithMany()
.HasForeignKey("ProviderId");
b.HasOne("Bit.Infrastructure.EntityFramework.Models.User", "User")
.WithMany("Transactions")
.HasForeignKey("UserId");
b.Navigation("Organization");
b.Navigation("Provider");
b.Navigation("User");
});

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,113 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Bit.PostgresMigrations.Migrations;
/// <inheritdoc />
public partial class SetupProviderBilling : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<Guid>(
name: "ProviderId",
table: "Transaction",
type: "uuid",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "GatewayCustomerId",
table: "Provider",
type: "text",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "GatewaySubscriptionId",
table: "Provider",
type: "text",
nullable: true);
migrationBuilder.AddColumn<byte>(
name: "GatewayType",
table: "Provider",
type: "smallint",
nullable: true);
migrationBuilder.CreateTable(
name: "ProviderPlan",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
ProviderId = table.Column<Guid>(type: "uuid", nullable: false),
PlanType = table.Column<byte>(type: "smallint", nullable: false),
SeatMinimum = table.Column<int>(type: "integer", nullable: true),
PurchasedSeats = table.Column<int>(type: "integer", nullable: true),
AllocatedSeats = table.Column<int>(type: "integer", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_ProviderPlan", x => x.Id);
table.ForeignKey(
name: "FK_ProviderPlan_Provider_ProviderId",
column: x => x.ProviderId,
principalTable: "Provider",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_Transaction_ProviderId",
table: "Transaction",
column: "ProviderId");
migrationBuilder.CreateIndex(
name: "IX_ProviderPlan_Id_PlanType",
table: "ProviderPlan",
columns: new[] { "Id", "PlanType" },
unique: true);
migrationBuilder.CreateIndex(
name: "IX_ProviderPlan_ProviderId",
table: "ProviderPlan",
column: "ProviderId");
migrationBuilder.AddForeignKey(
name: "FK_Transaction_Provider_ProviderId",
table: "Transaction",
column: "ProviderId",
principalTable: "Provider",
principalColumn: "Id");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Transaction_Provider_ProviderId",
table: "Transaction");
migrationBuilder.DropTable(
name: "ProviderPlan");
migrationBuilder.DropIndex(
name: "IX_Transaction_ProviderId",
table: "Transaction");
migrationBuilder.DropColumn(
name: "ProviderId",
table: "Transaction");
migrationBuilder.DropColumn(
name: "GatewayCustomerId",
table: "Provider");
migrationBuilder.DropColumn(
name: "GatewaySubscriptionId",
table: "Provider");
migrationBuilder.DropColumn(
name: "GatewayType",
table: "Provider");
}
}

View File

@ -18,7 +18,7 @@ namespace Bit.PostgresMigrations.Migrations
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("Npgsql:CollationDefinition:postgresIndetermanisticCollation", "en-u-ks-primary,en-u-ks-primary,icu,False")
.HasAnnotation("ProductVersion", "7.0.15")
.HasAnnotation("ProductVersion", "7.0.16")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
@ -282,6 +282,15 @@ namespace Bit.PostgresMigrations.Migrations
b.Property<bool>("Enabled")
.HasColumnType("boolean");
b.Property<string>("GatewayCustomerId")
.HasColumnType("text");
b.Property<string>("GatewaySubscriptionId")
.HasColumnType("text");
b.Property<byte?>("GatewayType")
.HasColumnType("smallint");
b.Property<string>("Name")
.HasColumnType("text");
@ -678,6 +687,36 @@ namespace Bit.PostgresMigrations.Migrations
b.ToTable("WebAuthnCredential", (string)null);
});
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Billing.Models.ProviderPlan", b =>
{
b.Property<Guid>("Id")
.HasColumnType("uuid");
b.Property<int?>("AllocatedSeats")
.HasColumnType("integer");
b.Property<byte>("PlanType")
.HasColumnType("smallint");
b.Property<Guid>("ProviderId")
.HasColumnType("uuid");
b.Property<int?>("PurchasedSeats")
.HasColumnType("integer");
b.Property<int?>("SeatMinimum")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("ProviderId");
b.HasIndex("Id", "PlanType")
.IsUnique();
b.ToTable("ProviderPlan", (string)null);
});
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Models.Collection", b =>
{
b.Property<Guid>("Id")
@ -1286,6 +1325,9 @@ namespace Bit.PostgresMigrations.Migrations
b.Property<byte?>("PaymentMethodType")
.HasColumnType("smallint");
b.Property<Guid?>("ProviderId")
.HasColumnType("uuid");
b.Property<bool?>("Refunded")
.HasColumnType("boolean");
@ -1302,6 +1344,8 @@ namespace Bit.PostgresMigrations.Migrations
b.HasIndex("OrganizationId");
b.HasIndex("ProviderId");
b.HasIndex("UserId")
.HasAnnotation("SqlServer:Clustered", false);
@ -2022,6 +2066,17 @@ namespace Bit.PostgresMigrations.Migrations
b.Navigation("User");
});
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Billing.Models.ProviderPlan", b =>
{
b.HasOne("Bit.Infrastructure.EntityFramework.AdminConsole.Models.Provider.Provider", "Provider")
.WithMany()
.HasForeignKey("ProviderId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Provider");
});
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Models.Collection", b =>
{
b.HasOne("Bit.Infrastructure.EntityFramework.AdminConsole.Models.Organization", "Organization")
@ -2217,12 +2272,18 @@ namespace Bit.PostgresMigrations.Migrations
.WithMany("Transactions")
.HasForeignKey("OrganizationId");
b.HasOne("Bit.Infrastructure.EntityFramework.AdminConsole.Models.Provider.Provider", "Provider")
.WithMany()
.HasForeignKey("ProviderId");
b.HasOne("Bit.Infrastructure.EntityFramework.Models.User", "User")
.WithMany("Transactions")
.HasForeignKey("UserId");
b.Navigation("Organization");
b.Navigation("Provider");
b.Navigation("User");
});

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,113 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Bit.SqliteMigrations.Migrations;
/// <inheritdoc />
public partial class SetupProviderBilling : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<Guid>(
name: "ProviderId",
table: "Transaction",
type: "TEXT",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "GatewayCustomerId",
table: "Provider",
type: "TEXT",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "GatewaySubscriptionId",
table: "Provider",
type: "TEXT",
nullable: true);
migrationBuilder.AddColumn<byte>(
name: "GatewayType",
table: "Provider",
type: "INTEGER",
nullable: true);
migrationBuilder.CreateTable(
name: "ProviderPlan",
columns: table => new
{
Id = table.Column<Guid>(type: "TEXT", nullable: false),
ProviderId = table.Column<Guid>(type: "TEXT", nullable: false),
PlanType = table.Column<byte>(type: "INTEGER", nullable: false),
SeatMinimum = table.Column<int>(type: "INTEGER", nullable: true),
PurchasedSeats = table.Column<int>(type: "INTEGER", nullable: true),
AllocatedSeats = table.Column<int>(type: "INTEGER", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_ProviderPlan", x => x.Id);
table.ForeignKey(
name: "FK_ProviderPlan_Provider_ProviderId",
column: x => x.ProviderId,
principalTable: "Provider",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_Transaction_ProviderId",
table: "Transaction",
column: "ProviderId");
migrationBuilder.CreateIndex(
name: "IX_ProviderPlan_Id_PlanType",
table: "ProviderPlan",
columns: new[] { "Id", "PlanType" },
unique: true);
migrationBuilder.CreateIndex(
name: "IX_ProviderPlan_ProviderId",
table: "ProviderPlan",
column: "ProviderId");
migrationBuilder.AddForeignKey(
name: "FK_Transaction_Provider_ProviderId",
table: "Transaction",
column: "ProviderId",
principalTable: "Provider",
principalColumn: "Id");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Transaction_Provider_ProviderId",
table: "Transaction");
migrationBuilder.DropTable(
name: "ProviderPlan");
migrationBuilder.DropIndex(
name: "IX_Transaction_ProviderId",
table: "Transaction");
migrationBuilder.DropColumn(
name: "ProviderId",
table: "Transaction");
migrationBuilder.DropColumn(
name: "GatewayCustomerId",
table: "Provider");
migrationBuilder.DropColumn(
name: "GatewaySubscriptionId",
table: "Provider");
migrationBuilder.DropColumn(
name: "GatewayType",
table: "Provider");
}
}

View File

@ -4,7 +4,6 @@ using Bit.Infrastructure.EntityFramework.Repositories;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
@ -16,7 +15,7 @@ namespace Bit.SqliteMigrations.Migrations
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "7.0.15");
modelBuilder.HasAnnotation("ProductVersion", "7.0.16");
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.AdminConsole.Models.Organization", b =>
{
@ -275,6 +274,15 @@ namespace Bit.SqliteMigrations.Migrations
b.Property<bool>("Enabled")
.HasColumnType("INTEGER");
b.Property<string>("GatewayCustomerId")
.HasColumnType("TEXT");
b.Property<string>("GatewaySubscriptionId")
.HasColumnType("TEXT");
b.Property<byte?>("GatewayType")
.HasColumnType("INTEGER");
b.Property<string>("Name")
.HasColumnType("TEXT");
@ -484,8 +492,7 @@ namespace Bit.SqliteMigrations.Migrations
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
.HasColumnType("INTEGER");
b.Property<string>("ClientId")
.IsRequired()
@ -664,6 +671,36 @@ namespace Bit.SqliteMigrations.Migrations
b.ToTable("WebAuthnCredential", (string)null);
});
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Billing.Models.ProviderPlan", b =>
{
b.Property<Guid>("Id")
.HasColumnType("TEXT");
b.Property<int?>("AllocatedSeats")
.HasColumnType("INTEGER");
b.Property<byte>("PlanType")
.HasColumnType("INTEGER");
b.Property<Guid>("ProviderId")
.HasColumnType("TEXT");
b.Property<int?>("PurchasedSeats")
.HasColumnType("INTEGER");
b.Property<int?>("SeatMinimum")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.HasIndex("ProviderId");
b.HasIndex("Id", "PlanType")
.IsUnique();
b.ToTable("ProviderPlan", (string)null);
});
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Models.Collection", b =>
{
b.Property<Guid>("Id")
@ -1271,6 +1308,9 @@ namespace Bit.SqliteMigrations.Migrations
b.Property<byte?>("PaymentMethodType")
.HasColumnType("INTEGER");
b.Property<Guid?>("ProviderId")
.HasColumnType("TEXT");
b.Property<bool?>("Refunded")
.HasColumnType("INTEGER");
@ -1287,6 +1327,8 @@ namespace Bit.SqliteMigrations.Migrations
b.HasIndex("OrganizationId");
b.HasIndex("ProviderId");
b.HasIndex("UserId")
.HasAnnotation("SqlServer:Clustered", false);
@ -2006,6 +2048,17 @@ namespace Bit.SqliteMigrations.Migrations
b.Navigation("User");
});
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Billing.Models.ProviderPlan", b =>
{
b.HasOne("Bit.Infrastructure.EntityFramework.AdminConsole.Models.Provider.Provider", "Provider")
.WithMany()
.HasForeignKey("ProviderId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Provider");
});
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Models.Collection", b =>
{
b.HasOne("Bit.Infrastructure.EntityFramework.AdminConsole.Models.Organization", "Organization")
@ -2201,12 +2254,18 @@ namespace Bit.SqliteMigrations.Migrations
.WithMany("Transactions")
.HasForeignKey("OrganizationId");
b.HasOne("Bit.Infrastructure.EntityFramework.AdminConsole.Models.Provider.Provider", "Provider")
.WithMany()
.HasForeignKey("ProviderId");
b.HasOne("Bit.Infrastructure.EntityFramework.Models.User", "User")
.WithMany("Transactions")
.HasForeignKey("UserId");
b.Navigation("Organization");
b.Navigation("Provider");
b.Navigation("User");
});