Create database at application startup
This commit is contained in:
@@ -7,7 +7,6 @@ namespace EstusShots.Server.Services
|
||||
{
|
||||
public EstusShotsContext(DbContextOptions options) : base(options)
|
||||
{
|
||||
Database.EnsureCreated();
|
||||
}
|
||||
|
||||
public DbSet<Season> Seasons { get; set; } = default!;
|
||||
|
||||
@@ -74,6 +74,11 @@ namespace EstusShots.Server
|
||||
app.UseRouting();
|
||||
app.UseAuthorization();
|
||||
app.UseEndpoints(endpoints => { endpoints.MapControllers(); });
|
||||
|
||||
// Open a scope and create the database, if necessary
|
||||
using var scope = app.ApplicationServices.GetRequiredService<IServiceScopeFactory>().CreateScope();
|
||||
using var context = scope.ServiceProvider.GetService<EstusShotsContext>();
|
||||
context.Database.EnsureCreated();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user