]> git.ipfire.org Git - thirdparty/patchwork.git/commit
models: Use database constraints to prevent split Series
authorStephen Finucane <stephen@that.guru>
Sun, 1 Dec 2019 17:10:43 +0000 (17:10 +0000)
committerStephen Finucane <stephen@that.guru>
Fri, 27 Dec 2019 13:21:03 +0000 (13:21 +0000)
commit9f72eb793dfb6e9d7ff54465d4b07291e9a75e38
treeea75b3298bcd616c3686fee1d340de59b49fc30f
parent757b33fa606aa7fcf3d2aafc1a6c2297fe3c9e3d
models: Use database constraints to prevent split Series

Currently, the 'SeriesReference' object has a unique constraint on the
two fields it has, 'series', which is a foreign key to 'Series', and
'msgid'. This is the wrong constraint. What we actually want to enforce
is that a patch, cover letter or comment is referenced by a single
series, or rather a single series per project the submission appears on.
As such, we should be enforcing uniqueness on the msgid and the project
that the patch, cover letter or comment belongs to.

This requires adding a new field to the object, 'project', since it's
not possible to do something like the following:

  unique_together = [('msgid', 'series__project')]

This is detailed here [1]. In addition, the migration needs a precursor
migration step to merge any broken series.

[1] https://stackoverflow.com/a/4440189/613428

Signed-off-by: Stephen Finucane <stephen@that.guru>
Closes: #241
Cc: Daniel Axtens <dja@axtens.net>
Cc: Petr Vorel <petr.vorel@gmail.com>
patchwork/migrations/0039_unique_series_references.py [new file with mode: 0644]
patchwork/models.py
patchwork/parser.py
patchwork/tests/test_parser.py
patchwork/tests/utils.py