diff options
| author | Peter Stone <thepeterstone@gmail.com> | 2026-09-20 08:11:38 +0000 |
|---|---|---|
| committer | Peter Stone <thepeterstone@gmail.com> | 2026-09-20 08:11:38 +0000 |
| commit | c7b18e70ea87c287240243aed867b3a8b51689cb (patch) | |
| tree | ee11162958b3bcbe9e043f86bbbcb9ae73311161 /migrations | |
| parent | 4c22de26ed3720411c2c2351f900dd4c1415b3f8 (diff) | |
Make shopping items editable: tap to rename, move store/section, delete
Tapping an item outside shopping mode now opens an edit sheet. User-added items
can be renamed, moved between stores and sections, and deleted. PlanToEat items
show why they cannot be edited — the client is read-only, so presenting fields
that silently would not save is worse than saying so — and offer removal, which
marks them checked, the same mechanism shopping mode already uses.
This needed a store registry first. Stores previously existed only because some
item referenced them by name, with Trello's list names quietly acting as the
registry; removing Trello as a source made the gap visible. Without a registry
you cannot move an item into an empty store, and moving the last item out of a
store makes it vanish mid-edit. Migration 034 adds shopping_stores and
shopping_sections, seeded from the stores currently in use, and gives items a
section column — sections previously existed only as PlanToEat category
strings, so a user item could not be filed under one at all.
Registered stores and sections now appear in the list even when empty, which is
the whole point of the registry.
Two deliberate choices about destructive edges:
* Renaming a store renames it and moves its items in one transaction. Items
reference the store by name, so doing either alone orphans them.
* Deleting a store or section keeps the items, moving them to Unassigned or
clearing the section. Losing the list is far worse than re-filing an item.
* An UPDATE matching no rows is an error, not a silent success, so a stale id
cannot look like a saved edit.
Section options are rebuilt per store in the edit sheet rather than shipped as
one flat list, so a Costco item cannot be filed under a Safeway aisle.
18 new store tests, 11 handler tests.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018AwnALZL6bD4VBtATDVv3B
Diffstat (limited to 'migrations')
| -rw-r--r-- | migrations/034_shopping_stores_and_sections.sql | 41 | ||||
| -rw-r--r-- | migrations/README.md | 3 |
2 files changed, 43 insertions, 1 deletions
diff --git a/migrations/034_shopping_stores_and_sections.sql b/migrations/034_shopping_stores_and_sections.sql new file mode 100644 index 0000000..2b47846 --- /dev/null +++ b/migrations/034_shopping_stores_and_sections.sql @@ -0,0 +1,41 @@ +-- A real registry for shopping stores and sections. +-- +-- Until now a store existed only because some item referenced it by name. +-- Trello's list names were quietly acting as the registry; removing Trello as +-- a shopping source (migration 032) made the gap visible. Without this you +-- cannot move an item to a store that is currently empty, and moving the last +-- item out of a store makes that store vanish mid-edit. +-- +-- Sections are the same idea one level down. They previously existed only as +-- PlanToEat's category strings, so a user item could not be filed under one at +-- all. + +CREATE TABLE IF NOT EXISTS shopping_stores ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + name TEXT NOT NULL UNIQUE, + sort_order INTEGER NOT NULL DEFAULT 0, + created_at DATETIME DEFAULT CURRENT_TIMESTAMP +); + +CREATE TABLE IF NOT EXISTS shopping_sections ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + store_id INTEGER NOT NULL REFERENCES shopping_stores(id) ON DELETE CASCADE, + name TEXT NOT NULL, + sort_order INTEGER NOT NULL DEFAULT 0, + created_at DATETIME DEFAULT CURRENT_TIMESTAMP, + UNIQUE (store_id, name) +); + +CREATE INDEX IF NOT EXISTS idx_shopping_sections_store ON shopping_sections(store_id); + +-- Items gain a section. Store stays a name rather than a foreign key: items +-- also arrive from PlanToEat carrying a store name that may not be registered +-- yet, and a NOT NULL reference would mean either dropping those items or +-- auto-creating stores from scraped data. +ALTER TABLE user_shopping_items ADD COLUMN section TEXT NOT NULL DEFAULT ''; + +-- Seed the registry from the stores that currently exist, so nothing +-- disappears the moment the registry becomes authoritative. +INSERT OR IGNORE INTO shopping_stores (name) +SELECT DISTINCT TRIM(store) FROM user_shopping_items +WHERE TRIM(COALESCE(store, '')) <> ''; diff --git a/migrations/README.md b/migrations/README.md index 1564b48..07320af 100644 --- a/migrations/README.md +++ b/migrations/README.md @@ -29,10 +29,11 @@ Migration 007 was reserved during development but never implemented. The gap is Migrations are applied automatically on application startup via `store.RunMigrations()`. The `schema_migrations` table tracks which migrations have been applied. | 032 | `032_import_trello_shopping_items.sql` | One-time import of Trello Shopping-board cards (Hardware Store + unlisted) into user items, ahead of removing Trello as a shopping source | | 033 | `033_ics_feeds.sql` | Subscribed iCalendar (.ics) feeds, merged into calendar_events | +| 034 | `034_shopping_stores_and_sections.sql` | Store/section registry + `user_shopping_items.section` | ## Creating New Migrations -1. Create file: `migrations/NNN_description.sql` (next number is 034) +1. Create file: `migrations/NNN_description.sql` (next number is 035) 2. Write idempotent SQL (use `IF NOT EXISTS` where possible) 3. Test locally: `go run cmd/dashboard/main.go` 4. Verify: Check `schema_migrations` table for new entry |
