Fix: DB-Pfad auf /app/data/fitness.db korrigiert
Deploy Fitness App / deploy (push) Successful in 1m6s
Deploy Fitness App / deploy (push) Successful in 1m6s
This commit is contained in:
+11
-1
@@ -2,8 +2,10 @@ using Microsoft.EntityFrameworkCore;
|
|||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
|
// Datenbank-Pfad: /app/data im Container (Volume) - überlebt Container-Neustarts!
|
||||||
|
var dbPath = Path.Combine("/app/data", "fitness.db");
|
||||||
builder.Services.AddDbContext<AppDbContext>(options =>
|
builder.Services.AddDbContext<AppDbContext>(options =>
|
||||||
options.UseSqlite("Data Source=fitness.db"));
|
options.UseSqlite($"Data Source={dbPath}"));
|
||||||
|
|
||||||
builder.Services.AddEndpointsApiExplorer();
|
builder.Services.AddEndpointsApiExplorer();
|
||||||
builder.Services.AddOpenApiDocument();
|
builder.Services.AddOpenApiDocument();
|
||||||
@@ -11,6 +13,13 @@ builder.Services.AddSwaggerGen();
|
|||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
||||||
|
// Datenbank automatisch erstellen, falls sie nicht existiert
|
||||||
|
using (var scope = app.Services.CreateScope())
|
||||||
|
{
|
||||||
|
var db = scope.ServiceProvider.GetRequiredService<AppDbContext>();
|
||||||
|
db.Database.EnsureCreated();
|
||||||
|
}
|
||||||
|
|
||||||
if (app.Environment.IsDevelopment())
|
if (app.Environment.IsDevelopment())
|
||||||
{
|
{
|
||||||
app.UseOpenApi();
|
app.UseOpenApi();
|
||||||
@@ -73,3 +82,4 @@ public class AppDbContext : DbContext
|
|||||||
public AppDbContext(DbContextOptions<AppDbContext> options) : base(options) { }
|
public AppDbContext(DbContextOptions<AppDbContext> options) : base(options) { }
|
||||||
public DbSet<Workout> Workouts => Set<Workout>();
|
public DbSet<Workout> Workouts => Set<Workout>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user