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:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user