Rework quantities the way seeds are actually described — a number of an informal
unit — and let a lot hold seeds or plants (plantel).
Quantity model (commons_core):
- Quantity is now { kind, count?, label } — "3 cobs", "2 packets", "a few".
Count is optional; uncountable vibes (a few, some, pinch) carry no number.
- QuantityKind reorganised into an ascending scale: vibes → containers
(teaspoon/spoon/cup/jar/sack) → seed & fruit forms → plant units, each tagged
countable/not. Stored by name; count reuses the existing numeric column.
Lot type (schema v2):
- Lots gain a `type` (seed | plant); germination stays meaningful for seeds.
schemaVersion 2 with a from1To2 migration (adds the column), drift_schema_v2
exported, migration test covers v1→v2.
UI:
- New QuantityPicker: a horizontal scale of large seed-glyph icons + a number
stepper (shown only for countable units), plus a seed/plant SegmentedButton.
Used in quick-add and add-lot. Lot lines render "3 cobs" / "a few".
- i18n: unit singular/plural (ES/EN, Weblate-friendly), lot-type labels.
Build: slang moved to its CLI (disabled in build_runner to avoid a multi-file
collision); CI runs `dart run slang` before build_runner. 38 tests green,
Linux migrates the existing v1 DB and runs.
109 lines
4.6 KiB
Dart
109 lines
4.6 KiB
Dart
import 'package:drift/drift.dart';
|
|
|
|
import 'enums.dart';
|
|
import 'sync_columns.dart';
|
|
|
|
/// The identity/accession — one row per distinct thing in the inventory.
|
|
/// Only [label] is mandatory (progressive disclosure).
|
|
class Varieties extends Table with SyncColumns {
|
|
TextColumn get label => text()();
|
|
TextColumn get speciesId => text().nullable()(); // → Species
|
|
TextColumn get cultivarName => text().nullable()();
|
|
TextColumn get category =>
|
|
text().nullable()(); // free text, prefilled from family
|
|
TextColumn get notes => text().nullable()();
|
|
}
|
|
|
|
/// The multiple common names of a Variety (separate table so concurrent adds
|
|
/// merge as a set).
|
|
class VarietyVernacularNames extends Table with SyncColumns {
|
|
TextColumn get varietyId => text()();
|
|
TextColumn get name => text()();
|
|
TextColumn get language => text().nullable()();
|
|
TextColumn get region => text().nullable()();
|
|
}
|
|
|
|
/// Bundled, mostly read-only name catalog (Wikidata CC0 + GBIF CC-BY).
|
|
class Species extends Table with SyncColumns {
|
|
TextColumn get scientificName => text()();
|
|
TextColumn get wikidataQid => text().nullable()();
|
|
IntColumn get gbifKey => integer().nullable()();
|
|
TextColumn get family => text().nullable()();
|
|
BoolColumn get isBundled => boolean().withDefault(const Constant(false))();
|
|
}
|
|
|
|
/// Localized common names for the catalog (bundled).
|
|
class SpeciesCommonNames extends Table with SyncColumns {
|
|
TextColumn get speciesId => text()();
|
|
TextColumn get name => text()();
|
|
TextColumn get language => text().nullable()();
|
|
}
|
|
|
|
/// A homogeneous batch held for a Variety — its own year and its own unit.
|
|
/// Quantity (commons_core value type) is flattened into columns here.
|
|
class Lots extends Table with SyncColumns {
|
|
TextColumn get varietyId => text()();
|
|
TextColumn get type =>
|
|
textEnum<LotType>().withDefault(const Constant('seed'))();
|
|
IntColumn get harvestYear => integer().nullable()();
|
|
TextColumn get quantityKind => text().nullable()(); // QuantityKind.name
|
|
RealColumn get quantityPrecise => real().nullable()();
|
|
TextColumn get quantityLabel => text().nullable()();
|
|
TextColumn get storageLocation => text().nullable()();
|
|
TextColumn get offerStatus =>
|
|
textEnum<OfferStatus>().withDefault(const Constant('private'))();
|
|
TextColumn get seedbankId => text().nullable()();
|
|
}
|
|
|
|
/// Optional germination history for a Lot; percent is derived in code.
|
|
class GerminationTests extends Table with SyncColumns {
|
|
TextColumn get lotId => text()();
|
|
IntColumn get testedOn => integer().nullable()(); // date, ms since epoch
|
|
IntColumn get sampleSize => integer().nullable()();
|
|
IntColumn get germinatedCount => integer().nullable()();
|
|
TextColumn get notes => text().nullable()();
|
|
}
|
|
|
|
/// The append-only event log on a Lot — history + provenance DAG.
|
|
class Movements extends Table with AppendOnlyColumns {
|
|
TextColumn get lotId => text()();
|
|
TextColumn get type => textEnum<MovementType>()();
|
|
IntColumn get occurredOn => integer().nullable()(); // date, ms since epoch
|
|
TextColumn get counterpartyId => text().nullable()(); // → Party
|
|
TextColumn get quantityKind => text().nullable()();
|
|
RealColumn get quantityPrecise => real().nullable()();
|
|
TextColumn get quantityLabel => text().nullable()();
|
|
TextColumn get parentMovementId => text().nullable()(); // provenance DAG
|
|
TextColumn get plantareId => text().nullable()(); // reserved (social layer)
|
|
TextColumn get notes => text().nullable()();
|
|
}
|
|
|
|
/// A person or collective you exchange with.
|
|
class Parties extends Table with SyncColumns {
|
|
TextColumn get displayName => text()();
|
|
TextColumn get publicKey => text().nullable()();
|
|
TextColumn get kind =>
|
|
textEnum<PartyKind>().withDefault(const Constant('person'))();
|
|
TextColumn get note => text().nullable()();
|
|
}
|
|
|
|
/// Photos/docs. Polymorphic parent. Photo bytes are stored in-DB (encrypted at
|
|
/// rest by SQLCipher) via [bytes]; external files use [uri]. Storing bytes here
|
|
/// keeps the "no plaintext at rest" rule for photos in Block 1; an external
|
|
/// encrypted file store is a later optimization.
|
|
class Attachments extends Table with SyncColumns {
|
|
TextColumn get parentType => textEnum<ParentType>()();
|
|
TextColumn get parentId => text()();
|
|
TextColumn get kind => textEnum<AttachmentKind>()();
|
|
TextColumn get uri => text().nullable()();
|
|
BlobColumn get bytes => blob().nullable()();
|
|
TextColumn get mimeType => text().nullable()();
|
|
}
|
|
|
|
/// Any pasted URL (Wikipedia, forum…). Polymorphic parent.
|
|
class ExternalLinks extends Table with SyncColumns {
|
|
TextColumn get parentType => textEnum<ParentType>()();
|
|
TextColumn get parentId => text()();
|
|
TextColumn get url => text()();
|
|
TextColumn get title => text().nullable()();
|
|
}
|