import 'package:drift/drift.dart'; import 'enums.dart'; import 'tables.dart'; part 'database.g.dart'; /// The encrypted local inventory database (SQLCipher via an injected executor). /// /// The executor is passed in so production wires SQLCipher while tests can use /// an in-memory database — the schema and queries are identical either way. @DriftDatabase( tables: [ Varieties, VarietyVernacularNames, Species, SpeciesCommonNames, Lots, GerminationTests, Movements, Parties, Attachments, ExternalLinks, ], ) class AppDatabase extends _$AppDatabase { AppDatabase(super.e); /// Current schema version; also stamped into interchange exports so an /// importer knows which app generation wrote the file (data-model §7). static const int currentSchemaVersion = 5; @override int get schemaVersion => currentSchemaVersion; @override MigrationStrategy get migration => MigrationStrategy( onCreate: (m) async => m.createAll(), onUpgrade: (m, from, to) async { // v2: lots can hold seeds or living plant material. if (from < 2) { await m.addColumn(lots, lots.type); } // v3: optional harvest month alongside the harvest year. if (from < 3) { await m.addColumn(lots, lots.harvestMonth); } // v4: optional packaging/supply form for living lots. if (from < 4) { await m.addColumn(lots, lots.presentation); } // v5: display order for attachments (cover photo = lowest sortOrder). if (from < 5) { await m.addColumn(attachments, attachments.sortOrder); } }, ); }