diff --git a/HISTORY.rst b/HISTORY.rst index 677bc150bc..6f7c1d0d11 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -1,3 +1,11 @@ +3.1.8 (2018-10-XX) +================== +* Reorganize documentation into topics and chapters. +* Add Workflows and API chapters. +* Add new material from the Wiki to the documentation. +* Add data migrations to the sources app migraton 0019 to ensure all labels + are unique before performing the schema migations. + 3.1.7 (2018-10-14) ================== * Fix an issue with some browsers not firing the .load event on cached diff --git a/mayan/apps/sources/migrations/0019_auto_20180803_0440.py b/mayan/apps/sources/migrations/0019_auto_20180803_0440.py index 4686d5107a..fdfb39b667 100644 --- a/mayan/apps/sources/migrations/0019_auto_20180803_0440.py +++ b/mayan/apps/sources/migrations/0019_auto_20180803_0440.py @@ -5,6 +5,28 @@ from __future__ import unicode_literals from django.db import migrations, models +def make_labels_unique(apps, schema_editor): + Source = apps.get_model('sources', 'Source') + + for source in Source.objects.using(schema_editor.connection.alias).all(): + # Look for sources with the same label + duplicate_queryset = Source.objects.using(schema_editor.connection.alias).filter(label=source.label).exclude(pk=source.pk) + if duplicate_queryset: + # If a duplicate is found, append the id to the original source + # label + source.label = '{}__{}'.format(source.label, source.pk) + source.save() + + +def make_labels_unique_reverse(apps, schema_editor): + Source = apps.get_model('sources', 'Source') + + for source in Source.objects.using(schema_editor.connection.alias).all(): + if source.label.endswith('__{}'.format(source.pk)): + source.label = source.label.replace('__{}'.format(source.pk), '') + source.save() + + class Migration(migrations.Migration): dependencies = [ @@ -12,6 +34,9 @@ class Migration(migrations.Migration): ] operations = [ + migrations.RunPython( + make_labels_unique, reverse_code=make_labels_unique_reverse + ), migrations.AlterField( model_name='source', name='label',