From 3badda83202146e27c25f4f3fecc116195f9b0d2 Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Fri, 15 Jan 2021 17:10:00 +0800 Subject: [PATCH 01/11] Remove the redis connection string when the public website option is not specified --- .../ProjectBuilding/Building/Steps/RemovePublicRedisStep.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/Steps/RemovePublicRedisStep.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/Steps/RemovePublicRedisStep.cs index 94056cbf5a..4ac2acb50e 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/Steps/RemovePublicRedisStep.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/Steps/RemovePublicRedisStep.cs @@ -1,4 +1,6 @@ -using System.Linq; +using System; +using System.Linq; +using NUglify.Helpers; using Volo.Abp.Cli.ProjectBuilding.Files; namespace Volo.Abp.Cli.ProjectBuilding.Building.Steps @@ -12,6 +14,7 @@ namespace Volo.Abp.Cli.ProjectBuilding.Building.Steps context.Files.FirstOrDefault(f => f.Name.EndsWith("MyCompanyName.MyProjectName.HttpApi.HostWithIds.csproj"))?.RemoveTemplateCodeIfNot("PUBLIC-REDIS"); context.Files.FirstOrDefault(f => f.Name.EndsWith("MyCompanyName.MyProjectName.HttpApi.Host.csproj"))?.RemoveTemplateCodeIfNot("PUBLIC-REDIS"); context.Files.FirstOrDefault(f => f.Name.EndsWith("MyProjectNameHttpApiHostModule.cs"))?.RemoveTemplateCodeIfNot("PUBLIC-REDIS"); + context.Files.Where(f => f.Name.EndsWith("appSettings.json", StringComparison.InvariantCultureIgnoreCase)).ForEach(x => x.RemoveTemplateCodeIfNot("PUBLIC-REDIS")); } } } From 572d8bdbfa01cf6775861bec4f7d6fd6f534d091 Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Fri, 15 Jan 2021 17:13:23 +0800 Subject: [PATCH 02/11] Update RemovePublicRedisStep --- .../Building/Steps/RemovePublicRedisStep.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/Steps/RemovePublicRedisStep.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/Steps/RemovePublicRedisStep.cs index 4ac2acb50e..1299f5b15d 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/Steps/RemovePublicRedisStep.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/Steps/RemovePublicRedisStep.cs @@ -1,6 +1,5 @@ using System; using System.Linq; -using NUglify.Helpers; using Volo.Abp.Cli.ProjectBuilding.Files; namespace Volo.Abp.Cli.ProjectBuilding.Building.Steps @@ -14,7 +13,12 @@ namespace Volo.Abp.Cli.ProjectBuilding.Building.Steps context.Files.FirstOrDefault(f => f.Name.EndsWith("MyCompanyName.MyProjectName.HttpApi.HostWithIds.csproj"))?.RemoveTemplateCodeIfNot("PUBLIC-REDIS"); context.Files.FirstOrDefault(f => f.Name.EndsWith("MyCompanyName.MyProjectName.HttpApi.Host.csproj"))?.RemoveTemplateCodeIfNot("PUBLIC-REDIS"); context.Files.FirstOrDefault(f => f.Name.EndsWith("MyProjectNameHttpApiHostModule.cs"))?.RemoveTemplateCodeIfNot("PUBLIC-REDIS"); - context.Files.Where(f => f.Name.EndsWith("appSettings.json", StringComparison.InvariantCultureIgnoreCase)).ForEach(x => x.RemoveTemplateCodeIfNot("PUBLIC-REDIS")); + + var appSettingsFiles = context.Files.Where(f => f.Name.EndsWith("appSettings.json", StringComparison.InvariantCultureIgnoreCase)).ToList(); + foreach (var appSettings in appSettingsFiles) + { + appSettings.RemoveTemplateCodeIfNot("PUBLIC-REDIS"); + } } } } From 1f4f9e33fe059c402fd6936835e88d4481b6e84d Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Fri, 15 Jan 2021 15:53:18 +0300 Subject: [PATCH 03/11] Cli: RunRemoveMigrations step before CleanupFolderHierarchy --- .../Abp/Cli/ProjectBuilding/Templates/App/AppTemplateBase.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Templates/App/AppTemplateBase.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Templates/App/AppTemplateBase.cs index 9a32caf378..65ec6d14ad 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Templates/App/AppTemplateBase.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Templates/App/AppTemplateBase.cs @@ -26,13 +26,13 @@ namespace Volo.Abp.Cli.ProjectBuilding.Templates.App SwitchDatabaseProvider(context, steps); DeleteUnrelatedProjects(context, steps); + RemoveMigrations(context, steps); ConfigurePublicWebSite(context, steps); RemoveUnnecessaryPorts(context, steps); RandomizeSslPorts(context, steps); RandomizeStringEncryption(context, steps); UpdateNuGetConfig(context, steps); CleanupFolderHierarchy(context, steps); - RemoveMigrations(context, steps); return steps; } From ba74464d0551d5ae3ee7f77b5fd24ee7a8a0c4ba Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Fri, 15 Jan 2021 21:40:54 +0800 Subject: [PATCH 04/11] Update TemplateCodeDeleteStep --- .../ProjectBuilding/Building/Steps/TemplateCodeDeleteStep.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/Steps/TemplateCodeDeleteStep.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/Steps/TemplateCodeDeleteStep.cs index 8942103873..8f17b90702 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/Steps/TemplateCodeDeleteStep.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/Steps/TemplateCodeDeleteStep.cs @@ -8,7 +8,7 @@ namespace Volo.Abp.Cli.ProjectBuilding.Building.Steps { foreach (var file in context.Files) { - if (file.Name.EndsWith(".cs") || file.Name.EndsWith(".csproj") || file.Name.EndsWith(".cshtml")) + if (file.Name.EndsWith(".cs") || file.Name.EndsWith(".csproj") || file.Name.EndsWith(".cshtml") || file.Name.EndsWith(".json")) { file.RemoveTemplateCode(); file.RemoveTemplateCodeMarkers(); From 2ee213b7add993c6f40951267a35573877571a02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Fri, 15 Jan 2021 17:49:50 +0300 Subject: [PATCH 05/11] Update Index.md --- docs/en/Samples/Index.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/en/Samples/Index.md b/docs/en/Samples/Index.md index b5dd0fab29..18312e4b55 100644 --- a/docs/en/Samples/Index.md +++ b/docs/en/Samples/Index.md @@ -17,6 +17,9 @@ A simple CRUD application to show basic principles of developing an application * **Book Store: Razor Pages UI & Entity Framework Core** * [Tutorial](https://docs.abp.io/en/abp/latest/Tutorials/Part-1?UI=MVC&DB=EF) * [Source code](https://github.com/abpframework/abp-samples/tree/master/BookStore-Mvc-EfCore) +* **Book Store: Blazor UI & Entity Framework Core** + * [Tutorial](https://docs.abp.io/en/abp/latest/Tutorials/Part-1?UI=Blazor&DB=EF) + * [Source code](https://github.com/abpframework/abp-samples/tree/master/BookStore-Blazor-EfCore) * **Book Store: Angular UI & MongoDB** * [Tutorial](https://docs.abp.io/en/abp/latest/Tutorials/Part-1?UI=NG&DB=Mongo) * [Source code](https://github.com/abpframework/abp-samples/tree/master/BookStore-Angular-MongoDb) From 654efac9f5c0ccb8ea2e70b04eaf0e28ec196785 Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Fri, 15 Jan 2021 18:14:18 +0300 Subject: [PATCH 06/11] Cli: Remove `DeleteMigrationsIfNeeded` method since migrations are already removed resolves https://github.com/abpframework/abp/issues/7270 --- .../Volo/Abp/Cli/Commands/NewCommand.cs | 19 ---------------- .../EfCoreMigrationManager.cs | 22 ------------------- 2 files changed, 41 deletions(-) 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 55247c71bb..9caa952528 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 @@ -226,8 +226,6 @@ namespace Volo.Abp.Cli.Commands } } - DeleteMigrationsIfNeeded(databaseProvider, databaseManagementSystem, outputFolder); - Logger.LogInformation($"'{projectName}' has been successfully created to '{outputFolder}'"); @@ -256,23 +254,6 @@ namespace Volo.Abp.Cli.Commands } } - private void DeleteMigrationsIfNeeded(DatabaseProvider databaseProvider, DatabaseManagementSystem databaseManagementSystem, string outputFolder) - { - if (databaseManagementSystem == DatabaseManagementSystem.NotSpecified || databaseManagementSystem == DatabaseManagementSystem.SQLServer) - { - return; - } - - if (databaseProvider != DatabaseProvider.NotSpecified && databaseProvider != DatabaseProvider.EntityFrameworkCore) - { - return; - } - - Logger.LogInformation($"Deleting migrations..."); - - _efCoreMigrationManager.RemoveAllMigrations(outputFolder); - } - private void OpenThanksPage(UiFramework uiFramework, DatabaseProvider databaseProvider, bool tiered, bool commercial) { uiFramework = uiFramework == UiFramework.NotSpecified || uiFramework == UiFramework.None ? UiFramework.Mvc : uiFramework; diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/EfCoreMigrationManager.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/EfCoreMigrationManager.cs index b26ca1be90..b15ffaa274 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/EfCoreMigrationManager.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/EfCoreMigrationManager.cs @@ -27,28 +27,6 @@ namespace Volo.Abp.Cli.ProjectModification GetStartupProjectOption(startupProject)); } - public void RemoveAllMigrations(string solutionFolder) - { - if (Directory.Exists(Path.Combine(solutionFolder, "aspnet-core"))) - { - solutionFolder = Path.Combine(solutionFolder, "aspnet-core"); - } - - var srcFolder = Path.Combine(solutionFolder, "src"); - - var migrationsFolder = Directory.GetDirectories(srcFolder) - .FirstOrDefault(d => d.EndsWith(".EntityFrameworkCore.DbMigrations")); - - if (migrationsFolder != null) - { - Directory.Delete(Path.Combine(migrationsFolder, "Migrations"), true); - } - else - { - Logger.LogWarning("No migration found to delete."); - } - } - protected virtual string ParseModuleName(string fullModuleName) { var words = fullModuleName?.Split('.'); From 793f98b2d3de4fe770c1a10e824dc3fc790e09b6 Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Sat, 16 Jan 2021 13:49:23 +0300 Subject: [PATCH 07/11] cli: move connectionstring step to customs --- .../Building/TemplateProjectBuildPipelineBuilder.cs | 6 ------ .../Cli/ProjectBuilding/Templates/App/AppTemplateBase.cs | 9 +++++++++ .../Templates/Module/ModuleTemplateBase.cs | 9 +++++++++ 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/TemplateProjectBuildPipelineBuilder.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/TemplateProjectBuildPipelineBuilder.cs index 7642a7d697..8b7cfeb440 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/TemplateProjectBuildPipelineBuilder.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/TemplateProjectBuildPipelineBuilder.cs @@ -17,12 +17,6 @@ namespace Volo.Abp.Cli.ProjectBuilding.Building pipeline.Steps.Add(new ProjectReferenceReplaceStep()); pipeline.Steps.Add(new TemplateCodeDeleteStep()); - - if (context.BuildArgs.ConnectionString != null) - { - pipeline.Steps.Add(new ConnectionStringChangeStep()); - } - pipeline.Steps.Add(new SolutionRenameStep()); if (context.Template.Name == AppProTemplate.TemplateName || diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Templates/App/AppTemplateBase.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Templates/App/AppTemplateBase.cs index 65ec6d14ad..99625d830f 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Templates/App/AppTemplateBase.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Templates/App/AppTemplateBase.cs @@ -32,6 +32,7 @@ namespace Volo.Abp.Cli.ProjectBuilding.Templates.App RandomizeSslPorts(context, steps); RandomizeStringEncryption(context, steps); UpdateNuGetConfig(context, steps); + ChangeConnectionString(context, steps); CleanupFolderHierarchy(context, steps); return steps; @@ -286,6 +287,14 @@ namespace Volo.Abp.Cli.ProjectBuilding.Templates.App } } + private static void ChangeConnectionString(ProjectBuildContext context, List steps) + { + if (context.BuildArgs.ConnectionString != null) + { + steps.Add(new ConnectionStringChangeStep()); + } + } + private static void CleanupFolderHierarchy(ProjectBuildContext context, List steps) { if (context.BuildArgs.UiFramework == UiFramework.Mvc && context.BuildArgs.MobileApp == MobileApp.None) diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Templates/Module/ModuleTemplateBase.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Templates/Module/ModuleTemplateBase.cs index ef8385d479..69ec43e276 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Templates/Module/ModuleTemplateBase.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Templates/Module/ModuleTemplateBase.cs @@ -19,6 +19,7 @@ namespace Volo.Abp.Cli.ProjectBuilding.Templates.Module DeleteUnrelatedProjects(context, steps); RandomizeSslPorts(context, steps); UpdateNuGetConfig(context, steps); + ChangeConnectionString(context, steps); CleanupFolderHierarchy(context, steps); return steps; @@ -78,6 +79,14 @@ namespace Volo.Abp.Cli.ProjectBuilding.Templates.Module steps.Add(new UpdateNuGetConfigStep("/aspnet-core/NuGet.Config")); } + private static void ChangeConnectionString(ProjectBuildContext context, List steps) + { + if (context.BuildArgs.ConnectionString != null) + { + steps.Add(new ConnectionStringChangeStep()); + } + } + private void CleanupFolderHierarchy(ProjectBuildContext context, List steps) { steps.Add(new MoveFolderStep("/aspnet-core/", "/")); From d8830a5c2778a6b1ddada1b5156109ee28005d53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Sat, 16 Jan 2021 13:59:05 +0300 Subject: [PATCH 08/11] Fix removed projects. --- .../Templates/Microservice/MicroserviceTemplateBase.cs | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Templates/Microservice/MicroserviceTemplateBase.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Templates/Microservice/MicroserviceTemplateBase.cs index 13bfe3433e..a9ffccd142 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Templates/Microservice/MicroserviceTemplateBase.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Templates/Microservice/MicroserviceTemplateBase.cs @@ -29,21 +29,17 @@ namespace Volo.Abp.Cli.ProjectBuilding.Templates.Microservice { case UiFramework.None: steps.Add(new RemoveProjectFromSolutionStep("MyCompanyName.MyProjectName.Web")); - steps.Add(new RemoveProjectFromSolutionStep("MyCompanyName.MyProjectName.WebGateway")); steps.Add(new RemoveProjectFromSolutionStep("MyCompanyName.MyProjectName.Blazor")); steps.Add(new RemoveFolderStep("/angular")); break; case UiFramework.Angular: steps.Add(new RemoveProjectFromSolutionStep("MyCompanyName.MyProjectName.Web")); - steps.Add(new RemoveProjectFromSolutionStep("MyCompanyName.MyProjectName.WebGateway")); steps.Add(new RemoveProjectFromSolutionStep("MyCompanyName.MyProjectName.Blazor")); break; - case UiFramework.Blazor: steps.Add(new RemoveProjectFromSolutionStep("MyCompanyName.MyProjectName.Web")); - steps.Add(new RemoveProjectFromSolutionStep("MyCompanyName.MyProjectName.WebGateway")); steps.Add(new RemoveFolderStep("/angular")); break; @@ -53,12 +49,6 @@ namespace Volo.Abp.Cli.ProjectBuilding.Templates.Microservice steps.Add(new RemoveFolderStep("/angular")); break; } - - if (!context.BuildArgs.PublicWebSite) - { - steps.Add(new RemoveProjectFromSolutionStep("MyCompanyName.MyProjectName.PublicWeb")); - steps.Add(new RemoveProjectFromSolutionStep("MyCompanyName.MyProjectName.PublicWebGateway")); - } } private static void RandomizeStringEncryption(ProjectBuildContext context, List steps) From 7f366449b30cda5a616796f6c05f9fe2a5a6bd55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Sat, 16 Jan 2021 19:31:47 +0300 Subject: [PATCH 09/11] Update MyCompanyName.MyProjectName.DbMigrator.csproj --- .../MyCompanyName.MyProjectName.DbMigrator.csproj | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.DbMigrator/MyCompanyName.MyProjectName.DbMigrator.csproj b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.DbMigrator/MyCompanyName.MyProjectName.DbMigrator.csproj index 6bf2650ea9..fd96bfd920 100644 --- a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.DbMigrator/MyCompanyName.MyProjectName.DbMigrator.csproj +++ b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.DbMigrator/MyCompanyName.MyProjectName.DbMigrator.csproj @@ -31,5 +31,12 @@ + + + + + + + From 1a8e59cbced8831d9b4734c0d2359a8c18a855f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Sun, 17 Jan 2021 12:36:07 +0300 Subject: [PATCH 10/11] Update Getting-Started-Running-Solution.md --- docs/en/Getting-Started-Running-Solution.md | 50 ++++++++------------- 1 file changed, 19 insertions(+), 31 deletions(-) diff --git a/docs/en/Getting-Started-Running-Solution.md b/docs/en/Getting-Started-Running-Solution.md index d1f02c887b..92c9a4b2a7 100644 --- a/docs/en/Getting-Started-Running-Solution.md +++ b/docs/en/Getting-Started-Running-Solution.md @@ -25,53 +25,41 @@ Check the **connection string** in the `appsettings.json` file under the {{if Ti } ```` -The solution is configured to use **Entity Framework Core** with **MS SQL Server** by default. EF Core supports [various](https://docs.microsoft.com/en-us/ef/core/providers/) database providers, so you can use any supported DBMS. See [the Entity Framework integration document](Entity-Framework-Core.md) to learn how to [switch to another DBMS](Entity-Framework-Core-Other-DBMS.md). - -### Apply the Migrations - -The solution uses the [Entity Framework Core Code First Migrations](https://docs.microsoft.com/en-us/ef/core/managing-schemas/migrations/?tabs=dotnet-core-cli). So, you need to apply migrations to create the database. There are two ways of applying the database migrations. +> **About the Connection Strings and Database Management Systems** +> +> The solution is configured to use **Entity Framework Core** with **MS SQL Server** by default. However, if you've selected another DBMS using the `-dbms` parameter on the ABP CLI `new` command (like `-dbms MySQL`), the connection string might be different for you. +> +> EF Core supports [various](https://docs.microsoft.com/en-us/ef/core/providers/) database providers and you can use any supported DBMS. See [the Entity Framework integration document](Entity-Framework-Core.md) to learn how to [switch to another DBMS](Entity-Framework-Core-Other-DBMS.md) if you need later. -#### Apply Migrations Using the DbMigrator +### Database Migrations -The solution comes with a `.DbMigrator` console application which applies migrations and also **seeds the initial data**. It is useful on **development** as well as on **production** environment. +The solution uses the [Entity Framework Core Code First Migrations](https://docs.microsoft.com/en-us/ef/core/managing-schemas/migrations/?tabs=dotnet-core-cli). It comes with a `.DbMigrator` console application which **applies the migrations** and also **seeds the initial data**. It is useful on **development** as well as on **production** environment. > `.DbMigrator` project has its own `appsettings.json`. So, if you have changed the connection string above, you should also change this one. -Right click to the `.DbMigrator` project and select **Set as StartUp Project** - -![set-as-startup-project](images/set-as-startup-project.png) - - Hit F5 (or Ctrl+F5) to run the application. It will have an output like shown below: +### The Initial Migration - ![db-migrator-output](images/db-migrator-output.png) - -> Initial [seed data](Data-Seeding.md) creates the `admin` user in the database (with the password is `1q2w3E*`) which is then used to login to the application. So, you need to use `.DbMigrator` at least once for a new database. +`.DbMigrator` application automatically **creates the Initial migration** on first run. -#### Using EF Core Update-Database Command +**If you are using Visual Studio, you can skip the the *Running the DbMigrator* section.** However, other IDEs (e.g. Rider) may have problems for the first run since it adds the initial migration and compiles the project. In this case, open a command line terminal in the folder of the `.DbMigrator` project and run the following command: -Ef Core has `Update-Database` command which creates database if necessary and applies pending migrations. - -{{ if UI == "MVC" }} - -Right click to the {{if Tiered == "Yes"}}`.IdentityServer`{{else}}`.Web`{{end}} project and select **Set as StartUp project**: +````bash +dotnet run +```` -{{ else if UI != "MVC" }} +For the next time, you can just run it in your IDE as you normally do. -Right click to the `.HttpApi.Host` project and select **Set as StartUp Project**: +### Running the DbMigrator -{{ end }} +Right click to the `.DbMigrator` project and select **Set as StartUp Project** ![set-as-startup-project](images/set-as-startup-project.png) -Open the **Package Manager Console**, select `.EntityFrameworkCore.DbMigrations` project as the **Default Project** and run the `Update-Database` command: - -![package-manager-console-update-database](images/package-manager-console-update-database.png) + Hit F5 (or Ctrl+F5) to run the application. It will have an output like shown below: -This will create a new database based on the configured connection string. + ![db-migrator-output](images/db-migrator-output.png) -> **Using the `.DbMigrator` tool is the suggested way**, because it also seeds the initial data to be able to properly run the web application. -> -> If you just use the `Update-Database` command, you will have an empty database, so you can not login to the application since there is no initial admin user in the database. You can use the `Update-Database` command in development time when you don't need to seed the database. However, using the `.DbMigrator` application is easier and you can always use it to migrate the schema and seed the database. +> Initial [seed data](Data-Seeding.md) creates the `admin` user in the database (with the password is `1q2w3E*`) which is then used to login to the application. So, you need to use `.DbMigrator` at least once for a new database. {{ else if DB == "Mongo" }} From 1bab1cdd2a1b19f32cf4c337a3a63bfa483aeaa7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Sun, 17 Jan 2021 12:39:03 +0300 Subject: [PATCH 11/11] Update Getting-Started-Running-Solution.md --- docs/en/Getting-Started-Running-Solution.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/Getting-Started-Running-Solution.md b/docs/en/Getting-Started-Running-Solution.md index 92c9a4b2a7..163a3890b2 100644 --- a/docs/en/Getting-Started-Running-Solution.md +++ b/docs/en/Getting-Started-Running-Solution.md @@ -41,7 +41,7 @@ The solution uses the [Entity Framework Core Code First Migrations](https://docs `.DbMigrator` application automatically **creates the Initial migration** on first run. -**If you are using Visual Studio, you can skip the the *Running the DbMigrator* section.** However, other IDEs (e.g. Rider) may have problems for the first run since it adds the initial migration and compiles the project. In this case, open a command line terminal in the folder of the `.DbMigrator` project and run the following command: +**If you are using Visual Studio, you can skip to the *Running the DbMigrator* section.** However, other IDEs (e.g. Rider) may have problems for the first run since it adds the initial migration and compiles the project. In this case, open a command line terminal in the folder of the `.DbMigrator` project and run the following command: ````bash dotnet run