mirror of
https://github.com/bitwarden/server.git
synced 2025-06-30 15:42:48 -05:00
[AC-2551] Consolidated Billing Migration (#4616)
* Move existing Billing SQL files into dbo folder I noticed that every other team had a nested dbo folder under their team folder while Billing did not. This change replicates that. * Add SQL files for ClientOrganizationMigrationRecord table * Add SQL Server migration for ClientOrganizationMigrationRecord table * Add ClientOrganizationMigrationRecord entity and repository interface * Add ClientOrganizationMigrationRecord Dapper repository * Add ClientOrganizationMigrationRecord EF repository * Add EF migrations for ClientOrganizationMigrationRecord table * Implement migration process * Wire up new Admin tool to migrate providers * Run dotnet format * Updated coupon and credit application per product request * AC-3057-3058: Fix expiration date and enabled from webhook processing * Run dotnet format * AC-3059: Fix assigned seats during migration * Updated AllocatedSeats in the case plan already exists * Update migration scripts to reflect current date
This commit is contained in:
@ -0,0 +1,175 @@
|
||||
-- Table
|
||||
IF OBJECT_ID('[dbo].[ClientOrganizationMigrationRecord]') IS NULL
|
||||
BEGIN
|
||||
CREATE TABLE [dbo].[ClientOrganizationMigrationRecord] (
|
||||
[Id] UNIQUEIDENTIFIER NOT NULL,
|
||||
[OrganizationId] UNIQUEIDENTIFIER NOT NULL,
|
||||
[ProviderId] UNIQUEIDENTIFIER NOT NULL,
|
||||
[PlanType] TINYINT NOT NULL,
|
||||
[Seats] SMALLINT NOT NULL,
|
||||
[MaxStorageGb] SMALLINT NULL,
|
||||
[GatewayCustomerId] VARCHAR(50) NOT NULL,
|
||||
[GatewaySubscriptionId] VARCHAR(50) NOT NULL,
|
||||
[ExpirationDate] DATETIME2(7) NULL,
|
||||
[MaxAutoscaleSeats] INT NULL,
|
||||
[Status] TINYINT NOT NULL,
|
||||
CONSTRAINT [PK_ClientOrganizationMigrationRecord] PRIMARY KEY CLUSTERED ([Id] ASC),
|
||||
CONSTRAINT [PK_OrganizationIdProviderId] UNIQUE ([ProviderId], [OrganizationId])
|
||||
);
|
||||
END
|
||||
GO
|
||||
|
||||
-- View
|
||||
CREATE OR AlTER VIEW [dbo].[ClientOrganizationMigrationRecordView]
|
||||
AS
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
[dbo].[ClientOrganizationMigrationRecord]
|
||||
GO
|
||||
|
||||
-- Stored Procedures: Create
|
||||
CREATE OR ALTER PROCEDURE [dbo].[ClientOrganizationMigrationRecord_Create]
|
||||
@Id UNIQUEIDENTIFIER OUTPUT,
|
||||
@OrganizationId UNIQUEIDENTIFIER,
|
||||
@ProviderId UNIQUEIDENTIFIER,
|
||||
@PlanType TINYINT,
|
||||
@Seats SMALLINT,
|
||||
@MaxStorageGb SMALLINT,
|
||||
@GatewayCustomerId VARCHAR(50),
|
||||
@GatewaySubscriptionId VARCHAR(50),
|
||||
@ExpirationDate DATETIME2(7),
|
||||
@MaxAutoscaleSeats INT,
|
||||
@Status TINYINT
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
INSERT INTO [dbo].[ClientOrganizationMigrationRecord]
|
||||
(
|
||||
[Id],
|
||||
[OrganizationId],
|
||||
[ProviderId],
|
||||
[PlanType],
|
||||
[Seats],
|
||||
[MaxStorageGb],
|
||||
[GatewayCustomerId],
|
||||
[GatewaySubscriptionId],
|
||||
[ExpirationDate],
|
||||
[MaxAutoscaleSeats],
|
||||
[Status]
|
||||
)
|
||||
VALUES
|
||||
(
|
||||
@Id,
|
||||
@OrganizationId,
|
||||
@ProviderId,
|
||||
@PlanType,
|
||||
@Seats,
|
||||
@MaxStorageGb,
|
||||
@GatewayCustomerId,
|
||||
@GatewaySubscriptionId,
|
||||
@ExpirationDate,
|
||||
@MaxAutoscaleSeats,
|
||||
@Status
|
||||
)
|
||||
END
|
||||
GO
|
||||
|
||||
-- Stored Procedures: DeleteById
|
||||
CREATE OR ALTER PROCEDURE [dbo].[ClientOrganizationMigrationRecord_DeleteById]
|
||||
@Id UNIQUEIDENTIFIER
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
DELETE
|
||||
FROM
|
||||
[dbo].[ClientOrganizationMigrationRecord]
|
||||
WHERE
|
||||
[Id] = @Id
|
||||
END
|
||||
GO
|
||||
|
||||
-- Stored Procedures: ReadById
|
||||
CREATE OR ALTER PROCEDURE [dbo].[ClientOrganizationMigrationRecord_ReadById]
|
||||
@Id UNIQUEIDENTIFIER
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
[dbo].[ClientOrganizationMigrationRecordView]
|
||||
WHERE
|
||||
[Id] = @Id
|
||||
END
|
||||
GO
|
||||
|
||||
-- Stored Procedures: ReadByOrganizationId
|
||||
CREATE OR ALTER PROCEDURE [dbo].[ClientOrganizationMigrationRecord_ReadByOrganizationId]
|
||||
@OrganizationId UNIQUEIDENTIFIER
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
[dbo].[ClientOrganizationMigrationRecordView]
|
||||
WHERE
|
||||
[OrganizationId] = @OrganizationId
|
||||
END
|
||||
GO
|
||||
|
||||
-- Stored Procedures: ReadByProviderId
|
||||
CREATE OR ALTER PROCEDURE [dbo].[ClientOrganizationMigrationRecord_ReadByProviderId]
|
||||
@ProviderId UNIQUEIDENTIFIER
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
[dbo].[ClientOrganizationMigrationRecordView]
|
||||
WHERE
|
||||
[ProviderId] = @ProviderId
|
||||
END
|
||||
GO
|
||||
|
||||
-- Stored Procedures: Update
|
||||
CREATE OR ALTER PROCEDURE [dbo].[ClientOrganizationMigrationRecord_Update]
|
||||
@Id UNIQUEIDENTIFIER OUTPUT,
|
||||
@OrganizationId UNIQUEIDENTIFIER,
|
||||
@ProviderId UNIQUEIDENTIFIER,
|
||||
@PlanType TINYINT,
|
||||
@Seats SMALLINT,
|
||||
@MaxStorageGb SMALLINT,
|
||||
@GatewayCustomerId VARCHAR(50),
|
||||
@GatewaySubscriptionId VARCHAR(50),
|
||||
@ExpirationDate DATETIME2(7),
|
||||
@MaxAutoscaleSeats INT,
|
||||
@Status TINYINT
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
UPDATE
|
||||
[dbo].[ClientOrganizationMigrationRecord]
|
||||
SET
|
||||
[OrganizationId] = @OrganizationId,
|
||||
[ProviderId] = @ProviderId,
|
||||
[PlanType] = @PlanType,
|
||||
[Seats] = @Seats,
|
||||
[MaxStorageGb] = @MaxStorageGb,
|
||||
[GatewayCustomerId] = @GatewayCustomerId,
|
||||
[GatewaySubscriptionId] = @GatewaySubscriptionId,
|
||||
[ExpirationDate] = @ExpirationDate,
|
||||
[MaxAutoscaleSeats] = @MaxAutoscaleSeats,
|
||||
[Status] = @Status
|
||||
WHERE
|
||||
[Id] = @Id
|
||||
END
|
||||
GO
|
2845
util/MySqlMigrations/Migrations/20241004140901_AddClientOrganizationMigrationRecordTable.Designer.cs
generated
Normal file
2845
util/MySqlMigrations/Migrations/20241004140901_AddClientOrganizationMigrationRecordTable.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,22 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Bit.MySqlMigrations.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddClientOrganizationMigrationRecordTable : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -687,6 +687,53 @@ namespace Bit.MySqlMigrations.Migrations
|
||||
b.ToTable("WebAuthnCredential", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Billing.Models.ClientOrganizationMigrationRecord", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.HasColumnType("char(36)");
|
||||
|
||||
b.Property<DateTime?>("ExpirationDate")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<string>("GatewayCustomerId")
|
||||
.IsRequired()
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("varchar(50)");
|
||||
|
||||
b.Property<string>("GatewaySubscriptionId")
|
||||
.IsRequired()
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("varchar(50)");
|
||||
|
||||
b.Property<int?>("MaxAutoscaleSeats")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<short?>("MaxStorageGb")
|
||||
.HasColumnType("smallint");
|
||||
|
||||
b.Property<Guid>("OrganizationId")
|
||||
.HasColumnType("char(36)");
|
||||
|
||||
b.Property<byte>("PlanType")
|
||||
.HasColumnType("tinyint unsigned");
|
||||
|
||||
b.Property<Guid>("ProviderId")
|
||||
.HasColumnType("char(36)");
|
||||
|
||||
b.Property<int>("Seats")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<byte>("Status")
|
||||
.HasColumnType("tinyint unsigned");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ProviderId", "OrganizationId")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("ClientOrganizationMigrationRecord", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Billing.Models.ProviderInvoiceItem", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
|
2851
util/PostgresMigrations/Migrations/20241004140910_AddClientOrganizationMigrationRecordTable.Designer.cs
generated
Normal file
2851
util/PostgresMigrations/Migrations/20241004140910_AddClientOrganizationMigrationRecordTable.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,22 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Bit.PostgresMigrations.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddClientOrganizationMigrationRecordTable : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -692,6 +692,53 @@ namespace Bit.PostgresMigrations.Migrations
|
||||
b.ToTable("WebAuthnCredential", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Billing.Models.ClientOrganizationMigrationRecord", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<DateTime?>("ExpirationDate")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("GatewayCustomerId")
|
||||
.IsRequired()
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("character varying(50)");
|
||||
|
||||
b.Property<string>("GatewaySubscriptionId")
|
||||
.IsRequired()
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("character varying(50)");
|
||||
|
||||
b.Property<int?>("MaxAutoscaleSeats")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<short?>("MaxStorageGb")
|
||||
.HasColumnType("smallint");
|
||||
|
||||
b.Property<Guid>("OrganizationId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<byte>("PlanType")
|
||||
.HasColumnType("smallint");
|
||||
|
||||
b.Property<Guid>("ProviderId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<int>("Seats")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<byte>("Status")
|
||||
.HasColumnType("smallint");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ProviderId", "OrganizationId")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("ClientOrganizationMigrationRecord", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Billing.Models.ProviderInvoiceItem", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
|
2834
util/SqliteMigrations/Migrations/20241004140906_AddClientOrganizationMigrationRecordTable.Designer.cs
generated
Normal file
2834
util/SqliteMigrations/Migrations/20241004140906_AddClientOrganizationMigrationRecordTable.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,22 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Bit.SqliteMigrations.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddClientOrganizationMigrationRecordTable : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -676,6 +676,53 @@ namespace Bit.SqliteMigrations.Migrations
|
||||
b.ToTable("WebAuthnCredential", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Billing.Models.ClientOrganizationMigrationRecord", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime?>("ExpirationDate")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("GatewayCustomerId")
|
||||
.IsRequired()
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("GatewaySubscriptionId")
|
||||
.IsRequired()
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int?>("MaxAutoscaleSeats")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<short?>("MaxStorageGb")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<Guid>("OrganizationId")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<byte>("PlanType")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<Guid>("ProviderId")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int>("Seats")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<byte>("Status")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ProviderId", "OrganizationId")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("ClientOrganizationMigrationRecord", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Billing.Models.ProviderInvoiceItem", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
|
Reference in New Issue
Block a user