diff options
author | Stephen Finucane <stephen@that.guru> | 2018-05-19 03:42:18 +0100 |
---|---|---|
committer | Stephen Finucane <stephen@that.guru> | 2018-10-17 18:37:54 +0100 |
commit | 76505e910d7da46e94fb136cfcd299f29a30a138 (patch) | |
tree | 49e69c91ab872a89e89d6ad977c14447b5c4bc3e /lib/sql | |
parent | 8883380269e22c61c91159a31992f8806bc27c79 (diff) | |
download | patchwork-76505e910d7da46e94fb136cfcd299f29a30a138.tar patchwork-76505e910d7da46e94fb136cfcd299f29a30a138.tar.gz |
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>
Diffstat (limited to 'lib/sql')
-rw-r--r-- | lib/sql/grant-all.mysql.sql | 2 | ||||
-rw-r--r-- | lib/sql/grant-all.postgres.sql | 4 |
2 files changed, 0 insertions, 6 deletions
diff --git a/lib/sql/grant-all.mysql.sql b/lib/sql/grant-all.mysql.sql index ff96219..0277077 100644 --- a/lib/sql/grant-all.mysql.sql +++ b/lib/sql/grant-all.mysql.sql @@ -27,7 +27,6 @@ GRANT SELECT, UPDATE, INSERT, DELETE ON patchwork_patchtag TO 'www-data'@localho GRANT SELECT, UPDATE, INSERT, DELETE ON patchwork_person TO 'www-data'@localhost; GRANT SELECT, UPDATE, INSERT, DELETE ON patchwork_project TO 'www-data'@localhost; GRANT SELECT, UPDATE, INSERT, DELETE ON patchwork_series TO 'www-data'@localhost; -GRANT SELECT, UPDATE, INSERT, DELETE ON patchwork_seriespatch TO 'www-data'@localhost; GRANT SELECT, UPDATE, INSERT, DELETE ON patchwork_seriesreference TO 'www-data'@localhost; GRANT SELECT, UPDATE, INSERT, DELETE ON patchwork_state TO 'www-data'@localhost; GRANT SELECT, UPDATE, INSERT, DELETE ON patchwork_submission TO 'www-data'@localhost; @@ -42,7 +41,6 @@ GRANT INSERT, SELECT ON patchwork_coverletter TO 'nobody'@localhost; GRANT INSERT, SELECT ON patchwork_patch TO 'nobody'@localhost; GRANT INSERT, SELECT ON patchwork_person TO 'nobody'@localhost; GRANT INSERT, SELECT ON patchwork_series TO 'nobody'@localhost; -GRANT INSERT, SELECT ON patchwork_seriespatch TO 'nobody'@localhost; GRANT INSERT, SELECT ON patchwork_seriesreference TO 'nobody'@localhost; GRANT INSERT, SELECT ON patchwork_submission TO 'nobody'@localhost; GRANT INSERT, SELECT, UPDATE, DELETE ON patchwork_patchtag TO 'nobody'@localhost; diff --git a/lib/sql/grant-all.postgres.sql b/lib/sql/grant-all.postgres.sql index 27f55c9..8f500e9 100644 --- a/lib/sql/grant-all.postgres.sql +++ b/lib/sql/grant-all.postgres.sql @@ -27,7 +27,6 @@ GRANT SELECT, UPDATE, INSERT, DELETE ON patchwork_person, patchwork_project, patchwork_series, - patchwork_seriespatch, patchwork_seriesreference, patchwork_state, patchwork_submission, @@ -56,7 +55,6 @@ GRANT SELECT, UPDATE ON patchwork_person_id_seq, patchwork_project_id_seq, patchwork_series_id_seq, - patchwork_seriespatch_id_seq, patchwork_seriesreference_id_seq, patchwork_state_id_seq, patchwork_tag_id_seq, @@ -70,7 +68,6 @@ GRANT INSERT, SELECT ON patchwork_comment, patchwork_coverletter, patchwork_event - patchwork_seriespatch, patchwork_seriesreference, patchwork_submission, TO "nobody"; @@ -93,7 +90,6 @@ GRANT UPDATE, SELECT ON patchwork_patchtag_id_seq, patchwork_person_id_seq, patchwork_series_id_seq, - patchwork_seriespatch_id_seq, patchwork_seriesreference_id_seq, TO "nobody"; |