mirror of
https://github.com/bitwarden/server.git
synced 2025-07-05 01:52:49 -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,21 @@
|
||||
using Bit.Infrastructure.EntityFramework.Billing.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace Bit.Infrastructure.EntityFramework.Billing.Configurations;
|
||||
|
||||
public class ClientOrganizationMigrationRecordEntityTypeConfiguration : IEntityTypeConfiguration<ClientOrganizationMigrationRecord>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<ClientOrganizationMigrationRecord> builder)
|
||||
{
|
||||
builder
|
||||
.Property(c => c.Id)
|
||||
.ValueGeneratedNever();
|
||||
|
||||
builder
|
||||
.HasIndex(migrationRecord => new { migrationRecord.ProviderId, migrationRecord.OrganizationId })
|
||||
.IsUnique();
|
||||
|
||||
builder.ToTable(nameof(ClientOrganizationMigrationRecord));
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
using AutoMapper;
|
||||
|
||||
namespace Bit.Infrastructure.EntityFramework.Billing.Models;
|
||||
|
||||
public class ClientOrganizationMigrationRecord : Core.Billing.Entities.ClientOrganizationMigrationRecord
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public class ClientOrganizationMigrationRecordProfile : Profile
|
||||
{
|
||||
public ClientOrganizationMigrationRecordProfile()
|
||||
{
|
||||
CreateMap<Core.Billing.Entities.ClientOrganizationMigrationRecord, ClientOrganizationMigrationRecord>().ReverseMap();
|
||||
}
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
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 EFClientOrganizationMigrationRecord = Bit.Infrastructure.EntityFramework.Billing.Models.ClientOrganizationMigrationRecord;
|
||||
|
||||
namespace Bit.Infrastructure.EntityFramework.Billing.Repositories;
|
||||
|
||||
public class ClientOrganizationMigrationRecordRepository(
|
||||
IMapper mapper,
|
||||
IServiceScopeFactory serviceScopeFactory)
|
||||
: Repository<ClientOrganizationMigrationRecord, EFClientOrganizationMigrationRecord, Guid>(
|
||||
serviceScopeFactory,
|
||||
mapper,
|
||||
context => context.ClientOrganizationMigrationRecords), IClientOrganizationMigrationRecordRepository
|
||||
{
|
||||
public async Task<ClientOrganizationMigrationRecord> GetByOrganizationId(Guid organizationId)
|
||||
{
|
||||
using var serviceScope = ServiceScopeFactory.CreateScope();
|
||||
|
||||
var databaseContext = GetDatabaseContext(serviceScope);
|
||||
|
||||
var query =
|
||||
from clientOrganizationMigrationRecord in databaseContext.ClientOrganizationMigrationRecords
|
||||
where clientOrganizationMigrationRecord.OrganizationId == organizationId
|
||||
select clientOrganizationMigrationRecord;
|
||||
|
||||
return await query.FirstOrDefaultAsync();
|
||||
}
|
||||
|
||||
public async Task<ICollection<ClientOrganizationMigrationRecord>> GetByProviderId(Guid providerId)
|
||||
{
|
||||
using var serviceScope = ServiceScopeFactory.CreateScope();
|
||||
|
||||
var databaseContext = GetDatabaseContext(serviceScope);
|
||||
|
||||
var query =
|
||||
from clientOrganizationMigrationRecord in databaseContext.ClientOrganizationMigrationRecords
|
||||
where clientOrganizationMigrationRecord.ProviderId == providerId
|
||||
select clientOrganizationMigrationRecord;
|
||||
|
||||
return await query.ToArrayAsync();
|
||||
}
|
||||
}
|
@ -93,6 +93,8 @@ public static class EntityFrameworkServiceCollectionExtensions
|
||||
services.AddSingleton<IProviderInvoiceItemRepository, ProviderInvoiceItemRepository>();
|
||||
services.AddSingleton<INotificationRepository, NotificationRepository>();
|
||||
services.AddSingleton<INotificationStatusRepository, NotificationStatusRepository>();
|
||||
services
|
||||
.AddSingleton<IClientOrganizationMigrationRecordRepository, ClientOrganizationMigrationRecordRepository>();
|
||||
|
||||
if (selfHosted)
|
||||
{
|
||||
|
@ -74,6 +74,7 @@ public class DatabaseContext : DbContext
|
||||
public DbSet<ProviderInvoiceItem> ProviderInvoiceItems { get; set; }
|
||||
public DbSet<Notification> Notifications { get; set; }
|
||||
public DbSet<NotificationStatus> NotificationStatuses { get; set; }
|
||||
public DbSet<ClientOrganizationMigrationRecord> ClientOrganizationMigrationRecords { get; set; }
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder builder)
|
||||
{
|
||||
|
Reference in New Issue
Block a user