feat(data): seed default Lists (My Day, Important, Planned)

This commit is contained in:
mika kuns
2026-04-20 10:02:07 +02:00
parent 928dde1358
commit bd8a4d0565
4 changed files with 72 additions and 2 deletions

View File

@@ -2,6 +2,7 @@ using Avalonia;
using ClaudeDo.Data;
using ClaudeDo.Data.Git;
using ClaudeDo.Data.Repositories;
using ClaudeDo.Data.Seeding;
using ClaudeDo.Ui;
using ClaudeDo.Ui.Services;
using ClaudeDo.Ui.ViewModels;
@@ -28,8 +29,9 @@ sealed class Program
using (var scope = services.CreateScope())
{
ClaudeDoDbContext.MigrateAndConfigure(
scope.ServiceProvider.GetRequiredService<ClaudeDoDbContext>());
var db = scope.ServiceProvider.GetRequiredService<ClaudeDoDbContext>();
ClaudeDoDbContext.MigrateAndConfigure(db);
DefaultListsSeeder.SeedAsync(db).GetAwaiter().GetResult();
}
try

View File

@@ -0,0 +1,25 @@
using ClaudeDo.Data.Models;
using Microsoft.EntityFrameworkCore;
namespace ClaudeDo.Data.Seeding;
public static class DefaultListsSeeder
{
private static readonly string[] Defaults = { "My Day", "Important", "Planned" };
public static async Task SeedAsync(ClaudeDoDbContext ctx, CancellationToken ct = default)
{
var existing = await ctx.Lists.Select(l => l.Name).ToListAsync(ct);
var now = DateTime.UtcNow;
foreach (var name in Defaults.Where(n => !existing.Contains(n)))
{
ctx.Lists.Add(new ListEntity
{
Id = Guid.NewGuid().ToString("N"),
Name = name,
CreatedAt = now,
});
}
await ctx.SaveChangesAsync(ct);
}
}

View File

@@ -1,4 +1,5 @@
using ClaudeDo.Data;
using ClaudeDo.Data.Seeding;
using ClaudeDo.Installer.Core;
using Microsoft.EntityFrameworkCore;
@@ -20,6 +21,7 @@ public sealed class InitDatabaseStep : IInstallStep
.Options;
using var context = new ClaudeDoDbContext(options);
ClaudeDoDbContext.MigrateAndConfigure(context);
DefaultListsSeeder.SeedAsync(context).GetAwaiter().GetResult();
progress.Report("Schema applied successfully");
return Task.FromResult(StepResult.Ok());