diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/NewCommand.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/NewCommand.cs index c3b9302d3b..0fd3360f15 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/NewCommand.cs +++ b/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); } - 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); if (uiFramework != UiFramework.NotSpecified) { @@ -305,7 +298,7 @@ namespace Volo.Abp.Cli.Commands sb.AppendLine("-ts|--template-source (your local or network abp template source)"); sb.AppendLine("-csf|--create-solution-folder (default: true)"); sb.AppendLine("-cs|--connection-string (your database connection string)"); - sb.AppendLine("--dbms (your database management system. Requires --connection-string to be set)"); + sb.AppendLine("--dbms (your database management system)"); sb.AppendLine("--tiered (if supported by the template)"); sb.AppendLine("--no-ui (if supported by the template)"); 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 -csf false"); 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(""); sb.AppendLine("See the documentation for more info: https://docs.abp.io/en/abp/latest/CLI"); diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/Steps/DatabaseManagementSystemChangeStep.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/Steps/DatabaseManagementSystemChangeStep.cs index f0f7c12872..f215d37954 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/Steps/DatabaseManagementSystemChangeStep.cs +++ b/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", "Volo.Abp.EntityFrameworkCore.MySQL", "AbpEntityFrameworkCoreMySQLModule"); - ChangeUseSqlServer(context,"UseMySql"); + AddMySqlServerVersion(context); + ChangeUseSqlServer(context,"UseMySQL", "UseMySql"); break; 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) { 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); } - 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 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)); - dbContextFactoryFile.ReplaceText(oldUseMethod, newUseMethod); + dbContextFactoryFile.ReplaceText(oldUseMethod, newUseMethodForDbContext); } } } diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/EfCoreMigrationRecreater.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/EfCoreMigrationRecreater.cs index 1f9dc7d93d..3abdaf9392 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/EfCoreMigrationRecreater.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/EfCoreMigrationRecreater.cs @@ -38,7 +38,7 @@ namespace Volo.Abp.Cli.ProjectModification } catch (Exception e) { - Logger.LogWarning($"\"Re-creating migrations process failed."); + Logger.LogWarning("Re-creating migrations process failed."); throw e; } }