mirror of
https://github.com/bitwarden/server.git
synced 2025-02-01 23:31:41 +01: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:
parent
43ee5a24ec
commit
9f7e05869e
@ -1,6 +1,7 @@
|
||||
using System.Net;
|
||||
using Bit.Core.AdminConsole.Enums.Provider;
|
||||
using Bit.Core.Entities;
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Core.Utilities;
|
||||
|
||||
namespace Bit.Core.AdminConsole.Entities.Provider;
|
||||
@ -29,6 +30,9 @@ public class Provider : ITableObject<Guid>
|
||||
public bool Enabled { get; set; } = true;
|
||||
public DateTime CreationDate { get; internal set; } = DateTime.UtcNow;
|
||||
public DateTime RevisionDate { get; internal set; } = DateTime.UtcNow;
|
||||
public GatewayType? Gateway { get; set; }
|
||||
public string GatewayCustomerId { get; set; }
|
||||
public string GatewaySubscriptionId { get; set; }
|
||||
|
||||
public void SetNewId()
|
||||
{
|
||||
|
23
src/Core/Billing/Entities/ProviderPlan.cs
Normal file
23
src/Core/Billing/Entities/ProviderPlan.cs
Normal file
@ -0,0 +1,23 @@
|
||||
using Bit.Core.Entities;
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Core.Utilities;
|
||||
|
||||
namespace Bit.Core.Billing.Entities;
|
||||
|
||||
public class ProviderPlan : ITableObject<Guid>
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public Guid ProviderId { get; set; }
|
||||
public PlanType PlanType { get; set; }
|
||||
public int? SeatMinimum { get; set; }
|
||||
public int? PurchasedSeats { get; set; }
|
||||
public int? AllocatedSeats { get; set; }
|
||||
|
||||
public void SetNewId()
|
||||
{
|
||||
if (Id == default)
|
||||
{
|
||||
Id = CoreHelpers.GenerateComb();
|
||||
}
|
||||
}
|
||||
}
|
9
src/Core/Billing/Repositories/IProviderPlanRepository.cs
Normal file
9
src/Core/Billing/Repositories/IProviderPlanRepository.cs
Normal file
@ -0,0 +1,9 @@
|
||||
using Bit.Core.Billing.Entities;
|
||||
using Bit.Core.Repositories;
|
||||
|
||||
namespace Bit.Core.Billing.Repositories;
|
||||
|
||||
public interface IProviderPlanRepository : IRepository<ProviderPlan, Guid>
|
||||
{
|
||||
Task<ProviderPlan> GetByProviderId(Guid providerId);
|
||||
}
|
@ -20,6 +20,7 @@ public class Transaction : ITableObject<Guid>
|
||||
[MaxLength(50)]
|
||||
public string GatewayId { get; set; }
|
||||
public DateTime CreationDate { get; set; } = DateTime.UtcNow;
|
||||
public Guid? ProviderId { get; set; }
|
||||
|
||||
public void SetNewId()
|
||||
{
|
||||
|
@ -7,5 +7,6 @@ public interface ITransactionRepository : IRepository<Transaction, Guid>
|
||||
{
|
||||
Task<ICollection<Transaction>> GetManyByUserIdAsync(Guid userId);
|
||||
Task<ICollection<Transaction>> GetManyByOrganizationIdAsync(Guid organizationId);
|
||||
Task<ICollection<Transaction>> GetManyByProviderIdAsync(Guid providerId);
|
||||
Task<Transaction> GetByGatewayIdAsync(GatewayType gatewayType, string gatewayId);
|
||||
}
|
||||
|
@ -0,0 +1,28 @@
|
||||
using System.Data;
|
||||
using Bit.Core.Billing.Entities;
|
||||
using Bit.Core.Billing.Repositories;
|
||||
using Bit.Core.Settings;
|
||||
using Bit.Infrastructure.Dapper.Repositories;
|
||||
using Dapper;
|
||||
using Microsoft.Data.SqlClient;
|
||||
|
||||
namespace Bit.Infrastructure.Dapper.Billing.Repositories;
|
||||
|
||||
public class ProviderPlanRepository(
|
||||
GlobalSettings globalSettings)
|
||||
: Repository<ProviderPlan, Guid>(
|
||||
globalSettings.SqlServer.ConnectionString,
|
||||
globalSettings.SqlServer.ReadOnlyConnectionString), IProviderPlanRepository
|
||||
{
|
||||
public async Task<ProviderPlan> GetByProviderId(Guid providerId)
|
||||
{
|
||||
var sqlConnection = new SqlConnection(ConnectionString);
|
||||
|
||||
var results = await sqlConnection.QueryAsync<ProviderPlan>(
|
||||
"[dbo].[ProviderPlan_ReadByProviderId]",
|
||||
new { ProviderId = providerId },
|
||||
commandType: CommandType.StoredProcedure);
|
||||
|
||||
return results.FirstOrDefault();
|
||||
}
|
||||
}
|
@ -1,11 +1,13 @@
|
||||
using Bit.Core.AdminConsole.Repositories;
|
||||
using Bit.Core.Auth.Repositories;
|
||||
using Bit.Core.Billing.Repositories;
|
||||
using Bit.Core.Repositories;
|
||||
using Bit.Core.SecretsManager.Repositories;
|
||||
using Bit.Core.Tools.Repositories;
|
||||
using Bit.Core.Vault.Repositories;
|
||||
using Bit.Infrastructure.Dapper.AdminConsole.Repositories;
|
||||
using Bit.Infrastructure.Dapper.Auth.Repositories;
|
||||
using Bit.Infrastructure.Dapper.Billing.Repositories;
|
||||
using Bit.Infrastructure.Dapper.Repositories;
|
||||
using Bit.Infrastructure.Dapper.SecretsManager.Repositories;
|
||||
using Bit.Infrastructure.Dapper.Tools.Repositories;
|
||||
@ -48,6 +50,7 @@ public static class DapperServiceCollectionExtensions
|
||||
services.AddSingleton<IUserRepository, UserRepository>();
|
||||
services.AddSingleton<IOrganizationDomainRepository, OrganizationDomainRepository>();
|
||||
services.AddSingleton<IWebAuthnCredentialRepository, WebAuthnCredentialRepository>();
|
||||
services.AddSingleton<IProviderPlanRepository, ProviderPlanRepository>();
|
||||
|
||||
if (selfHosted)
|
||||
{
|
||||
|
@ -44,6 +44,16 @@ public class TransactionRepository : Repository<Transaction, Guid>, ITransaction
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<ICollection<Transaction>> GetManyByProviderIdAsync(Guid providerId)
|
||||
{
|
||||
await using var sqlConnection = new SqlConnection(ConnectionString);
|
||||
var results = await sqlConnection.QueryAsync<Transaction>(
|
||||
$"[{Schema}].[Transaction_ReadByProviderId]",
|
||||
new { ProviderId = providerId },
|
||||
commandType: CommandType.StoredProcedure);
|
||||
return results.ToList();
|
||||
}
|
||||
|
||||
public async Task<Transaction> GetByGatewayIdAsync(GatewayType gatewayType, string gatewayId)
|
||||
{
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
|
@ -0,0 +1,21 @@
|
||||
using Bit.Infrastructure.EntityFramework.Billing.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace Bit.Infrastructure.EntityFramework.Billing.Configurations;
|
||||
|
||||
public class ProviderPlanEntityTypeConfiguration : IEntityTypeConfiguration<ProviderPlan>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<ProviderPlan> builder)
|
||||
{
|
||||
builder
|
||||
.Property(t => t.Id)
|
||||
.ValueGeneratedNever();
|
||||
|
||||
builder
|
||||
.HasIndex(providerPlan => new { providerPlan.Id, providerPlan.PlanType })
|
||||
.IsUnique();
|
||||
|
||||
builder.ToTable(nameof(ProviderPlan));
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
using AutoMapper;
|
||||
using Bit.Infrastructure.EntityFramework.AdminConsole.Models.Provider;
|
||||
|
||||
namespace Bit.Infrastructure.EntityFramework.Billing.Models;
|
||||
|
||||
public class ProviderPlan : Core.Billing.Entities.ProviderPlan
|
||||
{
|
||||
public virtual Provider Provider { get; set; }
|
||||
}
|
||||
|
||||
public class ProviderPlanMapperProfile : Profile
|
||||
{
|
||||
public ProviderPlanMapperProfile()
|
||||
{
|
||||
CreateMap<Core.Billing.Entities.ProviderPlan, ProviderPlan>().ReverseMap();
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
using AutoMapper;
|
||||
using Bit.Core.Billing.Entities;
|
||||
using Bit.Core.Billing.Repositories;
|
||||
using Bit.Infrastructure.EntityFramework.Repositories;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using EFProviderPlan = Bit.Infrastructure.EntityFramework.Billing.Models.ProviderPlan;
|
||||
|
||||
namespace Bit.Infrastructure.EntityFramework.Billing.Repositories;
|
||||
|
||||
public class ProviderPlanRepository(
|
||||
IMapper mapper,
|
||||
IServiceScopeFactory serviceScopeFactory)
|
||||
: Repository<ProviderPlan, EFProviderPlan, Guid>(
|
||||
serviceScopeFactory,
|
||||
mapper,
|
||||
context => context.ProviderPlans), IProviderPlanRepository
|
||||
{
|
||||
public async Task<ProviderPlan> GetByProviderId(Guid providerId)
|
||||
{
|
||||
using var serviceScope = ServiceScopeFactory.CreateScope();
|
||||
var databaseContext = GetDatabaseContext(serviceScope);
|
||||
var query =
|
||||
from providerPlan in databaseContext.ProviderPlans
|
||||
where providerPlan.ProviderId == providerId
|
||||
select providerPlan;
|
||||
return await query.FirstOrDefaultAsync();
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
using Bit.Core.AdminConsole.Repositories;
|
||||
using Bit.Core.Auth.Repositories;
|
||||
using Bit.Core.Billing.Repositories;
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Core.Repositories;
|
||||
using Bit.Core.SecretsManager.Repositories;
|
||||
@ -7,6 +8,7 @@ using Bit.Core.Tools.Repositories;
|
||||
using Bit.Core.Vault.Repositories;
|
||||
using Bit.Infrastructure.EntityFramework.AdminConsole.Repositories;
|
||||
using Bit.Infrastructure.EntityFramework.Auth.Repositories;
|
||||
using Bit.Infrastructure.EntityFramework.Billing.Repositories;
|
||||
using Bit.Infrastructure.EntityFramework.Repositories;
|
||||
using Bit.Infrastructure.EntityFramework.SecretsManager.Repositories;
|
||||
using Bit.Infrastructure.EntityFramework.Tools.Repositories;
|
||||
@ -85,6 +87,7 @@ public static class EntityFrameworkServiceCollectionExtensions
|
||||
services.AddSingleton<IUserRepository, UserRepository>();
|
||||
services.AddSingleton<IOrganizationDomainRepository, OrganizationDomainRepository>();
|
||||
services.AddSingleton<IWebAuthnCredentialRepository, WebAuthnCredentialRepository>();
|
||||
services.AddSingleton<IProviderPlanRepository, ProviderPlanRepository>();
|
||||
|
||||
if (selfHosted)
|
||||
{
|
||||
|
@ -1,5 +1,6 @@
|
||||
using AutoMapper;
|
||||
using Bit.Infrastructure.EntityFramework.AdminConsole.Models;
|
||||
using Bit.Infrastructure.EntityFramework.AdminConsole.Models.Provider;
|
||||
|
||||
namespace Bit.Infrastructure.EntityFramework.Models;
|
||||
|
||||
@ -7,6 +8,7 @@ public class Transaction : Core.Entities.Transaction
|
||||
{
|
||||
public virtual Organization Organization { get; set; }
|
||||
public virtual User User { get; set; }
|
||||
public virtual Provider Provider { get; set; }
|
||||
}
|
||||
|
||||
public class TransactionMapperProfile : Profile
|
||||
|
@ -2,6 +2,7 @@
|
||||
using Bit.Infrastructure.EntityFramework.AdminConsole.Models;
|
||||
using Bit.Infrastructure.EntityFramework.AdminConsole.Models.Provider;
|
||||
using Bit.Infrastructure.EntityFramework.Auth.Models;
|
||||
using Bit.Infrastructure.EntityFramework.Billing.Models;
|
||||
using Bit.Infrastructure.EntityFramework.Converters;
|
||||
using Bit.Infrastructure.EntityFramework.Models;
|
||||
using Bit.Infrastructure.EntityFramework.SecretsManager.Models;
|
||||
@ -65,6 +66,7 @@ public class DatabaseContext : DbContext
|
||||
public DbSet<AuthRequest> AuthRequests { get; set; }
|
||||
public DbSet<OrganizationDomain> OrganizationDomains { get; set; }
|
||||
public DbSet<WebAuthnCredential> WebAuthnCredentials { get; set; }
|
||||
public DbSet<ProviderPlan> ProviderPlans { get; set; }
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder builder)
|
||||
{
|
||||
|
@ -47,4 +47,14 @@ public class TransactionRepository : Repository<Core.Entities.Transaction, Trans
|
||||
return Mapper.Map<List<Core.Entities.Transaction>>(results);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<ICollection<Core.Entities.Transaction>> GetManyByProviderIdAsync(Guid providerId)
|
||||
{
|
||||
using var serviceScope = ServiceScopeFactory.CreateScope();
|
||||
var databaseContext = GetDatabaseContext(serviceScope);
|
||||
var results = await databaseContext.Transactions
|
||||
.Where(transaction => transaction.ProviderId == providerId)
|
||||
.ToListAsync();
|
||||
return Mapper.Map<List<Core.Entities.Transaction>>(results);
|
||||
}
|
||||
}
|
||||
|
30
src/Sql/Billing/Stored Procedures/ProviderPlan_Create.sql
Normal file
30
src/Sql/Billing/Stored Procedures/ProviderPlan_Create.sql
Normal file
@ -0,0 +1,30 @@
|
||||
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
|
@ -0,0 +1,12 @@
|
||||
CREATE PROCEDURE [dbo].[ProviderPlan_DeleteById]
|
||||
@Id UNIQUEIDENTIFIER
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
DELETE
|
||||
FROM
|
||||
[dbo].[ProviderPlan]
|
||||
WHERE
|
||||
[Id] = @Id
|
||||
END
|
13
src/Sql/Billing/Stored Procedures/ProviderPlan_ReadById.sql
Normal file
13
src/Sql/Billing/Stored Procedures/ProviderPlan_ReadById.sql
Normal file
@ -0,0 +1,13 @@
|
||||
CREATE PROCEDURE [dbo].[ProviderPlan_ReadById]
|
||||
@Id UNIQUEIDENTIFIER
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
[dbo].[ProviderPlanView]
|
||||
WHERE
|
||||
[Id] = @Id
|
||||
END
|
@ -0,0 +1,13 @@
|
||||
CREATE PROCEDURE [dbo].[ProviderPlan_ReadByProviderId]
|
||||
@ProviderId UNIQUEIDENTIFIER
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
[dbo].[ProviderPlanView]
|
||||
WHERE
|
||||
[ProviderId] = @ProviderId
|
||||
END
|
22
src/Sql/Billing/Stored Procedures/ProviderPlan_Update.sql
Normal file
22
src/Sql/Billing/Stored Procedures/ProviderPlan_Update.sql
Normal file
@ -0,0 +1,22 @@
|
||||
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
|
11
src/Sql/Billing/Tables/ProviderPlan.sql
Normal file
11
src/Sql/Billing/Tables/ProviderPlan.sql
Normal file
@ -0,0 +1,11 @@
|
||||
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])
|
||||
);
|
6
src/Sql/Billing/Views/ProviderPlanView.sql
Normal file
6
src/Sql/Billing/Views/ProviderPlanView.sql
Normal file
@ -0,0 +1,6 @@
|
||||
CREATE VIEW [dbo].[ProviderPlanView]
|
||||
AS
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
[dbo].[ProviderPlan]
|
@ -14,7 +14,10 @@
|
||||
@UseEvents BIT,
|
||||
@Enabled BIT,
|
||||
@CreationDate DATETIME2(7),
|
||||
@RevisionDate DATETIME2(7)
|
||||
@RevisionDate DATETIME2(7),
|
||||
@Gateway TINYINT = 0,
|
||||
@GatewayCustomerId VARCHAR(50) = NULL,
|
||||
@GatewaySubscriptionId VARCHAR(50) = NULL
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
@ -36,7 +39,10 @@ BEGIN
|
||||
[UseEvents],
|
||||
[Enabled],
|
||||
[CreationDate],
|
||||
[RevisionDate]
|
||||
[RevisionDate],
|
||||
[Gateway],
|
||||
[GatewayCustomerId],
|
||||
[GatewaySubscriptionId]
|
||||
)
|
||||
VALUES
|
||||
(
|
||||
@ -55,6 +61,9 @@ BEGIN
|
||||
@UseEvents,
|
||||
@Enabled,
|
||||
@CreationDate,
|
||||
@RevisionDate
|
||||
@RevisionDate,
|
||||
@Gateway,
|
||||
@GatewayCustomerId,
|
||||
@GatewaySubscriptionId
|
||||
)
|
||||
END
|
||||
|
@ -14,7 +14,10 @@
|
||||
@UseEvents BIT,
|
||||
@Enabled BIT,
|
||||
@CreationDate DATETIME2(7),
|
||||
@RevisionDate DATETIME2(7)
|
||||
@RevisionDate DATETIME2(7),
|
||||
@Gateway TINYINT = 0,
|
||||
@GatewayCustomerId VARCHAR(50) = NULL,
|
||||
@GatewaySubscriptionId VARCHAR(50) = NULL
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
@ -36,7 +39,10 @@ BEGIN
|
||||
[UseEvents] = @UseEvents,
|
||||
[Enabled] = @Enabled,
|
||||
[CreationDate] = @CreationDate,
|
||||
[RevisionDate] = @RevisionDate
|
||||
[RevisionDate] = @RevisionDate,
|
||||
[Gateway] = @Gateway,
|
||||
[GatewayCustomerId] = @GatewayCustomerId,
|
||||
[GatewaySubscriptionId] = @GatewaySubscriptionId
|
||||
WHERE
|
||||
[Id] = @Id
|
||||
END
|
||||
|
@ -10,7 +10,8 @@
|
||||
@PaymentMethodType TINYINT,
|
||||
@Gateway TINYINT,
|
||||
@GatewayId VARCHAR(50),
|
||||
@CreationDate DATETIME2(7)
|
||||
@CreationDate DATETIME2(7),
|
||||
@ProviderId UNIQUEIDENTIFIER = NULL
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
@ -28,7 +29,8 @@ BEGIN
|
||||
[PaymentMethodType],
|
||||
[Gateway],
|
||||
[GatewayId],
|
||||
[CreationDate]
|
||||
[CreationDate],
|
||||
[ProviderId]
|
||||
)
|
||||
VALUES
|
||||
(
|
||||
@ -43,6 +45,7 @@ BEGIN
|
||||
@PaymentMethodType,
|
||||
@Gateway,
|
||||
@GatewayId,
|
||||
@CreationDate
|
||||
@CreationDate,
|
||||
@ProviderId
|
||||
)
|
||||
END
|
||||
|
@ -9,4 +9,4 @@ BEGIN
|
||||
[dbo].[Transaction]
|
||||
WHERE
|
||||
[Id] = @Id
|
||||
END
|
||||
END
|
||||
|
@ -12,4 +12,4 @@ BEGIN
|
||||
WHERE
|
||||
[Gateway] = @Gateway
|
||||
AND [GatewayId] = @GatewayId
|
||||
END
|
||||
END
|
||||
|
@ -10,4 +10,4 @@ BEGIN
|
||||
[dbo].[TransactionView]
|
||||
WHERE
|
||||
[Id] = @Id
|
||||
END
|
||||
END
|
||||
|
@ -11,4 +11,4 @@ BEGIN
|
||||
WHERE
|
||||
[UserId] IS NULL
|
||||
AND [OrganizationId] = @OrganizationId
|
||||
END
|
||||
END
|
||||
|
@ -0,0 +1,13 @@
|
||||
CREATE PROCEDURE [dbo].[Transaction_ReadByProviderId]
|
||||
@ProviderId UNIQUEIDENTIFIER
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
[dbo].[TransactionView]
|
||||
WHERE
|
||||
[ProviderId] = @ProviderId
|
||||
END
|
@ -10,4 +10,4 @@ BEGIN
|
||||
[dbo].[TransactionView]
|
||||
WHERE
|
||||
[UserId] = @UserId
|
||||
END
|
||||
END
|
||||
|
@ -10,7 +10,8 @@
|
||||
@PaymentMethodType TINYINT,
|
||||
@Gateway TINYINT,
|
||||
@GatewayId VARCHAR(50),
|
||||
@CreationDate DATETIME2(7)
|
||||
@CreationDate DATETIME2(7),
|
||||
@ProviderId UNIQUEIDENTIFIER = NULL
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
@ -28,7 +29,8 @@ BEGIN
|
||||
[PaymentMethodType] = @PaymentMethodType,
|
||||
[Gateway] = @Gateway,
|
||||
[GatewayId] = @GatewayId,
|
||||
[CreationDate] = @CreationDate
|
||||
[CreationDate] = @CreationDate,
|
||||
[ProviderId] = @ProviderId
|
||||
WHERE
|
||||
[Id] = @Id
|
||||
END
|
||||
END
|
||||
|
@ -1,19 +1,22 @@
|
||||
CREATE TABLE [dbo].[Provider] (
|
||||
[Id] UNIQUEIDENTIFIER NOT NULL,
|
||||
[Name] NVARCHAR (50) NULL,
|
||||
[BusinessName] NVARCHAR (50) NULL,
|
||||
[BusinessAddress1] NVARCHAR (50) NULL,
|
||||
[BusinessAddress2] NVARCHAR (50) NULL,
|
||||
[BusinessAddress3] NVARCHAR (50) NULL,
|
||||
[BusinessCountry] VARCHAR (2) NULL,
|
||||
[BusinessTaxNumber] NVARCHAR (30) NULL,
|
||||
[BillingEmail] NVARCHAR (256) NULL,
|
||||
[BillingPhone] NVARCHAR (50) NULL,
|
||||
[Status] TINYINT NOT NULL,
|
||||
[UseEvents] BIT NOT NULL,
|
||||
[Type] TINYINT NOT NULL CONSTRAINT DF_Provider_Type DEFAULT (0),
|
||||
[Enabled] BIT NOT NULL,
|
||||
[CreationDate] DATETIME2 (7) NOT NULL,
|
||||
[RevisionDate] DATETIME2 (7) NOT NULL,
|
||||
[Id] UNIQUEIDENTIFIER NOT NULL,
|
||||
[Name] NVARCHAR (50) NULL,
|
||||
[BusinessName] NVARCHAR (50) NULL,
|
||||
[BusinessAddress1] NVARCHAR (50) NULL,
|
||||
[BusinessAddress2] NVARCHAR (50) NULL,
|
||||
[BusinessAddress3] NVARCHAR (50) NULL,
|
||||
[BusinessCountry] VARCHAR (2) NULL,
|
||||
[BusinessTaxNumber] NVARCHAR (30) NULL,
|
||||
[BillingEmail] NVARCHAR (256) NULL,
|
||||
[BillingPhone] NVARCHAR (50) NULL,
|
||||
[Status] TINYINT NOT NULL,
|
||||
[UseEvents] BIT NOT NULL,
|
||||
[Type] TINYINT NOT NULL CONSTRAINT DF_Provider_Type DEFAULT (0),
|
||||
[Enabled] BIT NOT NULL,
|
||||
[CreationDate] DATETIME2 (7) NOT NULL,
|
||||
[RevisionDate] DATETIME2 (7) NOT NULL,
|
||||
[Gateway] TINYINT NULL,
|
||||
[GatewayCustomerId] VARCHAR (50) NULL,
|
||||
[GatewaySubscriptionId] VARCHAR (50) NULL,
|
||||
CONSTRAINT [PK_Provider] PRIMARY KEY CLUSTERED ([Id] ASC)
|
||||
);
|
||||
|
@ -11,19 +11,18 @@
|
||||
[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_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);
|
||||
|
||||
|
513
util/Migrator/DbScripts/2024-03-07_00_SetupProviderBilling.sql
Normal file
513
util/Migrator/DbScripts/2024-03-07_00_SetupProviderBilling.sql
Normal 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
|
2580
util/MySqlMigrations/Migrations/20240308141726_SetupProviderBilling.Designer.cs
generated
Normal file
2580
util/MySqlMigrations/Migrations/20240308141726_SetupProviderBilling.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -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");
|
||||
}
|
||||
}
|
@ -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");
|
||||
});
|
||||
|
||||
|
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");
|
||||
});
|
||||
|
||||
|
2578
util/SqliteMigrations/Migrations/20240308141731_SetupProviderBilling.Designer.cs
generated
Normal file
2578
util/SqliteMigrations/Migrations/20240308141731_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.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");
|
||||
}
|
||||
}
|
@ -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");
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user