(tableId: string)
| 23 | * contiguous positions from this offset without per-batch position scans. |
| 24 | */ |
| 25 | export async function nextImportStartPosition(tableId: string): Promise<number> { |
| 26 | const [{ maxPos }] = await db |
| 27 | .select({ |
| 28 | maxPos: sql<number>`coalesce(max(${userTableRows.position}), -1)`.mapWith(Number), |
| 29 | }) |
| 30 | .from(userTableRows) |
| 31 | .where(eq(userTableRows.tableId, tableId)) |
| 32 | return maxPos + 1 |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * Append anchor `order_key` for an import — `max(order_key)`, or null when empty. Read once, |