Update Dockerfile

-install dotnet-ef and ensure database is updated within docker
-remove ensurecreated entirely
This commit is contained in:
Alan Moon 2025-03-18 16:56:22 -07:00
parent 856236caa5
commit b9c7e49dc6
2 changed files with 11 additions and 8 deletions

View File

@ -12,6 +12,12 @@ RUN dotnet build -c Release -o /app
RUN mv src/mods /app && ln -s /app/mods src/
RUN mv src/assets /app && ln -s /app/assets src/
# install ef tools
RUN dotnet tool install --global dotnet-ef --version 7.0.12
# ensure database is in sync with migrations
RUN dotnet ef database update
# Create clean run environment (without source and sdk)
# FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
# WORKDIR /app

View File

@ -63,14 +63,11 @@ var app = builder.Build();
using var scope = app.Services.CreateScope();
scope.ServiceProvider.GetRequiredService<DBContext>().Database.EnsureCreated();
// ensure any new migrations are applied
var migrations = scope.ServiceProvider.GetRequiredService<DBContext>().Database.GetPendingMigrations();
if (migrations != null)
// apply them
await scope.ServiceProvider.GetRequiredService<DBContext>().Database.MigrateAsync();
if(app.Environment.IsDevelopment())
{
var migrations = scope.ServiceProvider.GetRequiredService<DBContext>().Database.GetPendingMigrations();
if (migrations != null) await scope.ServiceProvider.GetRequiredService<DBContext>().Database.MigrateAsync();
}
// Configure the HTTP request pipeline.