Add ingredient and license tables

This commit is contained in:
Roland Geider
2026-03-14 17:38:38 +01:00
parent b106090004
commit 997e4afa99
7 changed files with 3395 additions and 53 deletions

View File

@@ -20,20 +20,22 @@ import 'package:drift/drift.dart';
import 'package:drift_sqlite_async/drift_sqlite_async.dart';
import 'package:flutter/material.dart' show TimeOfDay;
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:powersync/powersync.dart' show uuid;
import 'package:powersync/powersync.dart' as ps;
import 'package:wger/database/converters/int_to_string_converter.dart';
import 'package:wger/database/converters/time_of_day_converter.dart';
import 'package:wger/models/body_weight/weight_entry.dart';
import 'package:wger/models/core/language.dart';
import 'package:wger/models/core/license.dart';
import 'package:wger/models/exercises/category.dart';
import 'package:wger/models/exercises/equipment.dart';
import 'package:wger/models/exercises/exercise.dart';
import 'package:wger/models/exercises/image.dart';
import 'package:wger/models/exercises/language.dart';
import 'package:wger/models/exercises/muscle.dart';
import 'package:wger/models/exercises/translation.dart';
import 'package:wger/models/exercises/video.dart';
import 'package:wger/models/measurements/measurement_category.dart';
import 'package:wger/models/nutrition/ingredient.dart';
import 'package:wger/models/nutrition/ingredient_image.dart';
import 'package:wger/models/workouts/log.dart';
import 'package:wger/models/workouts/repetition_unit.dart';
import 'package:wger/models/workouts/session.dart';
@@ -42,7 +44,9 @@ import 'package:wger/models/workouts/weight_unit.dart';
import '../../models/measurements/measurement_entry.dart';
import 'powersync.dart';
import 'tables/exercise.dart';
import 'tables/ingredient.dart';
import 'tables/language.dart';
import 'tables/license.dart';
import 'tables/measurements.dart';
import 'tables/routines.dart';
import 'tables/weight.dart';
@@ -53,6 +57,7 @@ part 'database.g.dart';
tables: [
// Core
LanguageTable,
LicenseTable,
// Exercises
ExerciseTable,
@@ -66,14 +71,22 @@ part 'database.g.dart';
ExerciseImageTable,
ExerciseVideoTable,
// User data
// Body weight
WeightEntryTable,
// Measurements
MeasurementCategoryTable,
MeasurementEntryTable,
// Routines
WorkoutLogTable,
WorkoutSessionTable,
RoutineRepetitionUnitTable,
RoutineWeightUnitTable,
// Nutrition
IngredientTable,
IngredientImageTable,
],
//include: {'queries.drift'},
)

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,84 @@
/*
* This file is part of wger Workout Manager <https://github.com/wger-project>.
* Copyright (c) 2026 wger Team
*
* wger Workout Manager is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import 'package:drift/drift.dart';
import 'package:powersync/powersync.dart' as ps;
import 'package:wger/models/nutrition/ingredient.dart';
import 'package:wger/models/nutrition/ingredient_image.dart';
@UseRowClass(Ingredient)
class IngredientTable extends Table {
@override
String get tableName => 'nutrition_ingredient';
// Numerical id from the remote API
IntColumn get id => integer()();
// Local client UUID for sync purposes
TextColumn get uuid => text().clientDefault(() => ps.uuid.v4())();
// Other metadata
TextColumn get remoteId => text().nullable().named('remote_id')();
TextColumn get sourceName => text().nullable().named('source_name')();
TextColumn get sourceUrl => text().nullable().named('source_url')();
TextColumn get licenseObjectURl => text().named('license_object_url').nullable()();
// Product code / barcode
TextColumn get code => text().nullable()();
// Display name (required)
TextColumn get name => text()();
// Creation timestamp from server
DateTimeColumn get created => dateTime()();
// Energy and macronutrients
IntColumn get energy => integer()();
RealColumn get carbohydrates => real()();
RealColumn get carbohydratesSugar => real().named('carbohydrates_sugar')();
RealColumn get protein => real()();
RealColumn get fat => real()();
RealColumn get fatSaturated => real().named('fat_saturated')();
RealColumn get fiber => real()();
RealColumn get sodium => real()();
// Flags
BoolColumn get isVegan => boolean().withDefault(const Constant(false)).named('is_vegan')();
BoolColumn get isVegetarian =>
boolean().withDefault(const Constant(false)).named('is_vegetarian')();
}
@UseRowClass(IngredientImage)
class IngredientImageTable extends Table {
@override
String get tableName => 'nutrition_ingredientimage';
IntColumn get id => integer()();
TextColumn get uuid => text()();
IntColumn get ingredientId => integer().named('ingredient_id').references(IngredientTable, #id)();
TextColumn get url => text().named('image')();
IntColumn get size => integer()();
// License information
IntColumn get licenseId => integer().named('license')();
TextColumn get author => text().named('license_author')();
TextColumn get authorUrl => text().named('license_author_url')();
TextColumn get title => text().named('license_title')();
TextColumn get objectUrl => text().named('license_object_url')();
TextColumn get derivativeSourceUrl => text().named('license_derivative_source_url')();
}

View File

@@ -1,5 +1,23 @@
/*
* This file is part of wger Workout Manager <https://github.com/wger-project>.
* Copyright (c) 2026 wger Team
*
* wger Workout Manager is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import 'package:drift/drift.dart';
import 'package:wger/models/exercises/language.dart';
import 'package:wger/models/core/language.dart';
@UseRowClass(Language)
class LanguageTable extends Table {

View File

@@ -0,0 +1,31 @@
/*
* This file is part of wger Workout Manager <https://github.com/wger-project>.
* Copyright (c) 2020 - 2026 wger Team
*
* wger Workout Manager is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import 'package:drift/drift.dart';
import 'package:wger/models/core/license.dart';
@UseRowClass(License)
class LicenseTable extends Table {
@override
String get tableName => 'core_license';
IntColumn get id => integer()();
TextColumn get shortName => text().named('short_name')();
TextColumn get fullName => text().named('full_name')();
TextColumn get url => text()();
}