Seed provenance and inventory: source links and seed lots (#50)
"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:
@@ -109,6 +109,14 @@ const (
|
||||
OpCreate = "create"
|
||||
OpUpdate = "update"
|
||||
OpDelete = "delete"
|
||||
|
||||
// Units a seed lot's quantity can be counted in (mirrors the schema CHECK).
|
||||
UnitSeeds = "seeds"
|
||||
UnitGrams = "grams"
|
||||
UnitOunces = "ounces"
|
||||
UnitPackets = "packets"
|
||||
UnitBulbs = "bulbs"
|
||||
UnitPlants = "plants"
|
||||
)
|
||||
|
||||
// ChangeSet groups the revisions produced by one logical operation — the unit of
|
||||
@@ -280,6 +288,11 @@ type GardenObject struct {
|
||||
}
|
||||
|
||||
// Plant is a catalog entry. OwnerID nil means a read-only seeded built-in.
|
||||
//
|
||||
// SourceURL/Vendor are provenance for the variety itself — the page you'd go
|
||||
// back to in order to buy it again. What you actually bought, and how much is
|
||||
// left, lives in SeedLot instead: the same variety may come from two vendors in
|
||||
// two years, and a single pair of columns here would collapse that.
|
||||
type Plant struct {
|
||||
ID int64 `json:"id"`
|
||||
OwnerID *int64 `json:"ownerId,omitempty"` // nil = built-in
|
||||
@@ -289,12 +302,44 @@ type Plant struct {
|
||||
Color string `json:"color"`
|
||||
Icon string `json:"icon"`
|
||||
DaysToMaturity *int `json:"daysToMaturity,omitempty"`
|
||||
SourceURL string `json:"sourceUrl"`
|
||||
Vendor string `json:"vendor"`
|
||||
Notes string `json:"notes"`
|
||||
Version int64 `json:"version"`
|
||||
CreatedAt string `json:"createdAt"`
|
||||
UpdatedAt string `json:"updatedAt"`
|
||||
}
|
||||
|
||||
// SeedLot is one purchase: a specific packet of a specific variety, from a
|
||||
// specific vendor, in a specific year. Owned by the buyer even when it points at
|
||||
// a built-in plant, and never shared along with a garden.
|
||||
type SeedLot struct {
|
||||
ID int64 `json:"id"`
|
||||
OwnerID int64 `json:"ownerId"`
|
||||
PlantID int64 `json:"plantId"`
|
||||
Vendor string `json:"vendor"`
|
||||
SourceURL string `json:"sourceUrl"`
|
||||
SKU string `json:"sku"`
|
||||
LotCode string `json:"lotCode"`
|
||||
PurchasedAt *string `json:"purchasedAt,omitempty"`
|
||||
PackedForYear *int `json:"packedForYear,omitempty"`
|
||||
Quantity float64 `json:"quantity"`
|
||||
Unit string `json:"unit"`
|
||||
CostCents *int `json:"costCents,omitempty"`
|
||||
GerminationPct *float64 `json:"germinationPct,omitempty"`
|
||||
Notes string `json:"notes"`
|
||||
Version int64 `json:"version"`
|
||||
CreatedAt string `json:"createdAt"`
|
||||
UpdatedAt string `json:"updatedAt"`
|
||||
|
||||
// Used is the summed effective count of active plantings attributed to this
|
||||
// lot, and Remaining is Quantity - Used. Both are computed by the service and
|
||||
// never stored: a stored running total drifts the moment anything edits a
|
||||
// planting behind its back, and can't be audited afterwards.
|
||||
Used float64 `json:"used"`
|
||||
Remaining float64 `json:"remaining"`
|
||||
}
|
||||
|
||||
// Planting ("plop") is a circular patch of one plant, positioned in its parent
|
||||
// object's local frame. Count nil means it is derived from area / spacing².
|
||||
type Planting struct {
|
||||
@@ -308,9 +353,13 @@ type Planting struct {
|
||||
Label *string `json:"label,omitempty"`
|
||||
PlantedAt *string `json:"plantedAt,omitempty"`
|
||||
RemovedAt *string `json:"removedAt,omitempty"`
|
||||
Version int64 `json:"version"`
|
||||
CreatedAt string `json:"createdAt"`
|
||||
UpdatedAt string `json:"updatedAt"`
|
||||
// SeedLotID attributes this planting to a purchase, so a lot can report what
|
||||
// is left. Nullable: most plantings never name a lot, and retiring a lot sets
|
||||
// this back to NULL rather than destroying planting history.
|
||||
SeedLotID *int64 `json:"seedLotId,omitempty"`
|
||||
Version int64 `json:"version"`
|
||||
CreatedAt string `json:"createdAt"`
|
||||
UpdatedAt string `json:"updatedAt"`
|
||||
|
||||
// DerivedCount is the plant count implied by the plop's area and the plant's
|
||||
// mature spacing: max(1, round(π·r² / spacing²)). It is computed by the
|
||||
|
||||
Reference in New Issue
Block a user