Fixes the three review findings on 50399b6 (pull request #102):
- A batch now rereads every declined name inside its storing transaction,
so a Pass committed after the batch read its input but before it stores
can no longer let the passed dish into the deck (SQ-01).
- A decision that leaves the deck under five creates the replenish batch
and its job in the decision's own transaction, so a decision is never
recorded without the replenish it calls for; when they cannot be
written, neither is the decision, and a retry decides again (SQ-02).
StartBatch commits the batch with its job the same way, replacing the
mutex and the fail-on-enqueue cleanup. jobs gains Kind.EnqueueTx and
Kind.Wake for this.
- Migration 0012 gives each suggestion the name its dish was suggested
under; declined names for batches and the household context's passed
list read it instead of the dinner's mutable name, so renaming a passed
dinner no longer erases it from dedupe (SQ-03).
Task: b4f2558c-227f-4627-852b-be5aa190242a
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
89 lines
2.1 KiB
Go
89 lines
2.1 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.31.1
|
|
// source: household_context.sql
|
|
|
|
package db
|
|
|
|
import (
|
|
"context"
|
|
)
|
|
|
|
const listPlannedDinners = `-- name: ListPlannedDinners :many
|
|
SELECT plan_days.date, dinners.name
|
|
FROM plan_days
|
|
JOIN dinners ON dinners.id = plan_days.dinner_id
|
|
WHERE plan_days.date >= ?1 AND plan_days.date < ?2
|
|
ORDER BY plan_days.date, plan_days.id
|
|
`
|
|
|
|
type ListPlannedDinnersParams struct {
|
|
FromDate string
|
|
ToDate string
|
|
}
|
|
|
|
type ListPlannedDinnersRow struct {
|
|
Date string
|
|
Name string
|
|
}
|
|
|
|
// The planned dinners dated from from_date up to but not including
|
|
// to_date, oldest first. Days with no dinner are left out.
|
|
func (q *Queries) ListPlannedDinners(ctx context.Context, arg ListPlannedDinnersParams) ([]ListPlannedDinnersRow, error) {
|
|
rows, err := q.db.QueryContext(ctx, listPlannedDinners, arg.FromDate, arg.ToDate)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []ListPlannedDinnersRow
|
|
for rows.Next() {
|
|
var i ListPlannedDinnersRow
|
|
if err := rows.Scan(&i.Date, &i.Name); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Close(); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const listRecentDeclinedNames = `-- name: ListRecentDeclinedNames :many
|
|
|
|
SELECT name
|
|
FROM suggestions
|
|
WHERE status = 'declined'
|
|
ORDER BY decided_at DESC, id DESC
|
|
LIMIT ?
|
|
`
|
|
|
|
// Reads for the AI household context block (internal/ai/harness).
|
|
// The names the most recently declined suggestions were suggested under,
|
|
// newest first; renaming their dinners does not change them.
|
|
func (q *Queries) ListRecentDeclinedNames(ctx context.Context, limit int64) ([]string, error) {
|
|
rows, err := q.db.QueryContext(ctx, listRecentDeclinedNames, limit)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []string
|
|
for rows.Next() {
|
|
var name string
|
|
if err := rows.Scan(&name); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, name)
|
|
}
|
|
if err := rows.Close(); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|