Browse Source

Merge pull request #24692 from abpframework/auto-merge/rel-10-1/4296

Merge branch dev with rel-10.1
pull/24694/head
Ma Liming 2 weeks ago
committed by GitHub
parent
commit
2bb92d30f3
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 8
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/Internal/RecreateInitialMigrationCommand.cs
  2. 16
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/Services/InitialMigrationCreator.cs
  3. 9
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/EfCoreMigrationManager.cs

8
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/Internal/RecreateInitialMigrationCommand.cs

@ -54,6 +54,14 @@ public class RecreateInitialMigrationCommand : IConsoleCommand, ITransientDepend
Directory.Delete(Path.Combine(projectDir, "TenantMigrations"), true);
separateDbContext = true;
}
CmdHelper.RunCmd("dotnet build", workingDirectory: projectDir, exitCode: out var exitCode);
if (exitCode != 0)
{
Logger.LogError("Build failed for project {Project}. Skipping migration recreation.", csprojFile);
continue;
}
if (!separateDbContext)
{
CmdHelper.RunCmd($"dotnet ef migrations add Initial", workingDirectory: projectDir);

16
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/Services/InitialMigrationCreator.cs

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

9
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/EfCoreMigrationManager.cs

@ -44,13 +44,20 @@ public class EfCoreMigrationManager : ITransientDependency
string dbContext,
string outputDirectory)
{
CmdHelper.RunCmd($"dotnet build", workingDirectory: dbMigrationsProjectFolder, exitCode: out var buildExitCode);
if (buildExitCode != 0)
{
Logger.LogWarning("Dotnet build failed for project folder {ProjectFolder}. Skipping EF Core migration command.", dbMigrationsProjectFolder);
return;
}
var dbContextOption = string.IsNullOrWhiteSpace(dbContext)
? string.Empty
: $"--context {dbContext}";
CmdHelper.RunCmd($"dotnet ef migrations add {migrationName}" +
$" --output-dir {outputDirectory}" +
$" {dbContextOption}",
$" {dbContextOption}",
workingDirectory: dbMigrationsProjectFolder);
}

Loading…
Cancel
Save