Seed provenance and inventory: source links and seed lots (#50)
Build image / build-and-push (push) Successful in 4s
Gadfly review (reusable) / review (pull_request) Successful in 11m8s
Adversarial Review (Gadfly) / review (pull_request) Successful in 11m9s

"German Red Garlic" now links back to the Johnny's page it came from, and pansy
knows how much is left.

Two modelling calls, both of which look like omissions unless stated.

The plant catalog stays FLAT — no species/variety hierarchy. A row in your
catalog just is the thing you plant; the built-in "Garlic" is a generic starting
point you clone. A hierarchy buys taxonomy nobody asked for and complicates
every join.

Inventory belongs to a PURCHASE, not to a variety. You might buy the same garlic
from two vendors in two years at two prices and two germination rates; quantity
columns on plants would collapse all of that into one number and lose it. So
lots get their own table, and owner_id sits on the lot rather than being
inherited from the plant — you can buy generic built-in Garlic from Johnny's and
the record is still yours alone. Lots are never shared along with a garden.

`remaining` is derived, never stored: quantity minus the summed effective count
of the active plantings attributed to the lot. The alternative — decrementing a
column when you plant — drifts the moment anything edits or removes a planting
behind its back, and once it has drifted there's no way to tell what the true
number was. Removing a plop gives the seed back with nothing having to remember
to. The usage query returns raw radius/count/spacing rather than a SUM, because
the effective-count formula lives in the service and reproducing it in SQL would
guarantee the two drift apart.

source_url is validated as http(s) with a host, on both plants and lots. It
renders as a clickable link, so that check is load-bearing rather than tidiness:
without it a stored javascript: URL becomes script execution the moment someone
clicks it. Schemeless and relative URLs are refused too — they'd resolve against
pansy's own origin, which is never what a vendor link means.

A planting's lot must be the actor's AND a lot of the plant being planted.
Attributing a garlic planting to a tomato lot would silently corrupt every
remaining count downstream, so it's refused rather than stored, and re-checked
on update in case a plant swap invalidated a previously-valid attribution.

Deleting a lot leaves its plantings alone with a null link: the plants really
were in the ground, whatever happened to the record of the packet.

Closes #50

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01H3zbym8Doka2d7D48maSgZ
This commit is contained in:
2026-07-21 01:20:50 -04:00
co-authored by Claude Opus 4.8
parent 3ec77a1099
commit 81481ede2f
15 changed files with 1223 additions and 31 deletions
+17
View File
@@ -50,6 +50,9 @@ type PlantingInput struct {
Count *int
Label *string
PlantedAt *string
// SeedLotID attributes this planting to a purchase, so the lot can report
// what's left. Optional.
SeedLotID *int64
}
// PlantingPatch is a partial update. The nullable fields (Count/Label/PlantedAt/
@@ -68,6 +71,8 @@ type PlantingPatch struct {
PlantedAt *string
SetRemovedAt bool
RemovedAt *string
SetSeedLotID bool
SeedLotID *int64
}
// CreatePlanting places a plop in a plantable object the actor can edit.
@@ -93,6 +98,7 @@ func (s *Service) CreatePlanting(ctx context.Context, actorID, objectID int64, i
Count: in.Count,
Label: trimStringPtr(in.Label),
PlantedAt: in.PlantedAt,
SeedLotID: in.SeedLotID,
}
if p.PlantedAt == nil {
today := s.now().UTC().Format(dateLayout)
@@ -101,6 +107,9 @@ func (s *Service) CreatePlanting(ctx context.Context, actorID, objectID int64, i
if err := finalizePlanting(p, o, true); err != nil {
return nil, err
}
if err := s.seedLotForPlanting(ctx, actorID, p.SeedLotID, p.PlantID); err != nil {
return nil, err
}
created, err := s.store.CreatePlanting(ctx, p)
if err != nil {
return nil, err
@@ -148,6 +157,11 @@ func (s *Service) UpdatePlanting(ctx context.Context, actorID, plantingID int64,
if err := finalizePlanting(pl, o, checkBounds); err != nil {
return nil, err
}
// Re-checked on every update, not just when the lot changes: a plant swap can
// leave a previously-valid attribution pointing at a lot of the wrong variety.
if err := s.seedLotForPlanting(ctx, actorID, pl.SeedLotID, pl.PlantID); err != nil {
return nil, err
}
pl.Version = version
updated, err := s.store.UpdatePlanting(ctx, pl)
@@ -249,6 +263,9 @@ func applyPlantingPatch(pl *domain.Planting, p PlantingPatch) {
if p.SetRemovedAt {
pl.RemovedAt = p.RemovedAt
}
if p.SetSeedLotID {
pl.SeedLotID = p.SeedLotID
}
}
// finalizePlanting validates a built/merged plop against its parent object.