summaryrefslogtreecommitdiff
path: root/patchwork/migrations
diff options
context:
space:
mode:
authorStephen Finucane <stephen@that.guru>2017-01-06 15:51:05 +0000
committerStephen Finucane <stephen@that.guru>2017-01-22 21:36:24 +0000
commite3cbe4939b6589631d962a51469ab5b550d58e92 (patch)
treef0066090157a635a2b0a89f6e518853f0001b7d3 /patchwork/migrations
parentb3869768ab9667c542434eb7e4ca5ddda703d8a6 (diff)
downloadpatchwork-e3cbe4939b6589631d962a51469ab5b550d58e92.tar
patchwork-e3cbe4939b6589631d962a51469ab5b550d58e92.tar.gz
models: Add 'project' field to Series
This is helpful for filtering. We use RunPython because folks are likely to have few if any Series objects existing yet. In addition, we update the unique constraints for SeriesReference as it's now possible to handle messages with duplicate message IDs. The update is included in parser to ensure this applies immediately. Signed-off-by: Stephen Finucane <stephen@that.guru> Reviewed-by: Andy Doan <andy.doan@linaro.org>
Diffstat (limited to 'patchwork/migrations')
-rw-r--r--patchwork/migrations/0016_series_project.py48
1 files changed, 48 insertions, 0 deletions
diff --git a/patchwork/migrations/0016_series_project.py b/patchwork/migrations/0016_series_project.py
new file mode 100644
index 0000000..ecd8984
--- /dev/null
+++ b/patchwork/migrations/0016_series_project.py
@@ -0,0 +1,48 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+def copy_series_field(apps, schema_editor):
+ """Populate the project field from child cover letter/patches."""
+ # TODO(stephenfin): Perhaps we'd like to include an SQL variant of the
+ # below though I'd imagine it would be rather tricky
+ Series = apps.get_model('patchwork', 'Series')
+
+ for series in Series.objects.all():
+ if series.cover_letter:
+ series.project = series.cover_letter.project
+ series.save()
+ elif series.patches:
+ series.project = series.patches.first().project
+ series.save()
+ else:
+ # a series without patches or cover letters should not exist.
+ # Delete it.
+ series.delete()
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('patchwork', '0015_add_series_models'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='series',
+ name='project',
+ field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='series', to='patchwork.Project'),
+ ),
+ migrations.RunPython(copy_series_field, migrations.RunPython.noop),
+ migrations.AlterField(
+ model_name='seriesreference',
+ name='msgid',
+ field=models.CharField(max_length=255),
+ ),
+ migrations.AlterUniqueTogether(
+ name='seriesreference',
+ unique_together=set([('series', 'msgid')]),
+ ),
+ ]