52 changed files with 1484 additions and 1470 deletions
|
After Width: | Height: | Size: 166 KiB |
|
Before Width: | Height: | Size: 522 KiB After Width: | Height: | Size: 517 KiB |
@ -1,13 +1,12 @@ |
|||
using Microsoft.AspNetCore.Mvc; |
|||
using Volo.Abp.AspNetCore.Mvc; |
|||
|
|||
namespace EShopOnAbp.AdministrationService.Controllers |
|||
namespace EShopOnAbp.AdministrationService.Controllers; |
|||
|
|||
public class HomeController : AbpController |
|||
{ |
|||
public class HomeController : AbpController |
|||
public ActionResult Index() |
|||
{ |
|||
public ActionResult Index() |
|||
{ |
|||
return Redirect("~/swagger"); |
|||
} |
|||
return Redirect("~/swagger"); |
|||
} |
|||
} |
|||
} |
|||
@ -1,101 +1,94 @@ |
|||
using EShopOnAbp.AdministrationService.EntityFrameworkCore; |
|||
using EShopOnAbp.Shared.Hosting.Microservices.DbMigrations.EfCore; |
|||
using Serilog; |
|||
using System; |
|||
using System.Linq; |
|||
using System.Threading.Tasks; |
|||
using EShopOnAbp.Shared.Hosting.Microservices.DbMigrations.EfCore; |
|||
using Volo.Abp.Authorization.Permissions; |
|||
using Volo.Abp.Data; |
|||
using Volo.Abp.DistributedLocking; |
|||
using Volo.Abp.EventBus.Distributed; |
|||
using Volo.Abp.MultiTenancy; |
|||
using Volo.Abp.PermissionManagement; |
|||
using Volo.Abp.Uow; |
|||
|
|||
namespace EShopOnAbp.AdministrationService.DbMigrations |
|||
{ |
|||
public class AdministrationServiceDatabaseMigrationEventHandler |
|||
namespace EShopOnAbp.AdministrationService.DbMigrations; |
|||
|
|||
public class AdministrationServiceDatabaseMigrationEventHandler |
|||
: DatabaseEfCoreMigrationEventHandler<AdministrationServiceDbContext>, |
|||
IDistributedEventHandler<TenantCreatedEto>, |
|||
IDistributedEventHandler<ApplyDatabaseMigrationsEto> |
|||
IDistributedEventHandler<ApplyDatabaseMigrationsEto> |
|||
{ |
|||
private readonly IPermissionDefinitionManager _permissionDefinitionManager; |
|||
private readonly IPermissionDataSeeder _permissionDataSeeder; |
|||
|
|||
public AdministrationServiceDatabaseMigrationEventHandler( |
|||
ICurrentTenant currentTenant, |
|||
IUnitOfWorkManager unitOfWorkManager, |
|||
ITenantStore tenantStore, |
|||
IPermissionDefinitionManager permissionDefinitionManager, |
|||
IPermissionDataSeeder permissionDataSeeder, |
|||
IDistributedEventBus distributedEventBus, |
|||
IAbpDistributedLock distributedLockProvider |
|||
) : base( |
|||
currentTenant, |
|||
unitOfWorkManager, |
|||
tenantStore, |
|||
distributedEventBus, |
|||
AdministrationServiceDbProperties.ConnectionStringName, |
|||
distributedLockProvider |
|||
) |
|||
{ |
|||
private readonly IPermissionDefinitionManager _permissionDefinitionManager; |
|||
private readonly IPermissionDataSeeder _permissionDataSeeder; |
|||
_permissionDefinitionManager = permissionDefinitionManager; |
|||
_permissionDataSeeder = permissionDataSeeder; |
|||
} |
|||
|
|||
public AdministrationServiceDatabaseMigrationEventHandler( |
|||
ICurrentTenant currentTenant, |
|||
IUnitOfWorkManager unitOfWorkManager, |
|||
ITenantStore tenantStore, |
|||
IPermissionDefinitionManager permissionDefinitionManager, |
|||
IPermissionDataSeeder permissionDataSeeder, |
|||
IDistributedEventBus distributedEventBus |
|||
) : base( |
|||
currentTenant, |
|||
unitOfWorkManager, |
|||
tenantStore, |
|||
distributedEventBus, |
|||
AdministrationServiceDbProperties.ConnectionStringName) |
|||
public async Task HandleEventAsync(ApplyDatabaseMigrationsEto eventData) |
|||
{ |
|||
if (eventData.DatabaseName != DatabaseName) |
|||
{ |
|||
_permissionDefinitionManager = permissionDefinitionManager; |
|||
_permissionDataSeeder = permissionDataSeeder; |
|||
return; |
|||
} |
|||
|
|||
public async Task HandleEventAsync(ApplyDatabaseMigrationsEto eventData) |
|||
try |
|||
{ |
|||
if (eventData.DatabaseName != DatabaseName) |
|||
await using (var handle = await DistributedLockProvider.TryAcquireAsync(DatabaseName)) |
|||
{ |
|||
return; |
|||
} |
|||
Log.Information("AdministrationService acquired lock for db migration and seeding..."); |
|||
|
|||
try |
|||
{ |
|||
var schemaMigrated = await MigrateDatabaseSchemaAsync(eventData.TenantId); |
|||
await SeedDataAsync(eventData.TenantId); |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
await HandleErrorOnApplyDatabaseMigrationAsync(eventData, ex); |
|||
if (handle != null) |
|||
{ |
|||
await MigrateDatabaseSchemaAsync(); |
|||
await SeedDataAsync(); |
|||
} |
|||
} |
|||
} |
|||
|
|||
public async Task HandleEventAsync(TenantCreatedEto eventData) |
|||
catch (Exception ex) |
|||
{ |
|||
try |
|||
{ |
|||
await MigrateDatabaseSchemaAsync(eventData.Id); |
|||
await SeedDataAsync(eventData.Id); |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
await HandleErrorTenantCreatedAsync(eventData, ex); |
|||
} |
|||
await HandleErrorOnApplyDatabaseMigrationAsync(eventData, ex); |
|||
} |
|||
} |
|||
|
|||
private async Task SeedDataAsync(Guid? tenantId) |
|||
private async Task SeedDataAsync() |
|||
{ |
|||
using (var uow = UnitOfWorkManager.Begin(requiresNew: true, isTransactional: true)) |
|||
{ |
|||
using (CurrentTenant.Change(tenantId)) |
|||
{ |
|||
using (var uow = UnitOfWorkManager.Begin(requiresNew: true, isTransactional: true)) |
|||
{ |
|||
var multiTenancySide = tenantId == null |
|||
? MultiTenancySides.Host |
|||
: MultiTenancySides.Tenant; |
|||
var multiTenancySide = MultiTenancySides.Host; |
|||
|
|||
var permissionNames = _permissionDefinitionManager |
|||
.GetPermissions() |
|||
.Where(p => p.MultiTenancySide.HasFlag(multiTenancySide)) |
|||
.Where(p => !p.Providers.Any() || p.Providers.Contains(RolePermissionValueProvider.ProviderName)) |
|||
.Select(p => p.Name) |
|||
.ToArray(); |
|||
var permissionNames = _permissionDefinitionManager |
|||
.GetPermissions() |
|||
.Where(p => p.MultiTenancySide.HasFlag(multiTenancySide)) |
|||
.Where(p => !p.Providers.Any() || |
|||
p.Providers.Contains(RolePermissionValueProvider.ProviderName)) |
|||
.Select(p => p.Name) |
|||
.ToArray(); |
|||
|
|||
await _permissionDataSeeder.SeedAsync( |
|||
RolePermissionValueProvider.ProviderName, |
|||
"admin", |
|||
permissionNames, |
|||
tenantId |
|||
); |
|||
await _permissionDataSeeder.SeedAsync( |
|||
RolePermissionValueProvider.ProviderName, |
|||
"admin", |
|||
permissionNames |
|||
); |
|||
|
|||
await uow.CompleteAsync(); |
|||
} |
|||
} |
|||
await uow.CompleteAsync(); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -1,13 +1,12 @@ |
|||
using Microsoft.AspNetCore.Mvc; |
|||
using Volo.Abp.AspNetCore.Mvc; |
|||
|
|||
namespace EShopOnAbp.CatalogService.Controllers |
|||
namespace EShopOnAbp.CatalogService.Controllers; |
|||
|
|||
public class HomeController : AbpController |
|||
{ |
|||
public class HomeController : AbpController |
|||
public ActionResult Index() |
|||
{ |
|||
public ActionResult Index() |
|||
{ |
|||
return Redirect("~/swagger"); |
|||
} |
|||
return Redirect("~/swagger"); |
|||
} |
|||
} |
|||
} |
|||
@ -1,53 +1,66 @@ |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
using EShopOnAbp.CatalogService.MongoDB; |
|||
using EShopOnAbp.CatalogService.MongoDB; |
|||
using EShopOnAbp.Shared.Hosting.Microservices.DbMigrations.MongoDb; |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
using Serilog; |
|||
using Volo.Abp.Data; |
|||
using Volo.Abp.DistributedLocking; |
|||
using Volo.Abp.EventBus.Distributed; |
|||
using Volo.Abp.MultiTenancy; |
|||
using Volo.Abp.Uow; |
|||
|
|||
namespace EShopOnAbp.CatalogService.DbMigrations |
|||
{ |
|||
public class CatalogServiceDatabaseMigrationEventHandler |
|||
: DatabaseMongoDbMigrationEventHandler<CatalogServiceMongoDbContext>, |
|||
namespace EShopOnAbp.CatalogService.DbMigrations; |
|||
|
|||
public class CatalogServiceDatabaseMigrationEventHandler |
|||
: DatabaseMongoDbMigrationEventHandler<CatalogServiceMongoDbContext>, |
|||
IDistributedEventHandler<ApplyDatabaseMigrationsEto> |
|||
{ |
|||
public CatalogServiceDatabaseMigrationEventHandler( |
|||
ICurrentTenant currentTenant, |
|||
IUnitOfWorkManager unitOfWorkManager, |
|||
ITenantStore tenantStore, |
|||
IDistributedEventBus distributedEventBus, |
|||
IServiceProvider serviceProvider, |
|||
IAbpDistributedLock distributedLockProvider |
|||
) : base( |
|||
currentTenant, |
|||
unitOfWorkManager, |
|||
tenantStore, |
|||
distributedEventBus, |
|||
CatalogServiceDbProperties.ConnectionStringName, |
|||
serviceProvider, |
|||
distributedLockProvider) |
|||
{ |
|||
public CatalogServiceDatabaseMigrationEventHandler( |
|||
ICurrentTenant currentTenant, |
|||
IUnitOfWorkManager unitOfWorkManager, |
|||
ITenantStore tenantStore, |
|||
IDistributedEventBus distributedEventBus, |
|||
IServiceProvider serviceProvider |
|||
) : base( |
|||
currentTenant, |
|||
unitOfWorkManager, |
|||
tenantStore, |
|||
distributedEventBus, |
|||
CatalogServiceDbProperties.ConnectionStringName,serviceProvider) |
|||
} |
|||
|
|||
public async Task HandleEventAsync(ApplyDatabaseMigrationsEto eventData) |
|||
{ |
|||
if (eventData.DatabaseName != DatabaseName) |
|||
{ |
|||
return; |
|||
} |
|||
|
|||
public async Task HandleEventAsync(ApplyDatabaseMigrationsEto eventData) |
|||
if (eventData.TenantId != null) |
|||
{ |
|||
if (eventData.DatabaseName != DatabaseName) |
|||
{ |
|||
return; |
|||
} |
|||
return; |
|||
} |
|||
|
|||
if (eventData.TenantId != null) |
|||
{ |
|||
return; |
|||
} |
|||
try |
|||
{ |
|||
Log.Information("CatalogService has acquired lock for db migration..."); |
|||
|
|||
try |
|||
await using (var handle = await DistributedLockProvider.TryAcquireAsync(DatabaseName)) |
|||
{ |
|||
await MigrateDatabaseSchemaAsync(null); |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
await HandleErrorOnApplyDatabaseMigrationAsync(eventData, ex); |
|||
if (handle != null) |
|||
{ |
|||
Log.Information("CatalogService is migrating database..."); |
|||
await MigrateDatabaseSchemaAsync(); |
|||
} |
|||
} |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
await HandleErrorOnApplyDatabaseMigrationAsync(eventData, ex); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -1,110 +1,108 @@ |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
using EShopOnAbp.CatalogService.Products; |
|||
using Volo.Abp.Data; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.Domain.Repositories; |
|||
using Volo.Abp.Uow; |
|||
|
|||
namespace EShopOnAbp.CatalogService.DbMigrations |
|||
namespace EShopOnAbp.CatalogService.DbMigrations; |
|||
|
|||
public class ProductServiceDataSeeder : ITransientDependency |
|||
{ |
|||
public class ProductServiceDataSeeder : ITransientDependency |
|||
private readonly ProductManager _productManager; |
|||
private readonly IRepository<Product, Guid> _productRepository; |
|||
|
|||
public ProductServiceDataSeeder( |
|||
IRepository<Product, Guid> productRepository, |
|||
ProductManager productManager) |
|||
{ |
|||
private readonly ProductManager _productManager; |
|||
private readonly IRepository<Product, Guid> _productRepository; |
|||
_productRepository = productRepository; |
|||
_productManager = productManager; |
|||
} |
|||
|
|||
public ProductServiceDataSeeder( |
|||
IRepository<Product, Guid> productRepository, |
|||
ProductManager productManager) |
|||
{ |
|||
_productRepository = productRepository; |
|||
_productManager = productManager; |
|||
} |
|||
[UnitOfWork] |
|||
public virtual async Task SeedAsync() |
|||
{ |
|||
await AddProductsAsync(); |
|||
} |
|||
|
|||
[UnitOfWork] |
|||
public virtual async Task SeedAsync() |
|||
private async Task AddProductsAsync() |
|||
{ |
|||
if (await _productRepository.GetCountAsync() > 0) |
|||
{ |
|||
await AddProductsAsync(); |
|||
return; |
|||
} |
|||
|
|||
private async Task AddProductsAsync() |
|||
{ |
|||
if (await _productRepository.GetCountAsync() > 0) |
|||
{ |
|||
return; |
|||
} |
|||
|
|||
await _productManager.CreateAsync( |
|||
"ABP04918", |
|||
"Lego Star Wars - 75059 Sandcrawler UCS", |
|||
999, |
|||
42, |
|||
"lego.jpg" |
|||
); |
|||
await _productManager.CreateAsync( |
|||
"ABP04918", |
|||
"Lego Star Wars - 75059 Sandcrawler UCS", |
|||
999, |
|||
42, |
|||
"lego.jpg" |
|||
); |
|||
|
|||
await _productManager.CreateAsync( |
|||
"ABP23849", |
|||
"Nikon AF-S 50mm f/1.8 G Lens", |
|||
1499, |
|||
56, |
|||
"nikon.jpg" |
|||
); |
|||
await _productManager.CreateAsync( |
|||
"ABP23849", |
|||
"Nikon AF-S 50mm f/1.8 G Lens", |
|||
1499, |
|||
56, |
|||
"nikon.jpg" |
|||
); |
|||
|
|||
await _productManager.CreateAsync( |
|||
"ABP82731", |
|||
"Beats Solo3 Wireless On-Ear Headphone", |
|||
97, |
|||
20, |
|||
"beats.jpg" |
|||
); |
|||
await _productManager.CreateAsync( |
|||
"ABP82731", |
|||
"Beats Solo3 Wireless On-Ear Headphone", |
|||
97, |
|||
20, |
|||
"beats.jpg" |
|||
); |
|||
|
|||
await _productManager.CreateAsync( |
|||
"ABP12322", |
|||
"Rampage Sn-Rw2 Gamer Headphone", |
|||
654, |
|||
42, |
|||
"rampage.jpg" |
|||
); |
|||
await _productManager.CreateAsync( |
|||
"ABP12322", |
|||
"Rampage Sn-Rw2 Gamer Headphone", |
|||
654, |
|||
42, |
|||
"rampage.jpg" |
|||
); |
|||
|
|||
await _productManager.CreateAsync( |
|||
"ABP00291", |
|||
"Asus Transformer Book T300CHI-FH011H", |
|||
1249, |
|||
3, |
|||
"asus.jpg" |
|||
); |
|||
await _productManager.CreateAsync( |
|||
"ABP00291", |
|||
"Asus Transformer Book T300CHI-FH011H", |
|||
1249, |
|||
3, |
|||
"asus.jpg" |
|||
); |
|||
|
|||
await _productManager.CreateAsync( |
|||
"ABP02918", |
|||
"OKI C332DN Dublex + Network A4 Laser Printer", |
|||
215, |
|||
6, |
|||
"oki.jpg" |
|||
); |
|||
await _productManager.CreateAsync( |
|||
"ABP02918", |
|||
"OKI C332DN Dublex + Network A4 Laser Printer", |
|||
215, |
|||
6, |
|||
"oki.jpg" |
|||
); |
|||
|
|||
await _productManager.CreateAsync( |
|||
"ABP11121", |
|||
"Bluecat Rd810 Mini Led", |
|||
449, |
|||
13, |
|||
"bluecat.jpg" |
|||
); |
|||
await _productManager.CreateAsync( |
|||
"ABP11121", |
|||
"Bluecat Rd810 Mini Led", |
|||
449, |
|||
13, |
|||
"bluecat.jpg" |
|||
); |
|||
|
|||
await _productManager.CreateAsync( |
|||
"ABP44432", |
|||
"Sunny 55\" TV 4K Ultra HD Curved Smart Led TV", |
|||
2249, |
|||
1, |
|||
"sunny.jpg" |
|||
); |
|||
await _productManager.CreateAsync( |
|||
"ABP44432", |
|||
"Sunny 55\" TV 4K Ultra HD Curved Smart Led TV", |
|||
2249, |
|||
1, |
|||
"sunny.jpg" |
|||
); |
|||
|
|||
await _productManager.CreateAsync( |
|||
"ABP37182", |
|||
"Sony Playstation 4 Slim 500 GB (PAL)", |
|||
699, |
|||
120, |
|||
"playstation.jpg" |
|||
); |
|||
} |
|||
await _productManager.CreateAsync( |
|||
"ABP37182", |
|||
"Sony Playstation 4 Slim 500 GB (PAL)", |
|||
699, |
|||
120, |
|||
"playstation.jpg" |
|||
); |
|||
} |
|||
} |
|||
} |
|||
@ -1,13 +1,12 @@ |
|||
using Microsoft.AspNetCore.Mvc; |
|||
using Volo.Abp.AspNetCore.Mvc; |
|||
|
|||
namespace EShopOnAbp.IdentityService.Controllers |
|||
namespace EShopOnAbp.IdentityService.Controllers; |
|||
|
|||
public class HomeController : AbpController |
|||
{ |
|||
public class HomeController : AbpController |
|||
public ActionResult Index() |
|||
{ |
|||
public ActionResult Index() |
|||
{ |
|||
return Redirect("~/swagger"); |
|||
} |
|||
return Redirect("~/swagger"); |
|||
} |
|||
} |
|||
} |
|||
@ -1,10 +1,9 @@ |
|||
using Volo.Abp.Domain.Entities.Events.Distributed; |
|||
using Volo.Abp.EventBus; |
|||
|
|||
namespace EShopOnAbp.IdentityService.DbMigrations |
|||
namespace EShopOnAbp.IdentityService.DbMigrations; |
|||
|
|||
[EventName("abp.identity.apply_database_seeds")] |
|||
public class ApplyDatabaseSeedsEto : EtoBase |
|||
{ |
|||
[EventName("abp.identity.apply_database_seeds")] |
|||
public class ApplyDatabaseSeedsEto : EtoBase |
|||
{ |
|||
} |
|||
} |
|||
} |
|||
@ -1,23 +1,21 @@ |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Data; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.EventBus; |
|||
|
|||
namespace EShopOnAbp.IdentityService.DbMigrations |
|||
namespace EShopOnAbp.IdentityService.DbMigrations; |
|||
|
|||
public class DataSeederEventHandler : ILocalEventHandler<ApplyDatabaseSeedsEto>, ITransientDependency |
|||
{ |
|||
public class DataSeederEventHandler : ILocalEventHandler<ApplyDatabaseSeedsEto>, ITransientDependency |
|||
{ |
|||
protected IDataSeeder DataSeeder { get; } |
|||
protected IDataSeeder DataSeeder { get; } |
|||
|
|||
public DataSeederEventHandler(IDataSeeder dataSeeder) |
|||
{ |
|||
DataSeeder = dataSeeder; |
|||
} |
|||
public DataSeederEventHandler(IDataSeeder dataSeeder) |
|||
{ |
|||
DataSeeder = dataSeeder; |
|||
} |
|||
|
|||
public async Task HandleEventAsync(ApplyDatabaseSeedsEto eventData) |
|||
{ |
|||
await DataSeeder.SeedAsync(); |
|||
} |
|||
public async Task HandleEventAsync(ApplyDatabaseSeedsEto eventData) |
|||
{ |
|||
await DataSeeder.SeedAsync(); |
|||
} |
|||
} |
|||
} |
|||
@ -1,104 +1,90 @@ |
|||
using EShopOnAbp.IdentityService.EntityFrameworkCore; |
|||
using EShopOnAbp.Shared.Hosting.Microservices.DbMigrations.EfCore; |
|||
using Serilog; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Threading.Tasks; |
|||
using EShopOnAbp.Shared.Hosting.Microservices.DbMigrations.EfCore; |
|||
using Volo.Abp.Data; |
|||
using Volo.Abp.DistributedLocking; |
|||
using Volo.Abp.EventBus.Distributed; |
|||
using Volo.Abp.EventBus.Local; |
|||
using Volo.Abp.Identity; |
|||
using Volo.Abp.MultiTenancy; |
|||
using Volo.Abp.Uow; |
|||
|
|||
namespace EShopOnAbp.IdentityService.DbMigrations |
|||
namespace EShopOnAbp.IdentityService.DbMigrations; |
|||
|
|||
public class IdentityServiceDatabaseMigrationEventHandler |
|||
: DatabaseEfCoreMigrationEventHandler<IdentityServiceDbContext>, |
|||
IDistributedEventHandler<ApplyDatabaseMigrationsEto> |
|||
{ |
|||
public class IdentityServiceDatabaseMigrationEventHandler |
|||
: DatabaseEfCoreMigrationEventHandler<IdentityServiceDbContext>, |
|||
IDistributedEventHandler<TenantCreatedEto>, |
|||
IDistributedEventHandler<ApplyDatabaseMigrationsEto> |
|||
private readonly IIdentityDataSeeder _identityDataSeeder; |
|||
private readonly IdentityServerDataSeeder _identityServerDataSeeder; |
|||
private readonly ILocalEventBus _localEventBus; |
|||
|
|||
public IdentityServiceDatabaseMigrationEventHandler( |
|||
ICurrentTenant currentTenant, |
|||
IUnitOfWorkManager unitOfWorkManager, |
|||
ITenantStore tenantStore, |
|||
IIdentityDataSeeder identityDataSeeder, |
|||
IdentityServerDataSeeder identityServerDataSeeder, |
|||
IDistributedEventBus distributedEventBus, |
|||
ILocalEventBus localEventBus, |
|||
IAbpDistributedLock distributedLockProvider |
|||
) : base( |
|||
currentTenant, |
|||
unitOfWorkManager, |
|||
tenantStore, |
|||
distributedEventBus, |
|||
IdentityServiceDbProperties.ConnectionStringName, |
|||
distributedLockProvider) |
|||
{ |
|||
private readonly IIdentityDataSeeder _identityDataSeeder; |
|||
private readonly IdentityServerDataSeeder _identityServerDataSeeder; |
|||
private readonly ILocalEventBus _localEventBus; |
|||
_identityDataSeeder = identityDataSeeder; |
|||
_identityServerDataSeeder = identityServerDataSeeder; |
|||
_localEventBus = localEventBus; |
|||
} |
|||
|
|||
public IdentityServiceDatabaseMigrationEventHandler( |
|||
ICurrentTenant currentTenant, |
|||
IUnitOfWorkManager unitOfWorkManager, |
|||
ITenantStore tenantStore, |
|||
IIdentityDataSeeder identityDataSeeder, |
|||
IdentityServerDataSeeder identityServerDataSeeder, |
|||
IDistributedEventBus distributedEventBus, |
|||
ILocalEventBus localEventBus |
|||
) : base( |
|||
currentTenant, |
|||
unitOfWorkManager, |
|||
tenantStore, |
|||
distributedEventBus, |
|||
IdentityServiceDbProperties.ConnectionStringName) |
|||
public async Task HandleEventAsync(ApplyDatabaseMigrationsEto eventData) |
|||
{ |
|||
if (eventData.DatabaseName != DatabaseName) |
|||
{ |
|||
_identityDataSeeder = identityDataSeeder; |
|||
_identityServerDataSeeder = identityServerDataSeeder; |
|||
_localEventBus = localEventBus; |
|||
return; |
|||
} |
|||
|
|||
public async Task HandleEventAsync(ApplyDatabaseMigrationsEto eventData) |
|||
try |
|||
{ |
|||
if (eventData.DatabaseName != DatabaseName) |
|||
{ |
|||
return; |
|||
} |
|||
|
|||
try |
|||
await using (var handle = await DistributedLockProvider.TryAcquireAsync(DatabaseName)) |
|||
{ |
|||
var schemaMigrated = await MigrateDatabaseSchemaAsync(eventData.TenantId); |
|||
await SeedDataAsync( |
|||
tenantId: eventData.TenantId, |
|||
adminEmail: IdentityServiceDbProperties.DefaultAdminEmailAddress, |
|||
adminPassword: IdentityServiceDbProperties.DefaultAdminPassword |
|||
); |
|||
Log.Information("IdentityService has acquired lock for db migration..."); |
|||
|
|||
await _localEventBus.PublishAsync(new ApplyDatabaseSeedsEto()); |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
await HandleErrorOnApplyDatabaseMigrationAsync(eventData, ex); |
|||
if (handle != null) |
|||
{ |
|||
Log.Information("IdentityService is migrating database..."); |
|||
await MigrateDatabaseSchemaAsync(); |
|||
Log.Information("IdentityService is seeding data..."); |
|||
await SeedDataAsync( |
|||
adminEmail: IdentityServiceDbProperties.DefaultAdminEmailAddress, |
|||
adminPassword: IdentityServiceDbProperties.DefaultAdminPassword |
|||
); |
|||
} |
|||
} |
|||
|
|||
await _localEventBus.PublishAsync(new ApplyDatabaseSeedsEto()); |
|||
} |
|||
|
|||
public async Task HandleEventAsync(TenantCreatedEto eventData) |
|||
{ |
|||
try |
|||
{ |
|||
await MigrateDatabaseSchemaAsync(eventData.Id); |
|||
await SeedDataAsync( |
|||
tenantId: eventData.Id, |
|||
adminEmail: eventData.Properties.GetOrDefault(IdentityDataSeedContributor.AdminEmailPropertyName) ?? IdentityServiceDbProperties.DefaultAdminEmailAddress, |
|||
adminPassword: eventData.Properties.GetOrDefault(IdentityDataSeedContributor.AdminPasswordPropertyName) ?? IdentityServiceDbProperties.DefaultAdminPassword |
|||
); |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
await HandleErrorTenantCreatedAsync(eventData, ex); |
|||
} |
|||
} |
|||
private async Task SeedDataAsync(Guid? tenantId, string adminEmail, string adminPassword) |
|||
catch (Exception ex) |
|||
{ |
|||
using (CurrentTenant.Change(tenantId)) |
|||
{ |
|||
if (tenantId == null) |
|||
{ |
|||
Log.Information($"Seeding IdentityServer data..."); |
|||
await _identityServerDataSeeder.SeedAsync(); |
|||
} |
|||
Log.Information($"Seeding user data..."); |
|||
await _identityDataSeeder.SeedAsync( |
|||
adminEmail, |
|||
adminPassword, |
|||
tenantId |
|||
); |
|||
} |
|||
await HandleErrorOnApplyDatabaseMigrationAsync(eventData, ex); |
|||
} |
|||
} |
|||
} |
|||
|
|||
private async Task SeedDataAsync(string adminEmail, string adminPassword) |
|||
{ |
|||
Log.Information($"Seeding IdentityServer data..."); |
|||
await _identityServerDataSeeder.SeedAsync(); |
|||
|
|||
Log.Information($"Seeding user data..."); |
|||
await _identityDataSeeder.SeedAsync( |
|||
adminEmail, |
|||
adminPassword |
|||
); |
|||
} |
|||
} |
|||
@ -0,0 +1,9 @@ |
|||
namespace EShopOnAbp.OrderingService.Orders; |
|||
|
|||
public enum OrderStatus |
|||
{ |
|||
Placed, |
|||
Paid, |
|||
Shipped, |
|||
Cancelled |
|||
} |
|||
@ -1,48 +0,0 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using Volo.Abp; |
|||
|
|||
namespace EShopOnAbp.OrderingService.Orders; |
|||
|
|||
public class OrderStatus : Enumeration |
|||
{ |
|||
public static OrderStatus Placed = new OrderStatus(1, nameof(Placed).ToLowerInvariant()); |
|||
public static OrderStatus Paid = new OrderStatus(2, nameof(Paid).ToLowerInvariant()); |
|||
public static OrderStatus Shipped = new OrderStatus(3, nameof(Shipped).ToLowerInvariant()); |
|||
public static OrderStatus Cancelled = new OrderStatus(4, nameof(Cancelled).ToLowerInvariant()); |
|||
|
|||
public OrderStatus(int id, string name) : base(id, name) |
|||
{ |
|||
} |
|||
|
|||
public static IEnumerable<OrderStatus> List() => |
|||
new[] {Placed, Paid, Shipped, Cancelled}; |
|||
|
|||
public static OrderStatus FromName(string name) |
|||
{ |
|||
var state = List() |
|||
.SingleOrDefault(s => String.Equals(s.Name, name, StringComparison.CurrentCultureIgnoreCase)); |
|||
|
|||
if (state == null) |
|||
{ |
|||
throw new BusinessException(OrderingServiceErrorCodes.OrderingStatusNotFound) |
|||
.WithData("OrderStatus", String.Join(",", List().Select(s => s.Name))); |
|||
} |
|||
|
|||
return state; |
|||
} |
|||
|
|||
public static OrderStatus From(int id) |
|||
{ |
|||
var state = List().SingleOrDefault(s => s.Id == id); |
|||
|
|||
if (state == null) |
|||
{ |
|||
throw new BusinessException(OrderingServiceErrorCodes.OrderingStatusNotFound) |
|||
.WithData("OrderStatus", String.Join(",", List().Select(s => s.Name))); |
|||
} |
|||
|
|||
return state; |
|||
} |
|||
} |
|||
@ -1,37 +0,0 @@ |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Threading.Tasks; |
|||
using EShopOnAbp.OrderingService.Orders; |
|||
using Microsoft.EntityFrameworkCore; |
|||
using Volo.Abp.Data; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace EShopOnAbp.OrderingService.EntityFrameworkCore; |
|||
|
|||
/// <summary>
|
|||
/// DataSeedContributor for seeding pre-exist order status data.
|
|||
/// This is a sample for seeding data without DbSet (non-aggregate data), without using repository.
|
|||
/// </summary>
|
|||
public class OrderServiceDataSeedContributor : IDataSeedContributor, ITransientDependency |
|||
{ |
|||
private readonly IOrderingServiceDbContext _dbContext; |
|||
|
|||
public OrderServiceDataSeedContributor(IOrderingServiceDbContext dbContext) |
|||
{ |
|||
_dbContext = dbContext; |
|||
} |
|||
|
|||
public async Task SeedAsync(DataSeedContext context) |
|||
{ |
|||
await SeedOrderStatusAsync(); |
|||
} |
|||
|
|||
private async Task SeedOrderStatusAsync() |
|||
{ |
|||
if (!await _dbContext.Set<OrderStatus>().AnyAsync()) |
|||
{ |
|||
await _dbContext.Set<OrderStatus>().AddRangeAsync(OrderStatus.List()); |
|||
await _dbContext.SaveChangesAsync(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,182 @@ |
|||
// <auto-generated />
|
|||
using System; |
|||
using EShopOnAbp.OrderingService.EntityFrameworkCore; |
|||
using Microsoft.EntityFrameworkCore; |
|||
using Microsoft.EntityFrameworkCore.Infrastructure; |
|||
using Microsoft.EntityFrameworkCore.Migrations; |
|||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion; |
|||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; |
|||
using Volo.Abp.EntityFrameworkCore; |
|||
|
|||
#nullable disable |
|||
|
|||
namespace EShopOnAbp.OrderingService.Migrations |
|||
{ |
|||
[DbContext(typeof(OrderingServiceDbContext))] |
|||
[Migration("20220317123922_RemovedOrderStatusTable")] |
|||
partial class RemovedOrderStatusTable |
|||
{ |
|||
protected override void BuildTargetModel(ModelBuilder modelBuilder) |
|||
{ |
|||
#pragma warning disable 612, 618
|
|||
modelBuilder |
|||
.HasAnnotation("_Abp_DatabaseProvider", EfCoreDatabaseProvider.PostgreSql) |
|||
.HasAnnotation("ProductVersion", "6.0.1") |
|||
.HasAnnotation("Relational:MaxIdentifierLength", 63); |
|||
|
|||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); |
|||
|
|||
modelBuilder.Entity("EShopOnAbp.OrderingService.Orders.Order", b => |
|||
{ |
|||
b.Property<Guid>("Id") |
|||
.HasColumnType("uuid"); |
|||
|
|||
b.Property<string>("ConcurrencyStamp") |
|||
.IsConcurrencyToken() |
|||
.HasMaxLength(40) |
|||
.HasColumnType("character varying(40)") |
|||
.HasColumnName("ConcurrencyStamp"); |
|||
|
|||
b.Property<string>("ExtraProperties") |
|||
.HasColumnType("text") |
|||
.HasColumnName("ExtraProperties"); |
|||
|
|||
b.Property<DateTime>("OrderDate") |
|||
.HasColumnType("timestamp without time zone"); |
|||
|
|||
b.Property<int>("OrderNo") |
|||
.HasColumnType("integer"); |
|||
|
|||
b.Property<string>("OrderStatus") |
|||
.IsRequired() |
|||
.HasColumnType("text"); |
|||
|
|||
b.Property<string>("PaymentMethod") |
|||
.IsRequired() |
|||
.HasMaxLength(128) |
|||
.HasColumnType("character varying(128)"); |
|||
|
|||
b.Property<Guid?>("PaymentRequestId") |
|||
.HasColumnType("uuid"); |
|||
|
|||
b.Property<string>("PaymentStatus") |
|||
.HasMaxLength(256) |
|||
.HasColumnType("character varying(256)"); |
|||
|
|||
b.HasKey("Id"); |
|||
|
|||
b.ToTable("Orders", (string)null); |
|||
}); |
|||
|
|||
modelBuilder.Entity("EShopOnAbp.OrderingService.Orders.OrderItem", b => |
|||
{ |
|||
b.Property<Guid>("Id") |
|||
.HasColumnType("uuid"); |
|||
|
|||
b.Property<decimal>("Discount") |
|||
.HasColumnType("numeric"); |
|||
|
|||
b.Property<Guid>("OrderId") |
|||
.HasColumnType("uuid"); |
|||
|
|||
b.Property<string>("PictureUrl") |
|||
.HasColumnType("text"); |
|||
|
|||
b.Property<string>("ProductCode") |
|||
.IsRequired() |
|||
.HasColumnType("text"); |
|||
|
|||
b.Property<Guid>("ProductId") |
|||
.HasColumnType("uuid"); |
|||
|
|||
b.Property<string>("ProductName") |
|||
.IsRequired() |
|||
.HasColumnType("text"); |
|||
|
|||
b.Property<decimal>("UnitPrice") |
|||
.HasColumnType("numeric"); |
|||
|
|||
b.Property<int>("Units") |
|||
.HasColumnType("integer"); |
|||
|
|||
b.HasKey("Id"); |
|||
|
|||
b.HasIndex("OrderId"); |
|||
|
|||
b.ToTable("OrderItems", (string)null); |
|||
}); |
|||
|
|||
modelBuilder.Entity("EShopOnAbp.OrderingService.Orders.Order", b => |
|||
{ |
|||
b.OwnsOne("EShopOnAbp.OrderingService.Orders.Address", "Address", b1 => |
|||
{ |
|||
b1.Property<Guid>("OrderId") |
|||
.HasColumnType("uuid"); |
|||
|
|||
b1.Property<string>("City") |
|||
.HasColumnType("text"); |
|||
|
|||
b1.Property<string>("Country") |
|||
.HasColumnType("text"); |
|||
|
|||
b1.Property<string>("Description") |
|||
.HasColumnType("text"); |
|||
|
|||
b1.Property<string>("Street") |
|||
.HasColumnType("text"); |
|||
|
|||
b1.Property<string>("ZipCode") |
|||
.HasColumnType("text"); |
|||
|
|||
b1.HasKey("OrderId"); |
|||
|
|||
b1.ToTable("Orders"); |
|||
|
|||
b1.WithOwner() |
|||
.HasForeignKey("OrderId"); |
|||
}); |
|||
|
|||
b.OwnsOne("EShopOnAbp.OrderingService.Orders.Buyer", "Buyer", b1 => |
|||
{ |
|||
b1.Property<Guid>("OrderId") |
|||
.HasColumnType("uuid"); |
|||
|
|||
b1.Property<string>("Email") |
|||
.HasColumnType("text"); |
|||
|
|||
b1.Property<Guid?>("Id") |
|||
.HasColumnType("uuid"); |
|||
|
|||
b1.Property<string>("Name") |
|||
.HasColumnType("text"); |
|||
|
|||
b1.HasKey("OrderId"); |
|||
|
|||
b1.ToTable("Orders"); |
|||
|
|||
b1.WithOwner() |
|||
.HasForeignKey("OrderId"); |
|||
}); |
|||
|
|||
b.Navigation("Address"); |
|||
|
|||
b.Navigation("Buyer"); |
|||
}); |
|||
|
|||
modelBuilder.Entity("EShopOnAbp.OrderingService.Orders.OrderItem", b => |
|||
{ |
|||
b.HasOne("EShopOnAbp.OrderingService.Orders.Order", null) |
|||
.WithMany("OrderItems") |
|||
.HasForeignKey("OrderId") |
|||
.OnDelete(DeleteBehavior.Cascade) |
|||
.IsRequired(); |
|||
}); |
|||
|
|||
modelBuilder.Entity("EShopOnAbp.OrderingService.Orders.Order", b => |
|||
{ |
|||
b.Navigation("OrderItems"); |
|||
}); |
|||
#pragma warning restore 612, 618
|
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,73 @@ |
|||
using Microsoft.EntityFrameworkCore.Migrations; |
|||
|
|||
#nullable disable |
|||
|
|||
namespace EShopOnAbp.OrderingService.Migrations |
|||
{ |
|||
public partial class RemovedOrderStatusTable : Migration |
|||
{ |
|||
protected override void Up(MigrationBuilder migrationBuilder) |
|||
{ |
|||
migrationBuilder.DropForeignKey( |
|||
name: "FK_Orders_OrderStatus_OrderStatusId", |
|||
table: "Orders"); |
|||
|
|||
migrationBuilder.DropTable( |
|||
name: "OrderStatus"); |
|||
|
|||
migrationBuilder.DropIndex( |
|||
name: "IX_Orders_OrderStatusId", |
|||
table: "Orders"); |
|||
|
|||
migrationBuilder.DropColumn( |
|||
name: "OrderStatusId", |
|||
table: "Orders"); |
|||
|
|||
migrationBuilder.AddColumn<string>( |
|||
name: "OrderStatus", |
|||
table: "Orders", |
|||
type: "text", |
|||
nullable: false, |
|||
defaultValue: ""); |
|||
} |
|||
|
|||
protected override void Down(MigrationBuilder migrationBuilder) |
|||
{ |
|||
migrationBuilder.DropColumn( |
|||
name: "OrderStatus", |
|||
table: "Orders"); |
|||
|
|||
migrationBuilder.AddColumn<int>( |
|||
name: "OrderStatusId", |
|||
table: "Orders", |
|||
type: "integer", |
|||
nullable: false, |
|||
defaultValue: 0); |
|||
|
|||
migrationBuilder.CreateTable( |
|||
name: "OrderStatus", |
|||
columns: table => new |
|||
{ |
|||
Id = table.Column<int>(type: "integer", nullable: false, defaultValue: 1), |
|||
Name = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: false) |
|||
}, |
|||
constraints: table => |
|||
{ |
|||
table.PrimaryKey("PK_OrderStatus", x => x.Id); |
|||
}); |
|||
|
|||
migrationBuilder.CreateIndex( |
|||
name: "IX_Orders_OrderStatusId", |
|||
table: "Orders", |
|||
column: "OrderStatusId"); |
|||
|
|||
migrationBuilder.AddForeignKey( |
|||
name: "FK_Orders_OrderStatus_OrderStatusId", |
|||
table: "Orders", |
|||
column: "OrderStatusId", |
|||
principalTable: "OrderStatus", |
|||
principalColumn: "Id", |
|||
onDelete: ReferentialAction.Cascade); |
|||
} |
|||
} |
|||
} |
|||
@ -1,13 +1,12 @@ |
|||
using Microsoft.AspNetCore.Mvc; |
|||
using Volo.Abp.AspNetCore.Mvc; |
|||
|
|||
namespace EShopOnAbp.OrderingService.Controllers |
|||
namespace EShopOnAbp.OrderingService.Controllers; |
|||
|
|||
public class HomeController : AbpController |
|||
{ |
|||
public class HomeController : AbpController |
|||
public ActionResult Index() |
|||
{ |
|||
public ActionResult Index() |
|||
{ |
|||
return Redirect("~/swagger"); |
|||
} |
|||
return Redirect("~/swagger"); |
|||
} |
|||
} |
|||
} |
|||
@ -1,58 +1,70 @@ |
|||
using EShopOnAbp.OrderingService.EntityFrameworkCore; |
|||
using EShopOnAbp.Shared.Hosting.Microservices.DbMigrations.EfCore; |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
using EShopOnAbp.Shared.Hosting.Microservices.DbMigrations.EfCore; |
|||
using Microsoft.Extensions.Logging; |
|||
using Serilog; |
|||
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>, |
|||
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) |
|||
{ |
|||
private readonly IDataSeeder _dataSeeder; |
|||
public OrderingServiceDatabaseMigrationEventHandler( |
|||
ICurrentTenant currentTenant, |
|||
IUnitOfWorkManager unitOfWorkManager, |
|||
ITenantStore tenantStore, |
|||
IDistributedEventBus distributedEventBus, |
|||
IDataSeeder dataSeeder) |
|||
: base( |
|||
currentTenant, |
|||
unitOfWorkManager, |
|||
tenantStore, |
|||
distributedEventBus, |
|||
OrderingServiceDbProperties.ConnectionStringName) |
|||
_dataSeeder = dataSeeder; |
|||
} |
|||
|
|||
public async Task HandleEventAsync(ApplyDatabaseMigrationsEto eventData) |
|||
{ |
|||
if (eventData.DatabaseName != DatabaseName) |
|||
{ |
|||
_dataSeeder = dataSeeder; |
|||
return; |
|||
} |
|||
|
|||
public async Task HandleEventAsync(ApplyDatabaseMigrationsEto eventData) |
|||
if (eventData.TenantId != null) |
|||
{ |
|||
if (eventData.DatabaseName != DatabaseName) |
|||
{ |
|||
return; |
|||
} |
|||
return; |
|||
} |
|||
|
|||
if (eventData.TenantId != null) |
|||
try |
|||
{ |
|||
await using (var handle = await DistributedLockProvider.TryAcquireAsync(DatabaseName)) |
|||
{ |
|||
return; |
|||
} |
|||
Log.Information("OrderingService has acquired lock for db migration..."); |
|||
|
|||
try |
|||
{ |
|||
await MigrateDatabaseSchemaAsync(null); |
|||
Logger.LogInformation("Starting OrderingService DataSeeder..."); |
|||
await _dataSeeder.SeedAsync(); |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
await HandleErrorOnApplyDatabaseMigrationAsync(eventData, ex); |
|||
if (handle != null) |
|||
{ |
|||
Log.Information("OrderingService is migrating database..."); |
|||
await MigrateDatabaseSchemaAsync(); |
|||
Log.Information("OrderingService is seeding data..."); |
|||
await _dataSeeder.SeedAsync(); |
|||
} |
|||
} |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
await HandleErrorOnApplyDatabaseMigrationAsync(eventData, ex); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -1,13 +1,12 @@ |
|||
using Microsoft.AspNetCore.Mvc; |
|||
using Volo.Abp.AspNetCore.Mvc; |
|||
|
|||
namespace EShopOnAbp.PaymentService.Controllers |
|||
namespace EShopOnAbp.PaymentService.Controllers; |
|||
|
|||
public class HomeController : AbpController |
|||
{ |
|||
public class HomeController : AbpController |
|||
public ActionResult Index() |
|||
{ |
|||
public ActionResult Index() |
|||
{ |
|||
return Redirect("~/swagger"); |
|||
} |
|||
return Redirect("~/swagger"); |
|||
} |
|||
} |
|||
} |
|||
@ -1,52 +1,64 @@ |
|||
using EShopOnAbp.PaymentService.EntityFrameworkCore; |
|||
using EShopOnAbp.Shared.Hosting.Microservices.DbMigrations.EfCore; |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
using EShopOnAbp.Shared.Hosting.Microservices.DbMigrations.EfCore; |
|||
using Serilog; |
|||
using Volo.Abp.Data; |
|||
using Volo.Abp.DistributedLocking; |
|||
using Volo.Abp.EventBus.Distributed; |
|||
using Volo.Abp.MultiTenancy; |
|||
using Volo.Abp.Uow; |
|||
|
|||
namespace EShopOnAbp.PaymentService.DbMigrations |
|||
{ |
|||
public class PaymentServiceDatabaseMigrationEventHandler |
|||
: DatabaseEfCoreMigrationEventHandler<PaymentServiceDbContext>, |
|||
namespace EShopOnAbp.PaymentService.DbMigrations; |
|||
|
|||
public class PaymentServiceDatabaseMigrationEventHandler |
|||
: DatabaseEfCoreMigrationEventHandler<PaymentServiceDbContext>, |
|||
IDistributedEventHandler<ApplyDatabaseMigrationsEto> |
|||
{ |
|||
public PaymentServiceDatabaseMigrationEventHandler( |
|||
ICurrentTenant currentTenant, |
|||
IUnitOfWorkManager unitOfWorkManager, |
|||
ITenantStore tenantStore, |
|||
IDistributedEventBus distributedEventBus, |
|||
IAbpDistributedLock distributedLockProvider) |
|||
: base( |
|||
currentTenant, |
|||
unitOfWorkManager, |
|||
tenantStore, |
|||
distributedEventBus, |
|||
PaymentServiceDbProperties.ConnectionStringName, |
|||
distributedLockProvider) |
|||
{ |
|||
public PaymentServiceDatabaseMigrationEventHandler( |
|||
ICurrentTenant currentTenant, |
|||
IUnitOfWorkManager unitOfWorkManager, |
|||
ITenantStore tenantStore, |
|||
IDistributedEventBus distributedEventBus) |
|||
: base( |
|||
currentTenant, |
|||
unitOfWorkManager, |
|||
tenantStore, |
|||
distributedEventBus, |
|||
PaymentServiceDbProperties.ConnectionStringName) |
|||
} |
|||
|
|||
public async Task HandleEventAsync(ApplyDatabaseMigrationsEto eventData) |
|||
{ |
|||
if (eventData.DatabaseName != DatabaseName) |
|||
{ |
|||
return; |
|||
} |
|||
|
|||
public async Task HandleEventAsync(ApplyDatabaseMigrationsEto eventData) |
|||
if (eventData.TenantId != null) |
|||
{ |
|||
if (eventData.DatabaseName != DatabaseName) |
|||
{ |
|||
return; |
|||
} |
|||
return; |
|||
} |
|||
|
|||
if (eventData.TenantId != null) |
|||
{ |
|||
return; |
|||
} |
|||
try |
|||
{ |
|||
Log.Information("PaymentService has acquired lock for db migration..."); |
|||
|
|||
try |
|||
await using (var handle = await DistributedLockProvider.TryAcquireAsync(DatabaseName)) |
|||
{ |
|||
await MigrateDatabaseSchemaAsync(null); |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
await HandleErrorOnApplyDatabaseMigrationAsync(eventData, ex); |
|||
if (handle != null) |
|||
{ |
|||
Log.Information("PaymentService is migrating database..."); |
|||
await MigrateDatabaseSchemaAsync(); |
|||
} |
|||
} |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
await HandleErrorOnApplyDatabaseMigrationAsync(eventData, ex); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -1,40 +1,39 @@ |
|||
using Serilog; |
|||
using Serilog.Events; |
|||
|
|||
namespace EShopOnAbp.Shared.Hosting.AspNetCore |
|||
namespace EShopOnAbp.Shared.Hosting.AspNetCore; |
|||
|
|||
public static class SerilogConfigurationHelper |
|||
{ |
|||
public static class SerilogConfigurationHelper |
|||
public static void Configure(string applicationName) |
|||
{ |
|||
public static void Configure(string applicationName) |
|||
{ |
|||
// TODO: Uncomment following lines for ElasticSearch configuration
|
|||
// var configuration = new ConfigurationBuilder()
|
|||
// .SetBasePath(Directory.GetCurrentDirectory())
|
|||
// .AddJsonFile("appsettings.json")
|
|||
// .AddEnvironmentVariables()
|
|||
// .Build();
|
|||
// TODO: Uncomment following lines for ElasticSearch configuration
|
|||
// var configuration = new ConfigurationBuilder()
|
|||
// .SetBasePath(Directory.GetCurrentDirectory())
|
|||
// .AddJsonFile("appsettings.json")
|
|||
// .AddEnvironmentVariables()
|
|||
// .Build();
|
|||
|
|||
Log.Logger = new LoggerConfiguration() |
|||
Log.Logger = new LoggerConfiguration() |
|||
#if DEBUG
|
|||
.MinimumLevel.Debug() |
|||
.MinimumLevel.Debug() |
|||
#else
|
|||
.MinimumLevel.Information() |
|||
#endif
|
|||
.MinimumLevel.Override("Microsoft", LogEventLevel.Information) |
|||
.MinimumLevel.Override("Microsoft.EntityFrameworkCore", LogEventLevel.Warning) |
|||
.Enrich.FromLogContext() |
|||
.Enrich.WithProperty("Application", $"{applicationName}") |
|||
.WriteTo.Async(c => c.File("Logs/logs.txt")) |
|||
// TODO: Uncomment following lines for ElasticSearch configuration
|
|||
// .WriteTo.Elasticsearch(
|
|||
// new ElasticsearchSinkOptions(new Uri(configuration["ElasticSearch:Url"]))
|
|||
// {
|
|||
// AutoRegisterTemplate = true,
|
|||
// AutoRegisterTemplateVersion = AutoRegisterTemplateVersion.ESv6,
|
|||
// IndexFormat = "MyProjectName-log-{0:yyyy.MM}"
|
|||
// })
|
|||
.WriteTo.Async(c => c.Console()) |
|||
.CreateLogger(); |
|||
} |
|||
.MinimumLevel.Override("Microsoft", LogEventLevel.Information) |
|||
.MinimumLevel.Override("Microsoft.EntityFrameworkCore", LogEventLevel.Warning) |
|||
.Enrich.FromLogContext() |
|||
.Enrich.WithProperty("Application", $"{applicationName}") |
|||
.WriteTo.Async(c => c.File("Logs/logs.txt")) |
|||
// TODO: Uncomment following lines for ElasticSearch configuration
|
|||
// .WriteTo.Elasticsearch(
|
|||
// new ElasticsearchSinkOptions(new Uri(configuration["ElasticSearch:Url"]))
|
|||
// {
|
|||
// AutoRegisterTemplate = true,
|
|||
// AutoRegisterTemplateVersion = AutoRegisterTemplateVersion.ESv6,
|
|||
// IndexFormat = "MyProjectName-log-{0:yyyy.MM}"
|
|||
// })
|
|||
.WriteTo.Async(c => c.Console()) |
|||
.CreateLogger(); |
|||
} |
|||
} |
|||
@ -1,8 +1,7 @@ |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace EShopOnAbp.Shared.Hosting.Microservices.DbMigrations |
|||
namespace EShopOnAbp.Shared.Hosting.Microservices.DbMigrations; |
|||
|
|||
public abstract class PendingMigrationsCheckerBase : ITransientDependency |
|||
{ |
|||
public abstract class PendingMigrationsCheckerBase : ITransientDependency |
|||
{ |
|||
} |
|||
} |
|||
Loading…
Reference in new issue