feat(plantare): reproduction-commitment data layer (schema v9)

The Plantare — a promise to reproduce seed and return some (data-model §2.7,
the seed-domain Pledge with return_kind=similar). NOT a sale. Local-first
v1: your honest ledger of commitments (from/to a person by name); the
bilateral signed cross-party form is a later social-layer phase.

- New Plantares table (SyncColumns): varietyId, direction (iReturn/owedToMe),
  counterparty, owedDescription, madeOn, dueBy, status (open/returned/
  forgiven), settledOn, note. schemaVersion 8 -> 9 with a guarded createTable
  migration; schema exported + migration-test helper regenerated.
- VarietyRepository: createPlantare / watchPlantares / watchPlantaresForVariety
  / setPlantareStatus / deletePlantare (soft-delete, CRDT-stamped).
- Included in backups + sync: InventorySnapshot + JSON codec (round-trips
  isDeleted) + exportInventory/exportForSync/importInventory, so commitments
  survive restore and replicate LWW like every other row.

Tests: v1..v8 -> v9 migration + fresh v9; repo create/list/settle/reopen/
delete; and a backup round-trip preserving a commitment. 13 green.

UI (detail section + Plantares screen) follows.
This commit is contained in:
vjrj 2026-07-11 02:01:25 +02:00
parent 0e41293de5
commit 81094f25a8
12 changed files with 5418 additions and 60 deletions

View file

@ -208,6 +208,28 @@ class InventoryJsonCodec {
'sortOrder': a.sortOrder,
},
],
'plantares': [
for (final p in snapshot.plantares)
{
..._syncMeta(
id: p.id,
createdAt: p.createdAt,
updatedAt: p.updatedAt,
lastAuthor: p.lastAuthor,
schemaRowVersion: p.schemaRowVersion,
isDeleted: p.isDeleted,
),
'varietyId': p.varietyId,
'direction': p.direction.name,
'counterparty': p.counterparty,
'owedDescription': p.owedDescription,
'madeOn': p.madeOn,
'dueBy': p.dueBy,
'status': p.status.name,
'settledOn': p.settledOn,
'note': p.note,
},
],
});
}
@ -418,6 +440,28 @@ class InventoryJsonCodec {
sortOrder: _int(m, 'sortOrder', fallback: 0),
);
}),
plantares: _rows(root, 'plantares', (m) {
return Plantare(
id: _string(m, 'id'),
createdAt: _int(m, 'createdAt'),
updatedAt: _string(m, 'updatedAt'),
lastAuthor: _string(m, 'lastAuthor'),
isDeleted: _bool(m, 'isDeleted'),
schemaRowVersion: _int(m, 'schemaRowVersion', fallback: 1),
varietyId: m['varietyId'] as String?,
direction:
_enumOr(PlantareDirection.values, m['direction'],
PlantareDirection.iReturn),
counterparty: m['counterparty'] as String?,
owedDescription: m['owedDescription'] as String?,
madeOn: _int(m, 'madeOn'),
dueBy: m['dueBy'] as int?,
status:
_enumOr(PlantareStatus.values, m['status'], PlantareStatus.open),
settledOn: m['settledOn'] as int?,
note: m['note'] as String?,
);
}),
);
}

View file

@ -30,6 +30,7 @@ class InventorySnapshot {
this.movements = const [],
this.parties = const [],
this.attachments = const [],
this.plantares = const [],
this.speciesNamesById = const {},
});
@ -42,6 +43,7 @@ class InventorySnapshot {
final List<Movement> movements;
final List<Party> parties;
final List<Attachment> attachments;
final List<Plantare> plantares;
/// speciesId scientificName, for the species referenced by [varieties].
final Map<String, String> speciesNamesById;