diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 7a7c72b99efa204b0fac0d67031a938f904a554d..d941adfc7556c5852b631f792ec0ad2a3ca1aac2 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -13,6 +13,7 @@ Fixed ~~~~~ * Fix problems with displaying dates for events in the week and lesson view. +* Unique constraint on lesson documentations and personal notes did not work and caused racey duplicates. `2.0rc5`_ - 2021-08-12 ---------------------- diff --git a/aleksis/apps/alsijil/migrations/0014_fix_unique_lesson_documentation.py b/aleksis/apps/alsijil/migrations/0014_fix_unique_lesson_documentation.py new file mode 100644 index 0000000000000000000000000000000000000000..6ed00ec72a1a23e8bfbde5d765324cd6f59275a3 --- /dev/null +++ b/aleksis/apps/alsijil/migrations/0014_fix_unique_lesson_documentation.py @@ -0,0 +1,29 @@ +# Generated by Django 3.2.3 on 2021-08-20 12:38 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('alsijil', '0013_fix_uniqueness_per_site'), + ] + + operations = [ + migrations.RemoveConstraint( + model_name='lessondocumentation', + name='unique_documentation_per_object', + ), + migrations.AddConstraint( + model_name='lessondocumentation', + constraint=models.UniqueConstraint(fields=('week', 'year', 'lesson_period'), name='unique_documentation_per_lp'), + ), + migrations.AddConstraint( + model_name='lessondocumentation', + constraint=models.UniqueConstraint(fields=('week', 'year', 'event'), name='unique_documentation_per_ev'), + ), + migrations.AddConstraint( + model_name='lessondocumentation', + constraint=models.UniqueConstraint(fields=('week', 'year', 'extra_lesson'), name='unique_documentation_per_el'), + ), + ] diff --git a/aleksis/apps/alsijil/migrations/0015_fix_unique_personal_note.py b/aleksis/apps/alsijil/migrations/0015_fix_unique_personal_note.py new file mode 100644 index 0000000000000000000000000000000000000000..195e0ec80ef43a4d8afe8bb38193d954f833aef1 --- /dev/null +++ b/aleksis/apps/alsijil/migrations/0015_fix_unique_personal_note.py @@ -0,0 +1,29 @@ +# Generated by Django 3.2.4 on 2021-08-29 13:31 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('alsijil', '0014_fix_unique_lesson_documentation'), + ] + + operations = [ + migrations.RemoveConstraint( + model_name='personalnote', + name='unique_personal_note_per_object', + ), + migrations.AddConstraint( + model_name='personalnote', + constraint=models.UniqueConstraint(fields=('week', 'year', 'lesson_period', 'person'), name='unique_note_per_lp'), + ), + migrations.AddConstraint( + model_name='personalnote', + constraint=models.UniqueConstraint(fields=('week', 'year', 'event', 'person'), name='unique_note_per_ev'), + ), + migrations.AddConstraint( + model_name='personalnote', + constraint=models.UniqueConstraint(fields=('week', 'year', 'extra_lesson', 'person'), name='unique_note_per_el'), + ), + ] diff --git a/aleksis/apps/alsijil/models.py b/aleksis/apps/alsijil/models.py index 51857750b434dc03b36c23b7c10f6fcca69ed013..1c9cc995142510570db89f18a85ec9b2eaba9ba5 100644 --- a/aleksis/apps/alsijil/models.py +++ b/aleksis/apps/alsijil/models.py @@ -283,8 +283,13 @@ class PersonalNote(RegisterObjectRelatedMixin, ExtensibleModel): check=lesson_related_constraint_q, name="one_relation_only_personal_note" ), models.UniqueConstraint( - fields=("lesson_period", "week", "year", "event", "extra_lesson"), - name="unique_personal_note_per_object", + fields=("week", "year", "lesson_period", "person"), name="unique_note_per_lp", + ), + models.UniqueConstraint( + fields=("week", "year", "event", "person"), name="unique_note_per_ev", + ), + models.UniqueConstraint( + fields=("week", "year", "extra_lesson", "person"), name="unique_note_per_el", ), ] @@ -373,8 +378,13 @@ class LessonDocumentation(RegisterObjectRelatedMixin, ExtensibleModel): check=lesson_related_constraint_q, name="one_relation_only_lesson_documentation", ), models.UniqueConstraint( - fields=("lesson_period", "week", "year", "event", "extra_lesson"), - name="unique_documentation_per_object", + fields=("week", "year", "lesson_period"), name="unique_documentation_per_lp", + ), + models.UniqueConstraint( + fields=("week", "year", "event"), name="unique_documentation_per_ev", + ), + models.UniqueConstraint( + fields=("week", "year", "extra_lesson"), name="unique_documentation_per_el", ), ]