]> git.ipfire.org Git - thirdparty/patchwork.git/commit
models: Convert Series-Patch relationship to 1:N
authorStephen Finucane <stephen@that.guru>
Sat, 19 May 2018 02:42:18 +0000 (03:42 +0100)
committerStephen Finucane <stephen@that.guru>
Wed, 17 Oct 2018 17:37:54 +0000 (18:37 +0100)
commit76505e910d7da46e94fb136cfcd299f29a30a138
tree49e69c91ab872a89e89d6ad977c14447b5c4bc3e
parent8883380269e22c61c91159a31992f8806bc27c79
models: Convert Series-Patch relationship to 1:N

Late in the development of the series feature, it was decided that there
were advantages to allowing an N:M relationship between series and
patches. This would allow us to do things like create complete series
where a sole vN patch was sent to a list rather than the full series.
After some time using series in the wild, it's apparent that such
features are very difficult to implement correctly and will likely never
be implemented. As such, it's time to start cleaning up the mess, paving
the way for things like an improved tagging feature.

There are some significant changes to the model required:

- models.py, migrations/0027, migrations/0028, migrations/0029

  The migrations make the following changes:

  1. - Add 'Patch.series_alt' and 'Patch.number' fields.
  2. - Populate the 'Patch.series_alt' and 'Patch.number' fields from
       their 'SeriesPatch' equivalents.
  3. - Remove the 'SeriesPatch' model.
     - Rename 'Patch.series_alt' to 'Patch.series'.
     - Change 'Series.cover_letter' to a 'OneToOneField' since a cover
       letter can no longer be assigned to multiple series.

  Note that the migrations have to be split into multiple parts as the
  combined migration raises an OperationalError as below.

    (1072, "Key column 'series_alt_id' doesn't exist in table")

  This is due to Django's penchant for creating indexes for newly
  created fields, as noted here: https://stackoverflow.com/q/35158530/

Aside from the model changes, there are numerous other changes required:

- admin.py

  Reflect model changes for the 'PatchInline' inline used by
  'SeriesAdmin'

- api/cover.py, api/patch.py

  Update the 'series' field for the cover letter and patch resources to
  reflect the model changes. A 'to_representation' function is added in
  both cases to post-process this field and make it look like a list
  again. This is necessary to avoid breaking clients.

- parser.py

  Update to reflect the replacement of 'SeriesPatch' with 'Patch'.

- signals.py

  Update to filter on changes to 'Patch' instead of 'SeriesPatch'. This
  requires some reworking due to how we set these fields now, as we can
  no longer receive on 'post_save' signals for 'SeriesPatch' and must
  instead watch for 'pre_save' on 'Patch', which is what we do for
  delegate and state changes on same.

- templates/patchwork/*.html

  Remove logic that handled multiple series in favour of the (simpler)
  single series logic.

- tests/*

  Modify the 'create_series_patch' helper to reflect the removal of the
  'SeriesPatch' model. This entire helper will be removed in a future
  change. Improve some tests to cover edge cases that were highlighted
  during development

Unfortunately, all of the above changes must go in at the same time,
otherwise we end up with either (a) broken views, API etc. or (b) split
brain because we need to keep the new single-series fields alongside the
older multi-series fields and models while we rework the views. It's
unfortunate but there's not much to be done here.

Signed-off-by: Stephen Finucane <stephen@that.guru>
Tested-by: Daniel Axtens <dja@axtens.net>
21 files changed:
lib/sql/grant-all.mysql.sql
lib/sql/grant-all.postgres.sql
patchwork/admin.py
patchwork/api/cover.py
patchwork/api/patch.py
patchwork/migrations/0031_add_patch_series_fields.py [new file with mode: 0644]
patchwork/migrations/0032_migrate_data_from_series_patch_to_patch.py [new file with mode: 0644]
patchwork/migrations/0033_remove_patch_series_model.py [new file with mode: 0644]
patchwork/models.py
patchwork/parser.py
patchwork/signals.py
patchwork/templates/patchwork/partials/download-buttons.html
patchwork/templates/patchwork/partials/patch-list.html
patchwork/templates/patchwork/submission.html
patchwork/tests/test_detail.py
patchwork/tests/test_events.py
patchwork/tests/test_series.py
patchwork/tests/utils.py
patchwork/views/cover.py
patchwork/views/patch.py
patchwork/views/utils.py