refactor(data): centralize list seeding in MigrateAndConfigure, add default-value test
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -2,7 +2,6 @@ using Avalonia;
|
|||||||
using ClaudeDo.Data;
|
using ClaudeDo.Data;
|
||||||
using ClaudeDo.Data.Git;
|
using ClaudeDo.Data.Git;
|
||||||
using ClaudeDo.Data.Repositories;
|
using ClaudeDo.Data.Repositories;
|
||||||
using ClaudeDo.Data.Seeding;
|
|
||||||
using ClaudeDo.Ui;
|
using ClaudeDo.Ui;
|
||||||
using ClaudeDo.Ui.Services;
|
using ClaudeDo.Ui.Services;
|
||||||
using ClaudeDo.Ui.ViewModels;
|
using ClaudeDo.Ui.ViewModels;
|
||||||
@@ -31,7 +30,6 @@ sealed class Program
|
|||||||
{
|
{
|
||||||
var db = scope.ServiceProvider.GetRequiredService<ClaudeDoDbContext>();
|
var db = scope.ServiceProvider.GetRequiredService<ClaudeDoDbContext>();
|
||||||
ClaudeDoDbContext.MigrateAndConfigure(db);
|
ClaudeDoDbContext.MigrateAndConfigure(db);
|
||||||
DefaultListsSeeder.SeedAsync(db).GetAwaiter().GetResult();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using ClaudeDo.Data.Models;
|
using ClaudeDo.Data.Models;
|
||||||
|
using ClaudeDo.Data.Seeding;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
using Microsoft.EntityFrameworkCore.Storage;
|
using Microsoft.EntityFrameworkCore.Storage;
|
||||||
@@ -73,5 +74,6 @@ public class ClaudeDoDbContext : DbContext
|
|||||||
}
|
}
|
||||||
|
|
||||||
db.Database.Migrate();
|
db.Database.Migrate();
|
||||||
|
DefaultListsSeeder.SeedAsync(db).GetAwaiter().GetResult();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
using ClaudeDo.Data;
|
using ClaudeDo.Data;
|
||||||
using ClaudeDo.Data.Seeding;
|
|
||||||
using ClaudeDo.Installer.Core;
|
using ClaudeDo.Installer.Core;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
@@ -21,7 +20,6 @@ public sealed class InitDatabaseStep : IInstallStep
|
|||||||
.Options;
|
.Options;
|
||||||
using var context = new ClaudeDoDbContext(options);
|
using var context = new ClaudeDoDbContext(options);
|
||||||
ClaudeDoDbContext.MigrateAndConfigure(context);
|
ClaudeDoDbContext.MigrateAndConfigure(context);
|
||||||
DefaultListsSeeder.SeedAsync(context).GetAwaiter().GetResult();
|
|
||||||
|
|
||||||
progress.Report("Schema applied successfully");
|
progress.Report("Schema applied successfully");
|
||||||
return Task.FromResult(StepResult.Ok());
|
return Task.FromResult(StepResult.Ok());
|
||||||
|
|||||||
@@ -40,6 +40,25 @@ public class TaskEntityFlagsTests : IDisposable
|
|||||||
Assert.Equal("hello", loaded.Notes);
|
Assert.Equal("hello", loaded.Notes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Defaults_Are_False_And_Null_When_Not_Set()
|
||||||
|
{
|
||||||
|
await using var ctx = NewContext();
|
||||||
|
var list = new ListEntity { Id = "l1", Name = "L", CreatedAt = DateTime.UtcNow };
|
||||||
|
ctx.Lists.Add(list);
|
||||||
|
ctx.Tasks.Add(new TaskEntity
|
||||||
|
{
|
||||||
|
Id = "t2", ListId = "l1", Title = "T", CreatedAt = DateTime.UtcNow,
|
||||||
|
});
|
||||||
|
await ctx.SaveChangesAsync();
|
||||||
|
|
||||||
|
await using var ctx2 = NewContext();
|
||||||
|
var loaded = await ctx2.Tasks.SingleAsync();
|
||||||
|
Assert.False(loaded.IsStarred);
|
||||||
|
Assert.False(loaded.IsMyDay);
|
||||||
|
Assert.Null(loaded.Notes);
|
||||||
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
try { if (File.Exists(_dbPath)) File.Delete(_dbPath); } catch { }
|
try { if (File.Exists(_dbPath)) File.Delete(_dbPath); } catch { }
|
||||||
|
|||||||
Reference in New Issue
Block a user