feat: demo mode with SQLite and seed tasks

This commit is contained in:
2026-08-09 16:43:59 +02:00
parent 508a3f2dc7
commit af4389a7b9
3 changed files with 41 additions and 16 deletions
+10
View File
@@ -26,5 +26,15 @@ public class FocusContext : DbContext
entity.Property(e => e.CreatedAt).IsRequired();
entity.Property(e => e.UpdatedAt).IsRequired();
});
// Demo-Tasks fuer lokalen Test
var now = DateTime.UtcNow;
modelBuilder.Entity<FocusTask>().HasData(
new FocusTask { Id = 1, Title = "Projektstruktur klären", Description = "README, AGENTS.md, Lizenz", Order = 1, CreatedAt = now, UpdatedAt = now },
new FocusTask { Id = 2, Title = "API finalisieren", Description = "Health Endpoint, Validierung", Order = 2, CreatedAt = now, UpdatedAt = now },
new FocusTask { Id = 3, Title = "Frontend polishieren", Description = "CSS, Responsive, Tests", Order = 3, CreatedAt = now, UpdatedAt = now },
new FocusTask { Id = 4, Title = "Docker Setup prüfen", Description = "Healthcheck, CI/CD", Order = 4, CreatedAt = now, UpdatedAt = now },
new FocusTask { Id = 5, Title = "Doku vervollständigen", Description = "API Docs, Deployment Guide", Order = 5, CreatedAt = now, UpdatedAt = now }
);
}
}
+1
View File
@@ -12,6 +12,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="9.0.8" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="9.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="10.2.3" />
</ItemGroup>
+23 -9
View File
@@ -8,25 +8,39 @@ var builder = WebApplication.CreateBuilder(args);
builder.Logging.AddFilter("Microsoft.AspNetCore.HttpLogging", LogLevel.Information);
// Connection-String aus ENV-Variablen aufbauen (appsettings.json ist Fallback)
static string BuildConnectionString(IConfiguration config)
// Datenbank: MariaDB oder SQLite (Demo-Modus)
static void ConfigureDatabase(IConfiguration config, IServiceCollection services)
{
return $"Server={config["DB_HOST"] ?? "localhost"};" +
var dbHost = config["DB_HOST"];
if (!string.IsNullOrEmpty(dbHost))
{
// Produktion: MariaDB
var connectionString = $"Server={dbHost};" +
$"Port={config["DB_PORT"] ?? "3306"};" +
$"Database={config["DB_NAME"] ?? "focusapp"};" +
$"User={config["DB_USER"] ?? "focusapp"};" +
$"Password={config["DB_PASSWORD"] ?? "change-password"}";
}
var connectionString = BuildConnectionString(builder.Configuration);
// Add services
builder.Services.AddDbContext<FocusContext>(options =>
services.AddDbContext<FocusContext>(options =>
options.UseMySql(
connectionString,
ServerVersion.AutoDetect(connectionString)
)
);
);
Console.WriteLine("Using MariaDB database");
}
else
{
// Demo-Modus: SQLite
services.AddDbContext<FocusContext>(options =>
options.UseSqlite("Data Source=focusapp-demo.db")
);
Console.WriteLine("Using SQLite database (demo mode)");
}
}
ConfigureDatabase(builder.Configuration, builder.Services);
builder.Services.AddCors(options =>
{