-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use database constraints instead of python asserts (#1957)
* Implemented DB constraints * Fixed check_vote_date for single day votes * Refactored Question to QuestionTypes * Fixed check_count_null * Fixed check_additional_textanswers in tests * Fixed rebase issues * Fixed code style * Simplified constraint-migrations * Fixed migration history * Renamed QuestionTypes to QuestionType * Renamed constraints * Fixed check_evaluation_text_answer_is_modified * Reformat code * Implemented PR suggestions * rename migration after rebase --------- Co-authored-by: Niklas Mohrin <[email protected]>
- Loading branch information
1 parent
a09372a
commit 987684b
Showing
13 changed files
with
246 additions
and
127 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
evap/evaluation/migrations/0137_use_more_database_constraints.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Generated by Django 4.2.2 on 2023-07-03 22:18 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.functions.datetime | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("evaluation", "0136_alter_userprofile_first_name_chosen_and_more"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddConstraint( | ||
model_name="evaluation", | ||
constraint=models.CheckConstraint( | ||
check=models.Q( | ||
( | ||
"vote_end_date__gte", | ||
django.db.models.functions.datetime.TruncDate(models.F("vote_start_datetime")), | ||
) | ||
), | ||
name="check_evaluation_start_before_end", | ||
), | ||
), | ||
migrations.AddConstraint( | ||
model_name="evaluation", | ||
constraint=models.CheckConstraint( | ||
check=models.Q( | ||
("_participant_count__isnull", True), | ||
("_voter_count__isnull", True), | ||
_connector="XOR", | ||
_negated=True, | ||
), | ||
name="check_evaluation_participant_count_and_voter_count_both_set_or_not_set", | ||
), | ||
), | ||
migrations.AddConstraint( | ||
model_name="question", | ||
constraint=models.CheckConstraint( | ||
check=models.Q( | ||
models.Q(("type", 0), ("type", 5), _connector="OR", _negated=True), | ||
models.Q(("allows_additional_textanswers", True), _negated=True), | ||
_connector="OR", | ||
), | ||
name="check_evaluation_textanswer_or_heading_question_has_no_additional_textanswers", | ||
), | ||
), | ||
migrations.AddConstraint( | ||
model_name="textanswer", | ||
constraint=models.CheckConstraint( | ||
check=models.Q(("answer", models.F("original_answer")), _negated=True), | ||
name="check_evaluation_text_answer_is_modified", | ||
), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.