-
Notifications
You must be signed in to change notification settings - Fork 6
Bugfix: adjust MobileApp.package_version (str) to be compatible with Report.package_version (int) #314
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bugfix: adjust MobileApp.package_version (str) to be compatible with Report.package_version (int) #314
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| # Generated by Django 3.2.25 on 2025-08-22 08:18 | ||
|
|
||
| from django.db import migrations | ||
| import django.core.validators | ||
| import re | ||
| import semantic_version | ||
| import semantic_version.django_fields | ||
| from semantic_version import Version | ||
|
|
||
|
|
||
| def force_semantic_version(apps, schema_editor): | ||
| MobileApp = apps.get_model('tigaserver_app', 'MobileApp') | ||
|
|
||
| obj_to_update = [] | ||
| for mobile_app in MobileApp.objects.iterator(): | ||
| if not semantic_version.validate(mobile_app.package_version): | ||
| if '.' in mobile_app.package_version: | ||
| mobile_app.package_version = Version.coerce(mobile_app.package_version) | ||
| else: | ||
| # NOTE: this must be the same as in Report.save when doing the MobileApp.objects.get_or_create | ||
| mobile_app.package_version = Version( | ||
| major=0, | ||
| minor=int(mobile_app.package_version), | ||
| patch=0, | ||
| build=('legacy',) | ||
| ) | ||
| obj_to_update.append(mobile_app) | ||
|
|
||
| MobileApp.objects.bulk_update(obj_to_update, ['package_version'], batch_size=2000) | ||
|
|
||
| def undo_force_semantic_version(apps, schema_editor): | ||
| MobileApp = apps.get_model('tigaserver_app', 'MobileApp') | ||
|
|
||
| obj_to_update = [] | ||
| for mobile_app in MobileApp.objects.filter(package_version__contains='legacy').iterator(): | ||
| mobile_app.package_version = str(Version.coerce(mobile_app.package_version).minor) | ||
| obj_to_update.append(mobile_app) | ||
epou marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| MobileApp.objects.bulk_update(obj_to_update, ['package_version'], batch_size=2000) | ||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| ('tigaserver_app', '0083_europecountry_reports_can_be_published'), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.RunPython(force_semantic_version, undo_force_semantic_version), | ||
| migrations.AlterField( | ||
| model_name='mobileapp', | ||
| name='package_version', | ||
| field=semantic_version.django_fields.VersionField(coerce=False, max_length=32, partial=False, validators=[django.core.validators.RegexValidator(code='invalid_version', regex=re.compile('^(\\d+)\\.(\\d+)\\.(\\d+)(?:-([0-9a-zA-Z.-]+))?(?:\\+([0-9a-zA-Z.-]+))?$'))]), | ||
| ), | ||
| ] | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -22,6 +22,7 @@ | |||||
| from django.contrib.gis.db.models.functions import Distance as DistanceFunction | ||||||
| from django.contrib.gis.geos import GEOSGeometry | ||||||
| from django.contrib.gis.measure import Distance as DistanceMeasure | ||||||
| from django.core.validators import RegexValidator | ||||||
| from django.db import transaction | ||||||
| from django.db.models import Count, Q | ||||||
| from django.db.models.signals import post_save | ||||||
|
|
@@ -36,6 +37,8 @@ | |||||
| from fcm_django.models import AbstractFCMDevice, DeviceType | ||||||
| from imagekit.processors import ResizeToFit | ||||||
| from langcodes import Language, closest_supported_match, standardize_tag as standarize_language_tag, tag_is_valid as language_tag_is_valid | ||||||
| from semantic_version import Version | ||||||
| from semantic_version.django_fields import VersionField | ||||||
| from simple_history.models import HistoricalRecords | ||||||
| from timezone_field import TimeZoneField | ||||||
| from taggit.managers import TaggableManager | ||||||
|
|
@@ -333,8 +336,16 @@ class Meta: | |||||
|
|
||||||
|
|
||||||
| class MobileApp(models.Model): | ||||||
| # NOTE: At some point we should adjust the package_version which 'build' value is 'legacy' | ||||||
| # since this version were creating from Report.package_version (which is an IntegerField) | ||||||
| # and it's a number which is not related with the Mobile App pubspeck.yaml package version. | ||||||
| package_name = models.CharField(max_length=128) | ||||||
| package_version = models.CharField(max_length=32) | ||||||
| package_version = VersionField(max_length=32, validators=[ | ||||||
| RegexValidator( | ||||||
| regex=Version.version_re, | ||||||
| code='invalid_version' | ||||||
| ) | ||||||
| ]) | ||||||
|
||||||
| ]) | |
| package_version = VersionField(max_length=32) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's not exactly true... It has an python validator but not a django validator, which is interesting to, for example, raise ValidationError correctly in the API (compatible with DRF)
Uh oh!
There was an error while loading. Please reload this page.