|
|
@ -14,7 +14,7 @@ public class InitialMigrationCreator : ITransientDependency |
|
|
public ICmdHelper CmdHelper { get; } |
|
|
public ICmdHelper CmdHelper { get; } |
|
|
public DotnetEfToolManager DotnetEfToolManager { get; } |
|
|
public DotnetEfToolManager DotnetEfToolManager { get; } |
|
|
public ILogger<InitialMigrationCreator> Logger { get; set; } |
|
|
public ILogger<InitialMigrationCreator> Logger { get; set; } |
|
|
|
|
|
|
|
|
public InitialMigrationCreator(ICmdHelper cmdHelper, DotnetEfToolManager dotnetEfToolManager) |
|
|
public InitialMigrationCreator(ICmdHelper cmdHelper, DotnetEfToolManager dotnetEfToolManager) |
|
|
{ |
|
|
{ |
|
|
CmdHelper = cmdHelper; |
|
|
CmdHelper = cmdHelper; |
|
|
@ -30,11 +30,11 @@ public class InitialMigrationCreator : ITransientDependency |
|
|
Logger.LogError($"This path doesn't exist: {targetProjectFolder}"); |
|
|
Logger.LogError($"This path doesn't exist: {targetProjectFolder}"); |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
Logger.LogInformation("Creating initial migrations..."); |
|
|
Logger.LogInformation("Creating initial migrations..."); |
|
|
|
|
|
|
|
|
await DotnetEfToolManager.BeSureInstalledAsync(); |
|
|
await DotnetEfToolManager.BeSureInstalledAsync(); |
|
|
|
|
|
|
|
|
var tenantDbContextName = FindTenantDbContextName(targetProjectFolder); |
|
|
var tenantDbContextName = FindTenantDbContextName(targetProjectFolder); |
|
|
var dbContextName = tenantDbContextName != null ? |
|
|
var dbContextName = tenantDbContextName != null ? |
|
|
FindDbContextName(targetProjectFolder) |
|
|
FindDbContextName(targetProjectFolder) |
|
|
@ -60,7 +60,7 @@ public class InitialMigrationCreator : ITransientDependency |
|
|
|
|
|
|
|
|
return migrationSuccess; |
|
|
return migrationSuccess; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private string FindTenantDbContextName(string projectFolder) |
|
|
private string FindTenantDbContextName(string projectFolder) |
|
|
{ |
|
|
{ |
|
|
var tenantDbContext = Directory.GetFiles(projectFolder, "*TenantMigrationsDbContext.cs", SearchOption.AllDirectories) |
|
|
var tenantDbContext = Directory.GetFiles(projectFolder, "*TenantMigrationsDbContext.cs", SearchOption.AllDirectories) |
|
|
@ -93,6 +93,12 @@ public class InitialMigrationCreator : ITransientDependency |
|
|
|
|
|
|
|
|
private string AddMigrationAndGetOutput(string dbMigrationsFolder, string dbContext, string outputDirectory) |
|
|
private string AddMigrationAndGetOutput(string dbMigrationsFolder, string dbContext, string outputDirectory) |
|
|
{ |
|
|
{ |
|
|
|
|
|
var output = CmdHelper.RunCmdAndGetOutput("dotnet build", out int buildExitCode, dbMigrationsFolder); |
|
|
|
|
|
if (buildExitCode != 0) |
|
|
|
|
|
{ |
|
|
|
|
|
return output; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
var dbContextOption = string.IsNullOrWhiteSpace(dbContext) |
|
|
var dbContextOption = string.IsNullOrWhiteSpace(dbContext) |
|
|
? string.Empty |
|
|
? string.Empty |
|
|
: $"--context {dbContext}"; |
|
|
: $"--context {dbContext}"; |
|
|
@ -108,4 +114,4 @@ public class InitialMigrationCreator : ITransientDependency |
|
|
output.Contains("To undo this action") && |
|
|
output.Contains("To undo this action") && |
|
|
output.Contains("ef migrations remove")); |
|
|
output.Contains("ef migrations remove")); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|