fix: use integer instead of serial for taskNumber, add backfill on startup

serial caused db:push failure on existing tables. Now uses nullable
integer with app-level sequencing and startup backfill.
This commit is contained in:
2026-01-29 00:51:26 +00:00
parent 321ba2cadc
commit 76b9c61b09
3 changed files with 37 additions and 2 deletions

View File

@@ -119,6 +119,12 @@ export const taskRoutes = new Elysia({ prefix: "/api/tasks" })
const maxPos = await db
.select({ max: sql<number>`COALESCE(MAX(${tasks.position}), 0)` })
.from(tasks);
// Get next task number
const maxNum = await db
.select({ max: sql<number>`COALESCE(MAX(${tasks.taskNumber}), 0)` })
.from(tasks);
const nextNumber = (maxNum[0]?.max ?? 0) + 1;
const newTask = await db
.insert(tasks)
.values({
@@ -128,6 +134,7 @@ export const taskRoutes = new Elysia({ prefix: "/api/tasks" })
status: body.status || "queued",
priority: body.priority || "medium",
position: (maxPos[0]?.max ?? 0) + 1,
taskNumber: nextNumber,
progressNotes: [],
})
.returning();