forked from SoDOff-Project/sodoff
Update Dockerfile
-install dotnet-ef and ensure database is updated within docker -remove ensurecreated entirely
This commit is contained in:
parent
856236caa5
commit
b9c7e49dc6
@ -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
|
||||
|
@ -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.
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user