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()();
}

View File

@@ -0,0 +1,31 @@
/*
* 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:freezed_annotation/freezed_annotation.dart';
part 'license.freezed.dart';
@freezed
abstract class License with _$License {
const factory License({
required int id,
required String shortName,
required String fullName,
required String url,
}) = _License;
}

View File

@@ -0,0 +1,280 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
// coverage:ignore-file
// ignore_for_file: type=lint
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark
part of 'license.dart';
// **************************************************************************
// FreezedGenerator
// **************************************************************************
// dart format off
T _$identity<T>(T value) => value;
/// @nodoc
mixin _$License {
int get id; String get shortName; String get fullName; String get url;
/// Create a copy of License
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
$LicenseCopyWith<License> get copyWith => _$LicenseCopyWithImpl<License>(this as License, _$identity);
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is License&&(identical(other.id, id) || other.id == id)&&(identical(other.shortName, shortName) || other.shortName == shortName)&&(identical(other.fullName, fullName) || other.fullName == fullName)&&(identical(other.url, url) || other.url == url));
}
@override
int get hashCode => Object.hash(runtimeType,id,shortName,fullName,url);
@override
String toString() {
return 'License(id: $id, shortName: $shortName, fullName: $fullName, url: $url)';
}
}
/// @nodoc
abstract mixin class $LicenseCopyWith<$Res> {
factory $LicenseCopyWith(License value, $Res Function(License) _then) = _$LicenseCopyWithImpl;
@useResult
$Res call({
int id, String shortName, String fullName, String url
});
}
/// @nodoc
class _$LicenseCopyWithImpl<$Res>
implements $LicenseCopyWith<$Res> {
_$LicenseCopyWithImpl(this._self, this._then);
final License _self;
final $Res Function(License) _then;
/// Create a copy of License
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline') @override $Res call({Object? id = null,Object? shortName = null,Object? fullName = null,Object? url = null,}) {
return _then(_self.copyWith(
id: null == id ? _self.id : id // ignore: cast_nullable_to_non_nullable
as int,shortName: null == shortName ? _self.shortName : shortName // ignore: cast_nullable_to_non_nullable
as String,fullName: null == fullName ? _self.fullName : fullName // ignore: cast_nullable_to_non_nullable
as String,url: null == url ? _self.url : url // ignore: cast_nullable_to_non_nullable
as String,
));
}
}
/// Adds pattern-matching-related methods to [License].
extension LicensePatterns on License {
/// A variant of `map` that fallback to returning `orElse`.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case _:
/// return orElse();
/// }
/// ```
@optionalTypeArgs TResult maybeMap<TResult extends Object?>(TResult Function( _License value)? $default,{required TResult orElse(),}){
final _that = this;
switch (_that) {
case _License() when $default != null:
return $default(_that);case _:
return orElse();
}
}
/// A `switch`-like method, using callbacks.
///
/// Callbacks receives the raw object, upcasted.
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case final Subclass2 value:
/// return ...;
/// }
/// ```
@optionalTypeArgs TResult map<TResult extends Object?>(TResult Function( _License value) $default,){
final _that = this;
switch (_that) {
case _License():
return $default(_that);case _:
throw StateError('Unexpected subclass');
}
}
/// A variant of `map` that fallback to returning `null`.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case _:
/// return null;
/// }
/// ```
@optionalTypeArgs TResult? mapOrNull<TResult extends Object?>(TResult? Function( _License value)? $default,){
final _that = this;
switch (_that) {
case _License() when $default != null:
return $default(_that);case _:
return null;
}
}
/// A variant of `when` that fallback to an `orElse` callback.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case _:
/// return orElse();
/// }
/// ```
@optionalTypeArgs TResult maybeWhen<TResult extends Object?>(TResult Function( int id, String shortName, String fullName, String url)? $default,{required TResult orElse(),}) {final _that = this;
switch (_that) {
case _License() when $default != null:
return $default(_that.id,_that.shortName,_that.fullName,_that.url);case _:
return orElse();
}
}
/// A `switch`-like method, using callbacks.
///
/// As opposed to `map`, this offers destructuring.
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case Subclass2(:final field2):
/// return ...;
/// }
/// ```
@optionalTypeArgs TResult when<TResult extends Object?>(TResult Function( int id, String shortName, String fullName, String url) $default,) {final _that = this;
switch (_that) {
case _License():
return $default(_that.id,_that.shortName,_that.fullName,_that.url);case _:
throw StateError('Unexpected subclass');
}
}
/// A variant of `when` that fallback to returning `null`
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case _:
/// return null;
/// }
/// ```
@optionalTypeArgs TResult? whenOrNull<TResult extends Object?>(TResult? Function( int id, String shortName, String fullName, String url)? $default,) {final _that = this;
switch (_that) {
case _License() when $default != null:
return $default(_that.id,_that.shortName,_that.fullName,_that.url);case _:
return null;
}
}
}
/// @nodoc
class _License implements License {
const _License({required this.id, required this.shortName, required this.fullName, required this.url});
@override final int id;
@override final String shortName;
@override final String fullName;
@override final String url;
/// Create a copy of License
/// with the given fields replaced by the non-null parameter values.
@override @JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
_$LicenseCopyWith<_License> get copyWith => __$LicenseCopyWithImpl<_License>(this, _$identity);
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is _License&&(identical(other.id, id) || other.id == id)&&(identical(other.shortName, shortName) || other.shortName == shortName)&&(identical(other.fullName, fullName) || other.fullName == fullName)&&(identical(other.url, url) || other.url == url));
}
@override
int get hashCode => Object.hash(runtimeType,id,shortName,fullName,url);
@override
String toString() {
return 'License(id: $id, shortName: $shortName, fullName: $fullName, url: $url)';
}
}
/// @nodoc
abstract mixin class _$LicenseCopyWith<$Res> implements $LicenseCopyWith<$Res> {
factory _$LicenseCopyWith(_License value, $Res Function(_License) _then) = __$LicenseCopyWithImpl;
@override @useResult
$Res call({
int id, String shortName, String fullName, String url
});
}
/// @nodoc
class __$LicenseCopyWithImpl<$Res>
implements _$LicenseCopyWith<$Res> {
__$LicenseCopyWithImpl(this._self, this._then);
final _License _self;
final $Res Function(_License) _then;
/// Create a copy of License
/// with the given fields replaced by the non-null parameter values.
@override @pragma('vm:prefer-inline') $Res call({Object? id = null,Object? shortName = null,Object? fullName = null,Object? url = null,}) {
return _then(_License(
id: null == id ? _self.id : id // ignore: cast_nullable_to_non_nullable
as int,shortName: null == shortName ? _self.shortName : shortName // ignore: cast_nullable_to_non_nullable
as String,fullName: null == fullName ? _self.fullName : fullName // ignore: cast_nullable_to_non_nullable
as String,url: null == url ? _self.url : url // ignore: cast_nullable_to_non_nullable
as String,
));
}
}
// dart format on