Self hosted FLOSS fitness/workout, nutrition and weight tracker
Merge branch 'feature/sync-variations' into feature/version-2.5
Roland Geider473b5c5185e6
diff --cc CHANGELOG.mdindex 1020c275d,3acf04fd6..1c20676e1--- a/CHANGELOG.md+++ b/CHANGELOG.md@@@ -25,7 -25,7 +25,13 @@@ timer or similar. The `setting-repetiti<https://github.com/wger-project/wger/issues/2124>Automatically read the date from uploaded image to the gallery.+ <https://github.com/wger-project/wger/pull/2292> Move the variation ID from an+ (empty) table to a field in the exercise model. This simplifies a lot of code+ and allows us to properly sync them to local instances as well.+ The API endpoint `/api/v2/variations/` API endpoint has been removed.+++++Improve serving size support for ingredients. Users can now log food in+everyday units like "1 Serving (2 biscuits)" or "1 Cup" instead of only grams,+with serving sizes automatically imported from Open Food Facts.+The `/api/v2/weightunit/` endpoint has been removed.diff --cc wger/exercises/migrations/0037_replace_variation_with_uuid_field.pyindex 000000000,60a183d09..f3f741f0cmode 000000,100644..100644--- a/wger/exercises/migrations/0037_replace_variation_with_uuid_field.py+++ b/wger/exercises/migrations/0037_replace_variation_with_uuid_field.py@@@ -1,0 -1,125 +1,125 @@@+ """+ Replace the Variation ForeignKey on Exercise with a UUID field.++ Exercises with the same variation_group UUID belong to the same group.+ The separate Variation model is no longer needed.++ Steps:+ 1. Add UUID field to Variation model (so we have something to copy)+ 2. Add variation_group UUIDField to Exercise+ 3. Copy Variation UUIDs to Exercise.variation_group+ 4. Remove FK + delete model+ """++ import uuid as uuid_mod++ from django.db import migrations, models+ from django.db.backends.base.schema import BaseDatabaseSchemaEditor+ from django.db.migrations.state import StateApps+++ def fix_sqlite_historical_indexes(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor):+ """+ Fix index name collision caused by migration 0032_rename_exercise.++ When RenameModel renamed HistoricalExercise -> HistoricalTranslation and+ HistoricalExerciseBase -> HistoricalExercise, SQLite did not rename the+ indexes. The old exercises_historicalexercise_* indexes remain on the+ historicaltranslation table, colliding with indexes Django tries to+ create for the new HistoricalExercise model.++ This only affects SQLite; PostgreSQL renames indexes correctly.+ """+ if schema_editor.connection.vendor == 'postgresql':+ return++ cursor = schema_editor.connection.cursor()++ if schema_editor.connection.vendor == 'sqlite':+ cursor.execute(+ "SELECT name FROM sqlite_master WHERE type='index' "+ "AND tbl_name='exercises_historicaltranslation' "+ "AND name LIKE 'exercises_historicalexercise_%'"+ )+ for (index_name,) in cursor.fetchall():+ cursor.execute(f'DROP INDEX IF EXISTS "{index_name}"')++ elif schema_editor.connection.vendor == 'mysql':+ cursor.execute(+ "SELECT INDEX_NAME FROM INFORMATION_SCHEMA.STATISTICS "+ "WHERE TABLE_NAME = 'exercises_historicaltranslation' "+ "AND INDEX_NAME LIKE 'exercises_historicalexercise_%%'"+ )+ for (index_name,) in cursor.fetchall():+ cursor.execute(+ f'DROP INDEX `{index_name}` ON `exercises_historicaltranslation`'+ )+++ def generate_variation_uuids(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor):+ """Generate UUIDs for existing Variation objects."""+ Variation = apps.get_model('exercises', 'Variation')+ for variation in Variation.objects.all():+ variation.uuid = uuid_mod.uuid4()+ variation.save(update_fields=['uuid'])+++ def copy_variation_uuids(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor):+ """Copy the UUID from each Variation object to the exercises that reference it."""+ Exercise = apps.get_model('exercises', 'Exercise')+ for exercise in Exercise.objects.filter(variations__isnull=False).select_related('variations'):+ exercise.variation_group = exercise.variations.uuid+ exercise.save(update_fields=['variation_group'])+++ class Migration(migrations.Migration):+ dependencies = [- ('exercises', '0035_add_is_ai_generated'),++ ('exercises', '0036_add_markdown_description_field'),+ ]++ operations = [+ migrations.RunPython(fix_sqlite_historical_indexes, migrations.RunPython.noop),++ # Temporarily add UUID to the variation table+ migrations.AddField(+ model_name='variation',+ name='uuid',+ field=models.UUIDField(null=True),+ ),+ migrations.RunPython(generate_variation_uuids, migrations.RunPython.noop),+ migrations.AddField(+ model_name='exercise',+ name='variation_group',+ field=models.UUIDField(+ blank=True,+ db_index=True,+ null=True,+ verbose_name='Variation group',+ ),+ ),+ migrations.AddField(+ model_name='historicalexercise',+ name='variation_group',+ field=models.UUIDField(+ blank=True,+ null=True,+ verbose_name='Variation group',+ ),+ ),++ # Copy data and remove FK relations+ migrations.RunPython(copy_variation_uuids, migrations.RunPython.noop),+ migrations.RemoveField(+ model_name='exercise',+ name='variations',+ ),+ migrations.RemoveField(+ model_name='historicalexercise',+ name='variations',+ ),++ # Cleanup+ migrations.DeleteModel(+ name='Variation',+ ),+ ]diff --cc wger/exercises/migrations/0038_sync_model_changes.pyindex 000000000,8b4088bc1..7f7df9f13mode 000000,100644..100644--- a/wger/exercises/migrations/0038_sync_model_changes.py+++ b/wger/exercises/migrations/0038_sync_model_changes.py@@@ -1,0 -1,211 +1,211 @@@+ # Generated by Django 5.2.13 on 2026-04-13 09:38++ import django.db.models.deletion+ import wger.exercises.models.image+ import wger.utils.images+ from django.db import migrations, models++ """+ This migration has no real changes, it just re-syncs every change from the models+ back, like help text changes and so.+ """+++ class Migration(migrations.Migration):+ dependencies = [- ('exercises', '0036_replace_variation_with_uuid_field'),++ ('exercises', '0037_replace_variation_with_uuid_field'),+ ]++ operations = [+ migrations.AlterField(+ model_name='deletionlog',+ name='replaced_by',+ field=models.UUIDField(+ default=None,+ editable=False,+ help_text='UUID of the object replaced by the deleted one. At the moment only available for exercises',+ null=True,+ verbose_name='Replaced by',+ ),+ ),+ migrations.AlterField(+ model_name='exercise',+ name='created',+ field=models.DateTimeField(auto_now_add=True, verbose_name='Creation date'),+ ),+ migrations.AlterField(+ model_name='exercise',+ name='last_update',+ field=models.DateTimeField(auto_now=True, verbose_name='last update'),+ ),+ migrations.AlterField(+ model_name='exercise',+ name='license_author',+ field=models.TextField(+ blank=True,+ help_text='If you are not the author, enter the name or source here.',+ max_length=3500,+ null=True,+ verbose_name='Author(s)',+ ),+ ),+ migrations.AlterField(+ model_name='exerciseimage',+ name='image',+ field=models.ImageField(+ height_field='height',+ help_text='Only JPEG, PNG and WebP formats are supported',+ upload_to=wger.exercises.models.image.exercise_image_upload_dir,+ validators=[wger.utils.images.validate_image_static_no_animation],+ verbose_name='Image',+ width_field='width',+ ),+ ),+ migrations.AlterField(+ model_name='exerciseimage',+ name='is_main',+ field=models.BooleanField(default=False, verbose_name='Is main picture'),+ ),+ migrations.AlterField(+ model_name='exerciseimage',+ name='license_author',+ field=models.TextField(+ blank=True,+ help_text='If you are not the author, enter the name or source here.',+ max_length=3500,+ null=True,+ verbose_name='Author(s)',+ ),+ ),+ migrations.AlterField(+ model_name='exercisevideo',+ name='is_main',+ field=models.BooleanField(default=False, verbose_name='Is main video'),+ ),+ migrations.AlterField(+ model_name='exercisevideo',+ name='license_author',+ field=models.TextField(+ blank=True,+ help_text='If you are not the author, enter the name or source here.',+ max_length=3500,+ null=True,+ verbose_name='Author(s)',+ ),+ ),+ migrations.AlterField(+ model_name='historicalexercise',+ name='created',+ field=models.DateTimeField(blank=True, editable=False, verbose_name='Creation date'),+ ),+ migrations.AlterField(+ model_name='historicalexercise',+ name='last_update',+ field=models.DateTimeField(blank=True, editable=False, verbose_name='last update'),+ ),+ migrations.AlterField(+ model_name='historicalexercise',+ name='license_author',+ field=models.TextField(+ blank=True,+ help_text='If you are not the author, enter the name or source here.',+ max_length=3500,+ null=True,+ verbose_name='Author(s)',+ ),+ ),+ migrations.AlterField(+ model_name='historicalexercise',+ name='variation_group',+ field=models.UUIDField(+ blank=True, db_index=True, null=True, verbose_name='Variation group'+ ),+ ),+ migrations.AlterField(+ model_name='historicalexerciseimage',+ name='image',+ field=models.TextField(+ help_text='Only JPEG, PNG and WebP formats are supported',+ max_length=100,+ validators=[wger.utils.images.validate_image_static_no_animation],+ verbose_name='Image',+ ),+ ),+ migrations.AlterField(+ model_name='historicalexerciseimage',+ name='is_main',+ field=models.BooleanField(default=False, verbose_name='Is main picture'),+ ),+ migrations.AlterField(+ model_name='historicalexerciseimage',+ name='license_author',+ field=models.TextField(+ blank=True,+ help_text='If you are not the author, enter the name or source here.',+ max_length=3500,+ null=True,+ verbose_name='Author(s)',+ ),+ ),+ migrations.AlterField(+ model_name='historicalexercisevideo',+ name='is_main',+ field=models.BooleanField(default=False, verbose_name='Is main video'),+ ),+ migrations.AlterField(+ model_name='historicalexercisevideo',+ name='license_author',+ field=models.TextField(+ blank=True,+ help_text='If you are not the author, enter the name or source here.',+ max_length=3500,+ null=True,+ verbose_name='Author(s)',+ ),+ ),+ migrations.AlterField(+ model_name='historicaltranslation',+ name='exercise',+ field=models.ForeignKey(+ blank=True,+ db_constraint=False,+ default=None,+ null=True,+ on_delete=django.db.models.deletion.DO_NOTHING,+ related_name='+',+ to='exercises.exercise',+ ),+ ),+ migrations.AlterField(+ model_name='historicaltranslation',+ name='license_author',+ field=models.TextField(+ blank=True,+ help_text='If you are not the author, enter the name or source here.',+ max_length=3500,+ null=True,+ verbose_name='Author(s)',+ ),+ ),+ migrations.AlterField(+ model_name='translation',+ name='exercise',+ field=models.ForeignKey(+ default=None,+ on_delete=django.db.models.deletion.CASCADE,+ related_name='translations',+ to='exercises.exercise',+ ),+ ),+ migrations.AlterField(+ model_name='translation',+ name='license_author',+ field=models.TextField(+ blank=True,+ help_text='If you are not the author, enter the name or source here.',+ max_length=3500,+ null=True,+ verbose_name='Author(s)',+ ),+ ),+ ]diff --cc wger/version.pyindex 4dfa31d95,9477399d8..d18c873ec--- a/wger/version.py+++ b/wger/version.py@@@ -32,10 -32,10 +32,10 @@@ Minimum version of the mobile app requiAlways use versions in the x.y.z format, without any suffixes like "beta1" or such."""- MIN_SERVER_VERSION = Version('2.4.0-alpha2')+ MIN_SERVER_VERSION = Version('2.4.0-alpha3')"""Minimum version of the server required to run sync commands on this server"""-VERSION = Version('2.5.0-alpha2')+VERSION = Version('2.5.0')"""Current version of the app"""