Browse Source

DatabaseManagementSystemChangeStep improvements & remove connection string requirement

pull/6737/head
Yunus Emre Kalkan 6 years ago
parent
commit
a8be0b7611
  1. 11
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/NewCommand.cs
  2. 22
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/Steps/DatabaseManagementSystemChangeStep.cs
  3. 2
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/EfCoreMigrationRecreater.cs

11
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/NewCommand.cs

@ -101,13 +101,6 @@ namespace Volo.Abp.Cli.Commands
Logger.LogInformation("DBMS: " + databaseManagementSystem); Logger.LogInformation("DBMS: " + databaseManagementSystem);
} }
if (databaseManagementSystem != DatabaseManagementSystem.NotSpecified
&& databaseManagementSystem != DatabaseManagementSystem.SQLServer
&& connectionString == null)
{
throw new CliUsageException($"Connection string must be set if a Database Management System other than SQLServer is set. Use \"--{Options.ConnectionString.Long}\" parameter to set connection string");
}
var uiFramework = GetUiFramework(commandLineArgs); var uiFramework = GetUiFramework(commandLineArgs);
if (uiFramework != UiFramework.NotSpecified) if (uiFramework != UiFramework.NotSpecified)
{ {
@ -305,7 +298,7 @@ namespace Volo.Abp.Cli.Commands
sb.AppendLine("-ts|--template-source <template-source> (your local or network abp template source)"); sb.AppendLine("-ts|--template-source <template-source> (your local or network abp template source)");
sb.AppendLine("-csf|--create-solution-folder (default: true)"); sb.AppendLine("-csf|--create-solution-folder (default: true)");
sb.AppendLine("-cs|--connection-string <connection-string> (your database connection string)"); sb.AppendLine("-cs|--connection-string <connection-string> (your database connection string)");
sb.AppendLine("--dbms <database-management-system> (your database management system. Requires --connection-string to be set)"); sb.AppendLine("--dbms <database-management-system> (your database management system)");
sb.AppendLine("--tiered (if supported by the template)"); sb.AppendLine("--tiered (if supported by the template)");
sb.AppendLine("--no-ui (if supported by the template)"); sb.AppendLine("--no-ui (if supported by the template)");
sb.AppendLine("--no-random-port (Use template's default ports)"); sb.AppendLine("--no-random-port (Use template's default ports)");
@ -328,7 +321,7 @@ namespace Volo.Abp.Cli.Commands
sb.AppendLine(" abp new Acme.BookStore -ts \"D:\\localTemplate\\abp\""); sb.AppendLine(" abp new Acme.BookStore -ts \"D:\\localTemplate\\abp\"");
sb.AppendLine(" abp new Acme.BookStore -csf false"); sb.AppendLine(" abp new Acme.BookStore -csf false");
sb.AppendLine(" abp new Acme.BookStore --local-framework-ref --abp-path \"D:\\github\\abp\""); sb.AppendLine(" abp new Acme.BookStore --local-framework-ref --abp-path \"D:\\github\\abp\"");
sb.AppendLine(" abp new Acme.BookStore --dbms mysql --connection-string \"Server=myServerName\\myInstanceName;Database=myDatabase;User Id=myUsername;Password=myPassword\""); sb.AppendLine(" abp new Acme.BookStore --dbms mysql");
sb.AppendLine(" abp new Acme.BookStore --connection-string \"Server=myServerName\\myInstanceName;Database=myDatabase;User Id=myUsername;Password=myPassword\""); sb.AppendLine(" abp new Acme.BookStore --connection-string \"Server=myServerName\\myInstanceName;Database=myDatabase;User Id=myUsername;Password=myPassword\"");
sb.AppendLine(""); sb.AppendLine("");
sb.AppendLine("See the documentation for more info: https://docs.abp.io/en/abp/latest/CLI"); sb.AppendLine("See the documentation for more info: https://docs.abp.io/en/abp/latest/CLI");

22
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/Steps/DatabaseManagementSystemChangeStep.cs

@ -14,7 +14,8 @@ namespace Volo.Abp.Cli.ProjectBuilding.Building.Steps
ChangeEntityFrameworkCoreDependency(context,"Volo.Abp.EntityFrameworkCore.MySQL", ChangeEntityFrameworkCoreDependency(context,"Volo.Abp.EntityFrameworkCore.MySQL",
"Volo.Abp.EntityFrameworkCore.MySQL", "Volo.Abp.EntityFrameworkCore.MySQL",
"AbpEntityFrameworkCoreMySQLModule"); "AbpEntityFrameworkCoreMySQLModule");
ChangeUseSqlServer(context,"UseMySql"); AddMySqlServerVersion(context);
ChangeUseSqlServer(context,"UseMySQL", "UseMySql");
break; break;
case DatabaseManagementSystem.PostgreSQL: case DatabaseManagementSystem.PostgreSQL:
@ -50,6 +51,14 @@ namespace Volo.Abp.Cli.ProjectBuilding.Building.Steps
} }
} }
private void AddMySqlServerVersion(ProjectBuildContext context)
{
var dbContextFactoryFile = context.Files.First(f => f.Name.EndsWith("MigrationsDbContextFactory.cs", StringComparison.OrdinalIgnoreCase));
dbContextFactoryFile.ReplaceText("configuration.GetConnectionString(\"Default\")",
"configuration.GetConnectionString(\"Default\"), MySqlServerVersion.LatestSupportedServerVersion");
}
private void ChangeEntityFrameworkCoreDependency(ProjectBuildContext context, string newPackageName, string newModuleNamespace, string newModuleClass) private void ChangeEntityFrameworkCoreDependency(ProjectBuildContext context, string newPackageName, string newModuleNamespace, string newModuleClass)
{ {
var efCoreProjectFile = context.Files.First(f => f.Name.EndsWith("EntityFrameworkCore.csproj", StringComparison.OrdinalIgnoreCase)); var efCoreProjectFile = context.Files.First(f => f.Name.EndsWith("EntityFrameworkCore.csproj", StringComparison.OrdinalIgnoreCase));
@ -60,15 +69,20 @@ namespace Volo.Abp.Cli.ProjectBuilding.Building.Steps
efCoreModuleClass.ReplaceText("AbpEntityFrameworkCoreSqlServerModule", newModuleClass); efCoreModuleClass.ReplaceText("AbpEntityFrameworkCoreSqlServerModule", newModuleClass);
} }
private void ChangeUseSqlServer(ProjectBuildContext context, string newUseMethod) private void ChangeUseSqlServer(ProjectBuildContext context, string newUseMethodForEfModule, string newUseMethodForDbContext = null)
{ {
if (newUseMethodForDbContext == null)
{
newUseMethodForDbContext = newUseMethodForEfModule;
}
var oldUseMethod = "UseSqlServer"; var oldUseMethod = "UseSqlServer";
var efCoreModuleClass = context.Files.First(f => f.Name.EndsWith("EntityFrameworkCoreModule.cs", StringComparison.OrdinalIgnoreCase)); var efCoreModuleClass = context.Files.First(f => f.Name.EndsWith("EntityFrameworkCoreModule.cs", StringComparison.OrdinalIgnoreCase));
efCoreModuleClass.ReplaceText(oldUseMethod, newUseMethod); efCoreModuleClass.ReplaceText(oldUseMethod, newUseMethodForEfModule);
var dbContextFactoryFile = context.Files.First(f => f.Name.EndsWith("MigrationsDbContextFactory.cs", StringComparison.OrdinalIgnoreCase)); var dbContextFactoryFile = context.Files.First(f => f.Name.EndsWith("MigrationsDbContextFactory.cs", StringComparison.OrdinalIgnoreCase));
dbContextFactoryFile.ReplaceText(oldUseMethod, newUseMethod); dbContextFactoryFile.ReplaceText(oldUseMethod, newUseMethodForDbContext);
} }
} }
} }

2
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/EfCoreMigrationRecreater.cs

@ -38,7 +38,7 @@ namespace Volo.Abp.Cli.ProjectModification
} }
catch (Exception e) catch (Exception e)
{ {
Logger.LogWarning($"\"Re-creating migrations process failed."); Logger.LogWarning("Re-creating migrations process failed.");
throw e; throw e;
} }
} }

Loading…
Cancel
Save