diff --git a/Apps/Api/Startup.cs b/Apps/Api/Startup.cs
index 7bc2a8c..ef15b70 100644
--- a/Apps/Api/Startup.cs
+++ b/Apps/Api/Startup.cs
@@ -9,6 +9,7 @@ using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc.Authorization;
using Microsoft.AspNetCore.Routing;
+using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
@@ -106,6 +107,8 @@ namespace Api
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
+ MigrateDatabase(app);
+
app.UseOpenApi();
if (env.IsDevelopment())
@@ -135,5 +138,17 @@ namespace Api
});
});
}
+
+ ///
+ /// Lance les migrations. En production, il est plutôt conseillé de générer
+ /// les scripts avec `dotnet ef migrations script` et de les passer à la main.
+ ///
+ ///
+ private void MigrateDatabase(IApplicationBuilder app)
+ {
+ using var scope = app.ApplicationServices.CreateScope();
+ using var ctx = scope.ServiceProvider.GetRequiredService();
+ ctx.Database.Migrate();
+ }
}
}
diff --git a/Dockerfile b/Dockerfile
index 1cdc262..9e75f60 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -22,5 +22,6 @@ RUN dotnet publish -c release -o /app --no-restore
FROM mcr.microsoft.com/dotnet/aspnet:5.0
WORKDIR /app
COPY --from=build /app ./
+ENV "ConnectionStrings:Default"="Data Source=hn.db"
EXPOSE 80
ENTRYPOINT ["dotnet", "Api.dll"]
\ No newline at end of file