feat(data): add task numbers schema, allocator, and backfill migration
TaskEntity.Number is a global, monotonically increasing, never-reused integer (displayed as #123), allocated from AppSettingsEntity.NextTaskNumber via a single UPDATE...RETURNING statement rather than MAX(number)+1, which would reissue a deleted task's number. Both insert paths (TaskRepository. AddAsync and CreateChildAsync) route through the new TaskNumberAllocator, with a bounded retry on a unique-index collision. One migration adds the columns, backfills existing rows in creation order, and creates the unique index afterwards. Data-layer only; MCP/UI wiring is later slices.
This commit is contained in:
@@ -67,7 +67,7 @@ public class PlanningAggregatorTests : IDisposable
|
||||
ctx.Tasks.Add(new TaskEntity
|
||||
{
|
||||
Id = parentId, ListId = listId, Title = "plan", CreatedAt = DateTime.UtcNow,
|
||||
Status = TaskStatus.Idle, PlanningPhase = PlanningPhase.Active, SortOrder = 0,
|
||||
Status = TaskStatus.Idle, PlanningPhase = PlanningPhase.Active, SortOrder = 0, Number = 1,
|
||||
});
|
||||
|
||||
// Two children (sorted A then B).
|
||||
@@ -76,12 +76,12 @@ public class PlanningAggregatorTests : IDisposable
|
||||
ctx.Tasks.Add(new TaskEntity
|
||||
{
|
||||
Id = subA, ListId = listId, Title = "child A", CreatedAt = DateTime.UtcNow,
|
||||
ParentTaskId = parentId, Status = TaskStatus.Done, SortOrder = 1,
|
||||
ParentTaskId = parentId, Status = TaskStatus.Done, SortOrder = 1, Number = 2,
|
||||
});
|
||||
ctx.Tasks.Add(new TaskEntity
|
||||
{
|
||||
Id = subB, ListId = listId, Title = "child B", CreatedAt = DateTime.UtcNow,
|
||||
ParentTaskId = parentId, Status = TaskStatus.Done, SortOrder = 2,
|
||||
ParentTaskId = parentId, Status = TaskStatus.Done, SortOrder = 2, Number = 3,
|
||||
});
|
||||
await ctx.SaveChangesAsync();
|
||||
|
||||
@@ -171,19 +171,19 @@ public class PlanningAggregatorTests : IDisposable
|
||||
ctx.Tasks.Add(new TaskEntity
|
||||
{
|
||||
Id = parentId, ListId = listId, Title = "plan", CreatedAt = DateTime.UtcNow,
|
||||
Status = TaskStatus.Idle, PlanningPhase = PlanningPhase.Active, SortOrder = 0,
|
||||
Status = TaskStatus.Idle, PlanningPhase = PlanningPhase.Active, SortOrder = 0, Number = 1,
|
||||
});
|
||||
var subA = Guid.NewGuid().ToString();
|
||||
var subB = Guid.NewGuid().ToString();
|
||||
ctx.Tasks.Add(new TaskEntity
|
||||
{
|
||||
Id = subA, ListId = listId, Title = "A", CreatedAt = DateTime.UtcNow,
|
||||
ParentTaskId = parentId, Status = TaskStatus.Done, SortOrder = 1,
|
||||
ParentTaskId = parentId, Status = TaskStatus.Done, SortOrder = 1, Number = 2,
|
||||
});
|
||||
ctx.Tasks.Add(new TaskEntity
|
||||
{
|
||||
Id = subB, ListId = listId, Title = "B", CreatedAt = DateTime.UtcNow,
|
||||
ParentTaskId = parentId, Status = TaskStatus.Done, SortOrder = 2,
|
||||
ParentTaskId = parentId, Status = TaskStatus.Done, SortOrder = 2, Number = 3,
|
||||
});
|
||||
await ctx.SaveChangesAsync();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user