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:
2596
util/PostgresMigrations/Migrations/20240308141737_SetupProviderBilling.Designer.cs
generated
Normal file
2596
util/PostgresMigrations/Migrations/20240308141737_SetupProviderBilling.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -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");
|
||||
}
|
||||
}
|
@ -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");
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user