docker build fails at db migrations
This commit is contained in:
@@ -52,6 +52,31 @@ builder.Services.AddSwaggerGen(options =>
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Stelle sicher, dass das persistence-Verzeichnis existiert
|
||||
var persistenceDir = Path.Combine(Directory.GetCurrentDirectory(), "persistence");
|
||||
if (!Directory.Exists(persistenceDir))
|
||||
{
|
||||
Log.Information("Erstelle persistence-Verzeichnis: {PersistenceDir}", persistenceDir);
|
||||
Directory.CreateDirectory(persistenceDir);
|
||||
}
|
||||
|
||||
// Datenbank-Migration beim Start ausführen
|
||||
using (var scope = app.Services.CreateScope())
|
||||
{
|
||||
var dbContext = scope.ServiceProvider.GetRequiredService<WatcherDbContext>();
|
||||
try
|
||||
{
|
||||
Log.Information("Führe Datenbank-Migrationen aus...");
|
||||
dbContext.Database.Migrate();
|
||||
Log.Information("Datenbank-Migrationen erfolgreich angewendet");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, "Fehler beim Ausführen der Datenbank-Migrationen");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
if (!app.Environment.IsDevelopment())
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user