Creating a Regular now enqueues a ground_dinner job and returns at once
with its grounding_job_id. The job grounds the dinner's recipe_url with
GroundURL, else its name with Ground, and sets grounding_status grounded
(recipe, photo, method, minutes, difficulty) or failed with a
grounding_error reason code (migration 0009). It writes only a dinner
still pending, so a fix made meanwhile wins.
GET /api/v1/dinners/{id}/recipe-candidates returns up to 3 ranked
candidates {candidate_id, title, site_name, photo_url, minutes} without
downloading photos or running the model. POST /api/v1/dinners/{id}/ground
takes exactly one of {candidate_id}, {recipe_url} or {manual: {...}} and
sets grounded or manual.
PhotoCache takes an ImageFetcher interface and recipestest provides fakes
so other packages can test grounding with fake search, fetch and model.
main wires the Grounder with normalize_recipe over the AI settings.
Maestro task: 0cbaa5bf-8be4-4cbd-aab2-891e7f1bc2b5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
112 lines
2.5 KiB
SQL
112 lines
2.5 KiB
SQL
-- name: CreateDinner :one
|
|
INSERT INTO dinners (
|
|
id, name, normalized_name, status, origin, method, minutes_total,
|
|
difficulty, cuisine, is_favorite, recipe_id, recipe_url, photo_id,
|
|
grounding_status, updated_by, created_at, updated_at
|
|
) VALUES (
|
|
?, ?, ?, ?, ?, ?, ?,
|
|
?, ?, ?, ?, ?, ?,
|
|
?, ?, ?, ?
|
|
)
|
|
RETURNING *;
|
|
|
|
-- name: GetDinner :one
|
|
SELECT * FROM dinners
|
|
WHERE id = ?;
|
|
|
|
-- name: ListDinnersByStatus :many
|
|
SELECT * FROM dinners
|
|
WHERE status = ?
|
|
ORDER BY normalized_name, id;
|
|
|
|
-- name: ListUnarchivedDinners :many
|
|
-- Every dinner a new or renamed dinner must not repeat.
|
|
SELECT * FROM dinners
|
|
WHERE status <> 'archived'
|
|
ORDER BY id;
|
|
|
|
-- name: UpdateDinner :one
|
|
-- An unknown id returns sql.ErrNoRows.
|
|
UPDATE dinners
|
|
SET name = ?,
|
|
normalized_name = ?,
|
|
status = ?,
|
|
origin = ?,
|
|
method = ?,
|
|
minutes_total = ?,
|
|
difficulty = ?,
|
|
cuisine = ?,
|
|
recipe_id = ?,
|
|
photo_id = ?,
|
|
grounding_status = ?,
|
|
updated_by = ?,
|
|
updated_at = ?
|
|
WHERE id = ?
|
|
RETURNING *;
|
|
|
|
-- name: ArchiveDinner :one
|
|
-- An unknown id returns sql.ErrNoRows.
|
|
UPDATE dinners
|
|
SET status = 'archived',
|
|
updated_by = ?,
|
|
updated_at = ?
|
|
WHERE id = ?
|
|
RETURNING *;
|
|
|
|
-- name: SetDinnerFavorite :one
|
|
-- An unknown id returns sql.ErrNoRows.
|
|
UPDATE dinners
|
|
SET is_favorite = ?,
|
|
updated_by = ?,
|
|
updated_at = ?
|
|
WHERE id = ?
|
|
RETURNING *;
|
|
|
|
-- name: ToggleDinnerFavorite :one
|
|
-- An unknown id returns sql.ErrNoRows.
|
|
UPDATE dinners
|
|
SET is_favorite = 1 - is_favorite,
|
|
updated_by = ?,
|
|
updated_at = ?
|
|
WHERE id = ?
|
|
RETURNING *;
|
|
|
|
-- name: GroundDinner :one
|
|
-- Records a dinner's grounding (grounded or manual) and clears any
|
|
-- grounding_error. An unknown id returns sql.ErrNoRows.
|
|
UPDATE dinners
|
|
SET recipe_id = ?,
|
|
photo_id = ?,
|
|
method = ?,
|
|
minutes_total = ?,
|
|
difficulty = ?,
|
|
grounding_status = ?,
|
|
grounding_error = NULL,
|
|
updated_by = ?,
|
|
updated_at = ?
|
|
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).
|
|
UPDATE dinners
|
|
SET recipe_id = ?,
|
|
photo_id = ?,
|
|
method = ?,
|
|
minutes_total = ?,
|
|
difficulty = ?,
|
|
grounding_status = 'grounded',
|
|
grounding_error = NULL,
|
|
updated_at = ?
|
|
WHERE id = ? AND grounding_status = 'pending';
|
|
|
|
-- 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).
|
|
UPDATE dinners
|
|
SET grounding_status = 'failed',
|
|
grounding_error = ?,
|
|
updated_at = ?
|
|
WHERE id = ? AND grounding_status = 'pending';
|