Browse Source

Merge pull request #8022 from abpframework/issue/7983

app template: use template-remove for efcore related code in MyProjectNameDbMigrationService
pull/8037/head
liangshiwei 6 years ago
committed by GitHub
parent
commit
b13a2a3286
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/Steps/RemoveEfCoreRelatedCodeStep.cs
  2. 6
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Templates/App/AppTemplateBase.cs
  3. 55
      templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Domain/Data/MyProjectNameDbMigrationService.cs

2
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/Steps/RemoveEfCoreDependencyFromPublicStep.cs → framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/Steps/RemoveEfCoreRelatedCodeStep.cs

@ -3,7 +3,7 @@ using Volo.Abp.Cli.ProjectBuilding.Files;
namespace Volo.Abp.Cli.ProjectBuilding.Building.Steps namespace Volo.Abp.Cli.ProjectBuilding.Building.Steps
{ {
public class RemoveEfCoreDependencyFromPublicStep : ProjectBuildPipelineStep public class RemoveEfCoreRelatedCodeStep : ProjectBuildPipelineStep
{ {
public override void Execute(ProjectBuildContext context) public override void Execute(ProjectBuildContext context)
{ {

6
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Templates/App/AppTemplateBase.cs

@ -64,6 +64,7 @@ namespace Volo.Abp.Cli.ProjectBuilding.Templates.App
steps.Add(new RemoveProjectFromSolutionStep("MyCompanyName.MyProjectName.EntityFrameworkCore")); steps.Add(new RemoveProjectFromSolutionStep("MyCompanyName.MyProjectName.EntityFrameworkCore"));
steps.Add(new RemoveProjectFromSolutionStep("MyCompanyName.MyProjectName.EntityFrameworkCore.DbMigrations")); steps.Add(new RemoveProjectFromSolutionStep("MyCompanyName.MyProjectName.EntityFrameworkCore.DbMigrations"));
steps.Add(new RemoveProjectFromSolutionStep("MyCompanyName.MyProjectName.EntityFrameworkCore.Tests", projectFolderPath: "/aspnet-core/test/MyCompanyName.MyProjectName.EntityFrameworkCore.Tests")); steps.Add(new RemoveProjectFromSolutionStep("MyCompanyName.MyProjectName.EntityFrameworkCore.Tests", projectFolderPath: "/aspnet-core/test/MyCompanyName.MyProjectName.EntityFrameworkCore.Tests"));
steps.Add(new RemoveEfCoreRelatedCodeStep());
} }
if (context.BuildArgs.DatabaseProvider != DatabaseProvider.MongoDb) if (context.BuildArgs.DatabaseProvider != DatabaseProvider.MongoDb)
@ -154,11 +155,6 @@ namespace Volo.Abp.Cli.ProjectBuilding.Templates.App
steps.Add(new ChangePublicAuthPortStep()); steps.Add(new ChangePublicAuthPortStep());
} }
if (context.BuildArgs.DatabaseProvider != DatabaseProvider.NotSpecified && context.BuildArgs.DatabaseProvider != DatabaseProvider.EntityFrameworkCore)
{
steps.Add(new RemoveEfCoreDependencyFromPublicStep());
}
// We disabled cms-kit for v4.2 release. // We disabled cms-kit for v4.2 release.
if (true || context.BuildArgs.ExtraProperties.ContainsKey("without-cms-kit")) if (true || context.BuildArgs.ExtraProperties.ContainsKey("without-cms-kit"))
{ {

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

@ -40,18 +40,14 @@ namespace MyCompanyName.MyProjectName.Data
public async Task MigrateAsync() public async Task MigrateAsync()
{ {
try //<TEMPLATE-REMOVE IF-NOT='EFCORE'>
{ var initialMigrationAdded = AddInitialMigrationIfNotExist();
if (DbMigrationsProjectExists() && !MigrationsFolderExists())
{ if (initialMigrationAdded)
AddInitialMigration();
return;
}
}
catch (Exception e)
{ {
Logger.LogWarning("Couldn't determinate if any migrations exist : " + e.Message); return;
} }
//</TEMPLATE-REMOVE>
Logger.LogInformation("Started database migrations..."); Logger.LogInformation("Started database migrations...");
@ -112,6 +108,40 @@ namespace MyCompanyName.MyProjectName.Data
); );
} }
//<TEMPLATE-REMOVE IF-NOT='EFCORE'>
private bool AddInitialMigrationIfNotExist()
{
try
{
if (!DbMigrationsProjectExists())
{
return false;
}
}
catch (Exception)
{
return false;
}
try
{
if (!MigrationsFolderExists())
{
AddInitialMigration();
return true;
}
else
{
return false;
}
}
catch (Exception e)
{
Logger.LogWarning("Couldn't determinate if any migrations exist : " + e.Message);
return false;
}
}
private bool DbMigrationsProjectExists() private bool DbMigrationsProjectExists()
{ {
var dbMigrationsProjectFolder = GetDbMigrationsProjectFolderPath(); var dbMigrationsProjectFolder = GetDbMigrationsProjectFolderPath();
@ -123,7 +153,7 @@ namespace MyCompanyName.MyProjectName.Data
{ {
var dbMigrationsProjectFolder = GetDbMigrationsProjectFolderPath(); var dbMigrationsProjectFolder = GetDbMigrationsProjectFolderPath();
return Directory.Exists(Path.Combine(dbMigrationsProjectFolder, "migrations")); return Directory.Exists(Path.Combine(dbMigrationsProjectFolder, "Migrations"));
} }
private void AddInitialMigration() private void AddInitialMigration()
@ -144,7 +174,7 @@ namespace MyCompanyName.MyProjectName.Data
fileName = "cmd.exe"; fileName = "cmd.exe";
} }
var procStartInfo = new ProcessStartInfo( fileName, var procStartInfo = new ProcessStartInfo(fileName,
$"{argumentPrefix} \"abp create-migration-and-run-migrator \"{GetDbMigrationsProjectFolderPath()}\"\"" $"{argumentPrefix} \"abp create-migration-and-run-migrator \"{GetDbMigrationsProjectFolderPath()}\"\""
); );
@ -189,5 +219,6 @@ namespace MyCompanyName.MyProjectName.Data
return null; return null;
} }
//</TEMPLATE-REMOVE>
} }
} }

Loading…
Cancel
Save