1

I'm trying to set up a system, so when our Staging server builds, the "Update-Database" command is automatically applied.

The migrations are uploaded via the git pushes.

I've tried to put it as a build step in our CI, executing the console command: dotnet ef update database returning a headace since it does not seem to use the connection string form the config file and fails.

I also tried putting it as a pre-build event command line in the csproj, resulting it it hanging untill it eats up all the ram.

Any suggestions?

PeaceDealer
  • 977
  • 2
  • 9
  • 20

1 Answers1

0

I found the answer i was looking for at the end of the documentation> https://learn.microsoft.com/en-us/ef/core/managing-schemas/migrations/#apply-migrations-at-runtime

Some apps may want to apply migrations at runtime during startup or first run. Do this using the Migrate() method.

This method builds on top of the IMigrator service, which can be used for more advanced scenarios. Use DbContext.GetService<IMigrator>() to access it.

PeaceDealer
  • 977
  • 2
  • 9
  • 20