Replies: 2 comments 1 reply
-
There are certainly some improvements that could be made, and I'm interested to hear any suggestions. Please take a look at my blog post on Database Initialisation Strategies for Entity Framework Core for additional information. Currently, the database is automatically initialised when the application runs. Within WebUI/Program.cs, the following code is responsible for that behaviour: await app.InitialiseDatabaseAsync(); This is normal behaviour and desirable for new solutions when the data model will change frequently. However, as development progresses this behaviour can be disabled. Since this repo is a template for new solutions, I think this should be the default behaviour, however I am not opposed to adding an option to disable this behaviour, e.g. The initialiser also runs after a successful build. However, this is not normal and is a side effect of the NSwag MSBuild task contained within WebUI.csproj: <Target Name="NSwag" AfterTargets="PostBuildEvent" Condition=" '$(Configuration)' == 'Debug' And '$(SkipNSwag)' != 'True' ">
<Exec ConsoleToMSBuild="true" ContinueOnError="true" WorkingDirectory="$(ProjectDir)" EnvironmentVariables="ASPNETCORE_ENVIRONMENT=Development" Command="$(NSwagExe_Net70) run config.nswag /variables:Configuration=$(Configuration)">
<Output TaskParameter="ExitCode" PropertyName="NSwagExitCode" />
<Output TaskParameter="ConsoleOutput" PropertyName="NSwagOutput" />
</Exec>
<Message Text="$(NSwagOutput)" Condition="'$(NSwagExitCode)' == '0'" Importance="low" />
<Error Text="$(NSwagOutput)" Condition="'$(NSwagExitCode)' != '0'" />
</Target> This task is responsible for generating the Open API specification and the Angular / React TypeScript clients (if applicable). I haven't worked out how to stop this from happening, so any suggestions would be greatly appreciated. Hopefully this provides enough detail on how it all works. Let me know if you have any suggestions for improvement. |
Beta Was this translation helpful? Give feedback.
-
The latest update will only apply |
Beta Was this translation helpful? Give feedback.
-
TLDR: Remove auto applying migrations to the database
In creating a Web API-only solution, I noticed that migrations get auto applied to the database when the API is spun up or when a
dotnet build
command is executed. This seems to be by design. But it's also doing it on subsequent migrations and I'm not sure if this is a bug or by design.Either way, I think it'd be better to let the user dictate when migrations get applied to the db via the CLI commands e.g
dotnet ef database update
. I understand it's easier to auto create the db and run migrations when first setting up the project, but I think it could be a cause for confusion on subsequent migrations.If it's easier, I'd say just add extra commands during setup to create and apply the migrations manually.
On a side note, how is it auto applying migrations via `dotnet build'? 🤯 I'm looking around and haven't been able to put two and two together yet.
Beta Was this translation helpful? Give feedback.
All reactions