You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
72 lines
2.3 KiB
72 lines
2.3 KiB
using EShopOnAbp.OrderingService.EntityFrameworkCore;
|
|
using EShopOnAbp.Shared.Hosting.Microservices.DbMigrations.EfCore;
|
|
using Microsoft.Extensions.Logging;
|
|
using System;
|
|
using System.Threading.Tasks;
|
|
using Volo.Abp.Data;
|
|
using Volo.Abp.DistributedLocking;
|
|
using Volo.Abp.EventBus.Distributed;
|
|
using Volo.Abp.MultiTenancy;
|
|
using Volo.Abp.Uow;
|
|
|
|
namespace EShopOnAbp.OrderingService.DbMigrations
|
|
{
|
|
public class OrderingServiceDatabaseMigrationEventHandler
|
|
: DatabaseEfCoreMigrationEventHandler<OrderingServiceDbContext>,
|
|
IDistributedEventHandler<ApplyDatabaseMigrationsEto>
|
|
{
|
|
private readonly IDataSeeder _dataSeeder;
|
|
|
|
public OrderingServiceDatabaseMigrationEventHandler(
|
|
ICurrentTenant currentTenant,
|
|
IUnitOfWorkManager unitOfWorkManager,
|
|
ITenantStore tenantStore,
|
|
IDistributedEventBus distributedEventBus,
|
|
IDataSeeder dataSeeder,
|
|
IAbpDistributedLock distributedLockProvider)
|
|
: base(
|
|
currentTenant,
|
|
unitOfWorkManager,
|
|
tenantStore,
|
|
distributedEventBus,
|
|
OrderingServiceDbProperties.ConnectionStringName,
|
|
distributedLockProvider)
|
|
{
|
|
_dataSeeder = dataSeeder;
|
|
}
|
|
|
|
public async Task HandleEventAsync(ApplyDatabaseMigrationsEto eventData)
|
|
{
|
|
Logger.LogInformation("OrderingService - HandleEventAsync started ...");
|
|
|
|
if (eventData.DatabaseName != DatabaseName)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (eventData.TenantId != null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
try
|
|
{
|
|
Logger.LogInformation("OrderingService - Before Acquire ");
|
|
|
|
await using (var handle = await DistributedLockProvider.TryAcquireAsync(DatabaseName))
|
|
{
|
|
if (handle != null)
|
|
{
|
|
await MigrateDatabaseSchemaAsync(null);
|
|
Logger.LogInformation("Starting OrderingService DataSeeder...");
|
|
await _dataSeeder.SeedAsync();
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
await HandleErrorOnApplyDatabaseMigrationAsync(eventData, ex);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|