feat(bibliotheque): tags et duplication profonde

Ticket #83 B1-B3 : tags JSON dénormalisés, migration Drift v19, mappings sync, helpers de filtre/suggestions, duplication profonde Program/WorkoutTemplate, tests associés.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-07-22 10:01:31 +02:00
parent 10fba8d2ec
commit add5025dd2
9 changed files with 1012 additions and 10 deletions

View File

@ -48,7 +48,7 @@ final class AppDatabase extends _$AppDatabase {
}
@override
int get schemaVersion => 18;
int get schemaVersion => 19;
@override
MigrationStrategy get migration {
@ -116,6 +116,9 @@ final class AppDatabase extends _$AppDatabase {
if (from < 17) {
await _migrateToSchema17();
}
if (from < 19) {
await _migrateToSchema19();
}
await _createIndexes();
},
beforeOpen: (details) async {
@ -746,6 +749,27 @@ CREATE TABLE IF NOT EXISTS active_set_timer_states (
await _backfillWorkoutHistoryStepSourceExerciseIds();
}
Future<void> _migrateToSchema19() async {
await _addColumnIfMissing(
tableName: 'exercises',
columnName: 'tags_json',
definition:
"tags_json TEXT NOT NULL DEFAULT '[]' CHECK (json_valid(tags_json))",
);
await _addColumnIfMissing(
tableName: 'programs',
columnName: 'tags_json',
definition:
"tags_json TEXT NOT NULL DEFAULT '[]' CHECK (json_valid(tags_json))",
);
await _addColumnIfMissing(
tableName: 'workout_templates',
columnName: 'tags_json',
definition:
"tags_json TEXT NOT NULL DEFAULT '[]' CHECK (json_valid(tags_json))",
);
}
Future<void> _backfillWorkoutHistorySetSourceExerciseIds() async {
await customStatement(r'''
UPDATE workout_history_set_results AS result