Browse Source
Merge pull request #5364 from abpframework/liangshiwei/patch-1
Always migrate seed data
pull/5368/head
maliming
6 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with
14 additions and
16 deletions
-
templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Domain/Data/MyProjectNameDbMigrationService.cs
|
|
|
@ -47,27 +47,25 @@ namespace MyCompanyName.MyProjectName.Data |
|
|
|
var migratedDatabaseSchemas = new HashSet<string>(); |
|
|
|
foreach (var tenant in tenants) |
|
|
|
{ |
|
|
|
if (!tenant.ConnectionStrings.Any()) |
|
|
|
if (tenant.ConnectionStrings.Any()) |
|
|
|
{ |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
using (_currentTenant.Change(tenant.Id)) |
|
|
|
{ |
|
|
|
var tenantConnectionStrings = tenant.ConnectionStrings |
|
|
|
.Select(x => x.Value) |
|
|
|
.ToList(); |
|
|
|
|
|
|
|
if (!migratedDatabaseSchemas.IsSupersetOf(tenantConnectionStrings)) |
|
|
|
using (_currentTenant.Change(tenant.Id)) |
|
|
|
{ |
|
|
|
await MigrateDatabaseSchemaAsync(tenant); |
|
|
|
var tenantConnectionStrings = tenant.ConnectionStrings |
|
|
|
.Select(x => x.Value) |
|
|
|
.ToList(); |
|
|
|
|
|
|
|
migratedDatabaseSchemas.AddIfNotContains(tenantConnectionStrings); |
|
|
|
} |
|
|
|
if (!migratedDatabaseSchemas.IsSupersetOf(tenantConnectionStrings)) |
|
|
|
{ |
|
|
|
await MigrateDatabaseSchemaAsync(tenant); |
|
|
|
|
|
|
|
await SeedDataAsync(tenant); |
|
|
|
migratedDatabaseSchemas.AddIfNotContains(tenantConnectionStrings); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
await SeedDataAsync(tenant); |
|
|
|
|
|
|
|
Logger.LogInformation($"Successfully completed {tenant.Name} tenant database migrations."); |
|
|
|
} |
|
|
|
|
|
|
|
@ -92,4 +90,4 @@ namespace MyCompanyName.MyProjectName.Data |
|
|
|
await _dataSeeder.SeedAsync(tenant?.Id); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|