✅ EF Core migrations with Docker
I'm trying to do a simple blazor app that works with database but I can't find a standardized good practice to perform migrations. I'm running both db and blazor app via docker compose.
17 Replies
does the built in migrations work for you? https://learn.microsoft.com/en-us/ef/core/managing-schemas/migrations/?tabs=dotnet-core-cli
Migrations Overview - EF Core
Overview of using migrations to manage database schemas with Entity Framework Core
@Clean Cock see https://learn.microsoft.com/en-us/ef/core/managing-schemas/migrations/applying?tabs=dotnet-core-cli
Applying Migrations - EF Core
Strategies for applying schema migrations to production and development databases using Entity Framework Core
Yea, the catch is that im running both database and blazor app via docker compose on separate containers
Anything wrong with running migrations on startup? If you're on compose, you (probably) run only a single instance anyways, unless you use replicas
You could also build a startup dependency chain and run an init container after your db container is up and running
How is that a catch?
im fairly new to both docker and ef core and I mostly have no idea what are you talking about sorry, ill try to do a better research first
Am I correct in that this is a two-container setup? One for you app, the other for the database server?
yes
@Clean Chicken and how do you want to apply the migrations? https://learn.microsoft.com/en-us/ef/core/managing-schemas/migrations/applying?tabs=dotnet-core-cli
Applying Migrations - EF Core
Strategies for applying schema migrations to production and development databases using Entity Framework Core
Do you just want it done automatically when the app starts up, or do you want to do it in a separate step?
im just starting to develop this app so for now it would be every time I add a new model or something
if I do not change anything in schema and set migrations on startup will it create empty migrations?
It only applies the migrations that aren't already applied to the database.
You probably want "Apply migrations at runtime"
oh, so for development applying them on startup would be the best option
Yes.
For production, you may want to consider other options, all depends on your needs.
Personally for my personal apps I just migrate at startup.
yea this makes life easier, ill read about that and implement it later, thanks
$close
If you have no further questions, please use /close to mark the forum thread as answered