@@ -6,6 +6,13 @@ from django.utils import six
def merge_duplicate_series(apps, schema_editor):
+ Project = apps.get_model('patchwork', 'Project')
+
+ for project in Project.objects.values('id'):
+ _merge_duplicate_series(apps, schema_editor, project=project['id'])
+
+
+def _merge_duplicate_series(apps, schema_editor, project):
SeriesReference = apps.get_model('patchwork', 'SeriesReference')
Patch = apps.get_model('patchwork', 'Patch')
@@ -14,9 +21,10 @@ def merge_duplicate_series(apps, schema_editor):
# find all SeriesReference that share a msgid but point to different series
# and decide which of the series is going to be the authoritative one
msgid_counts = (
- SeriesReference.objects.values('msgid')
+ SeriesReference.objects.filter(series__project_id=project)
.annotate(count=Count('msgid'))
.filter(count__gt=1)
+ .values('msgid')
)
for msgid_count in msgid_counts:
msgid = msgid_count['msgid']
We shouldn't attempt to merge series associated with different projects. Signed-off-by: Stephen Finucane <stephen@that.guru> Related: #340 --- v2: - Use 'project' value from 'SeriesReference.series', not 'SeriesReference' --- patchwork/migrations/0039_unique_series_references.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)