mirror of
https://github.com/skoelle/focusapp.git
synced 2026-09-17 20:10:25 +00:00
feat: demo mode with SQLite and seed tasks
This commit is contained in:
@@ -26,5 +26,15 @@ public class FocusContext : DbContext
|
|||||||
entity.Property(e => e.CreatedAt).IsRequired();
|
entity.Property(e => e.CreatedAt).IsRequired();
|
||||||
entity.Property(e => e.UpdatedAt).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 }
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="9.0.8" />
|
||||||
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="9.0.0" />
|
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="9.0.0" />
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="10.2.3" />
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="10.2.3" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
+30
-16
@@ -8,25 +8,39 @@ var builder = WebApplication.CreateBuilder(args);
|
|||||||
|
|
||||||
builder.Logging.AddFilter("Microsoft.AspNetCore.HttpLogging", LogLevel.Information);
|
builder.Logging.AddFilter("Microsoft.AspNetCore.HttpLogging", LogLevel.Information);
|
||||||
|
|
||||||
// Connection-String aus ENV-Variablen aufbauen (appsettings.json ist Fallback)
|
// Datenbank: MariaDB oder SQLite (Demo-Modus)
|
||||||
static string BuildConnectionString(IConfiguration config)
|
static void ConfigureDatabase(IConfiguration config, IServiceCollection services)
|
||||||
{
|
{
|
||||||
return $"Server={config["DB_HOST"] ?? "localhost"};" +
|
var dbHost = config["DB_HOST"];
|
||||||
$"Port={config["DB_PORT"] ?? "3306"};" +
|
|
||||||
$"Database={config["DB_NAME"] ?? "focusapp"};" +
|
if (!string.IsNullOrEmpty(dbHost))
|
||||||
$"User={config["DB_USER"] ?? "focusapp"};" +
|
{
|
||||||
$"Password={config["DB_PASSWORD"] ?? "change-password"}";
|
// 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"}";
|
||||||
|
|
||||||
|
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)");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var connectionString = BuildConnectionString(builder.Configuration);
|
ConfigureDatabase(builder.Configuration, builder.Services);
|
||||||
|
|
||||||
// Add services
|
|
||||||
builder.Services.AddDbContext<FocusContext>(options =>
|
|
||||||
options.UseMySql(
|
|
||||||
connectionString,
|
|
||||||
ServerVersion.AutoDetect(connectionString)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
builder.Services.AddCors(options =>
|
builder.Services.AddCors(options =>
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user