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>
38 lines
1.6 KiB
SQL
38 lines
1.6 KiB
SQL
-- 0012_suggestion_name: a suggestion keeps the name its dish was suggested
|
|
-- under. Its dinner can be renamed, even once archived by a Pass, so the
|
|
-- declined names every later batch refuses are read from here, never from
|
|
-- the dinner. A suggestion stored before this takes its dinner's name now.
|
|
-- SQLite cannot add a NOT NULL column without a default, so the table is
|
|
-- rebuilt as 0005 does: copy the rows aside, drop the table, create it
|
|
-- again, copy the rows back and drop the copy. Nothing references
|
|
-- suggestions.
|
|
|
|
CREATE TABLE suggestions_copy AS SELECT * FROM suggestions;
|
|
|
|
DROP TABLE suggestions;
|
|
|
|
CREATE TABLE suggestions (
|
|
id TEXT NOT NULL PRIMARY KEY,
|
|
dinner_id TEXT NOT NULL REFERENCES dinners (id),
|
|
batch_id TEXT NOT NULL REFERENCES suggestion_batches (id),
|
|
name TEXT NOT NULL CHECK (name <> ''),
|
|
reason TEXT NOT NULL,
|
|
cited_regular_ids TEXT NOT NULL, -- JSON array of dinner ids
|
|
status TEXT NOT NULL CHECK (status IN ('pending', 'accepted', 'declined')),
|
|
decided_at TEXT,
|
|
created_at TEXT NOT NULL,
|
|
updated_at TEXT NOT NULL
|
|
);
|
|
|
|
INSERT INTO suggestions (
|
|
id, dinner_id, batch_id, name, reason, cited_regular_ids, status, decided_at, created_at, updated_at
|
|
)
|
|
SELECT
|
|
suggestions_copy.id, suggestions_copy.dinner_id, suggestions_copy.batch_id, dinners.name,
|
|
suggestions_copy.reason, suggestions_copy.cited_regular_ids, suggestions_copy.status,
|
|
suggestions_copy.decided_at, suggestions_copy.created_at, suggestions_copy.updated_at
|
|
FROM suggestions_copy
|
|
JOIN dinners ON dinners.id = suggestions_copy.dinner_id;
|
|
|
|
DROP TABLE suggestions_copy;
|