Fix stale Regular grounding and enforce three Regulars for onboarding
A background grounding result now applies only while the dinner is still pending under the normalized name the job searched: GroundPendingDinner and FailPendingDinnerGrounding match normalized_name, so a rename makes the old job's success or failure a no-op. Renaming a dinner still pending enqueues a fresh grounding job for the new name; if that cannot be enqueued, the dinner's grounding is failed so it is not left pending with no job. Completing onboarding (PATCH /api/v1/settings/household with onboarding_completed true) is refused with 400 invalid_settings until the household has at least three Regulars (status regular; archived and Quest log dinners do not count), and onboarding_completed_at is set only then. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -19,6 +19,11 @@ SELECT * FROM dinners
|
||||
WHERE status = ?
|
||||
ORDER BY normalized_name, id;
|
||||
|
||||
-- name: CountRegularDinners :one
|
||||
-- How many Regulars the household has; archived dinners are not counted.
|
||||
SELECT COUNT(*) FROM dinners
|
||||
WHERE status = 'regular';
|
||||
|
||||
-- name: ListUnarchivedDinners :many
|
||||
-- Every dinner a new or renamed dinner must not repeat.
|
||||
SELECT * FROM dinners
|
||||
@@ -88,8 +93,9 @@ WHERE id = ?
|
||||
RETURNING *;
|
||||
|
||||
-- name: GroundPendingDinner :execrows
|
||||
-- Records the background grounding of a dinner still pending; a dinner
|
||||
-- grounded some other way meanwhile is left as it is (0 rows).
|
||||
-- Records the background grounding of a dinner still pending under the
|
||||
-- normalized name it was grounded for; a dinner grounded some other way or
|
||||
-- renamed meanwhile is left as it is (0 rows).
|
||||
UPDATE dinners
|
||||
SET recipe_id = ?,
|
||||
photo_id = ?,
|
||||
@@ -99,16 +105,17 @@ SET recipe_id = ?,
|
||||
grounding_status = 'grounded',
|
||||
grounding_error = NULL,
|
||||
updated_at = ?
|
||||
WHERE id = ? AND grounding_status = 'pending';
|
||||
WHERE id = ? AND grounding_status = 'pending' AND normalized_name = ?;
|
||||
|
||||
-- name: FailPendingDinnerGrounding :execrows
|
||||
-- Records why the background grounding of a dinner still pending failed; a
|
||||
-- dinner grounded some other way meanwhile is left as it is (0 rows).
|
||||
-- Records why the background grounding of a dinner still pending under the
|
||||
-- normalized name it was grounded for failed; a dinner grounded some other
|
||||
-- way or renamed meanwhile is left as it is (0 rows).
|
||||
UPDATE dinners
|
||||
SET grounding_status = 'failed',
|
||||
grounding_error = ?,
|
||||
updated_at = ?
|
||||
WHERE id = ? AND grounding_status = 'pending';
|
||||
WHERE id = ? AND grounding_status = 'pending' AND normalized_name = ?;
|
||||
|
||||
-- name: FailOrphanedPendingDinnerGroundings :execrows
|
||||
-- Fails every dinner still pending whose grounding job is no longer queued
|
||||
|
||||
Reference in New Issue
Block a user