Browse Source

Fix DbMigrator for mongodb

resolves https://github.com/abpframework/abp/issues/7242
pull/7244/head
Yunus Emre Kalkan 6 years ago
parent
commit
a71e460892
  1. 19
      templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Domain/Data/MyProjectNameDbMigrationService.cs

19
templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Domain/Data/MyProjectNameDbMigrationService.cs

@ -41,9 +41,9 @@ namespace MyCompanyName.MyProjectName.Data
{ {
try try
{ {
if (!await MigrationsFolderExists()) if (await DbMigrationsProjectExistsAsync() && !await MigrationsFolderExistsAsync())
{ {
await AddInitialMigration(); await AddInitialMigrationAsync();
return; return;
} }
} }
@ -108,14 +108,21 @@ namespace MyCompanyName.MyProjectName.Data
await _dataSeeder.SeedAsync(tenant?.Id); await _dataSeeder.SeedAsync(tenant?.Id);
} }
private async Task<bool> MigrationsFolderExists() private async Task<bool> DbMigrationsProjectExistsAsync()
{
var dbMigrationsProjectFolder = GetDbMigrationsProjectFolderPath();
return dbMigrationsProjectFolder != null;
}
private async Task<bool> MigrationsFolderExistsAsync()
{ {
var dbMigrationsProjectFolder = GetDbMigrationsProjectFolderPath(); var dbMigrationsProjectFolder = GetDbMigrationsProjectFolderPath();
return Directory.Exists(Path.Combine(dbMigrationsProjectFolder, "migrations")); return Directory.Exists(Path.Combine(dbMigrationsProjectFolder, "migrations"));
} }
private async Task AddInitialMigration() private async Task AddInitialMigrationAsync()
{ {
Logger.LogInformation("Creating initial migration..."); Logger.LogInformation("Creating initial migration...");
@ -147,7 +154,7 @@ namespace MyCompanyName.MyProjectName.Data
} }
} }
private static string GetDbMigrationsProjectFolderPath() private string GetDbMigrationsProjectFolderPath()
{ {
var slnDirectoryPath = GetSolutionDirectoryPath(); var slnDirectoryPath = GetSolutionDirectoryPath();
@ -162,7 +169,7 @@ namespace MyCompanyName.MyProjectName.Data
.FirstOrDefault(d => d.EndsWith(".DbMigrations")); .FirstOrDefault(d => d.EndsWith(".DbMigrations"));
} }
private static string GetSolutionDirectoryPath() private string GetSolutionDirectoryPath()
{ {
var currentDirectory = new DirectoryInfo(Directory.GetCurrentDirectory()); var currentDirectory = new DirectoryInfo(Directory.GetCurrentDirectory());

Loading…
Cancel
Save