forked from CGM_Public/pretix_original
QuestionAnswer: Add UNIQUE keys on (orderposition, question) and (cartposition, question) (#1994)
This commit is contained in:
committed by
GitHub
parent
4a2ac110b3
commit
46cee890f0
49
src/pretix/base/migrations/0179_auto_20210311_1653.py
Normal file
49
src/pretix/base/migrations/0179_auto_20210311_1653.py
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
# Generated by Django 3.0.10 on 2021-03-11 16:53
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
def clean_duplicates(apps, schema_editor):
|
||||||
|
while True:
|
||||||
|
delete_options = """
|
||||||
|
DELETE
|
||||||
|
FROM pretixbase_questionanswer_options
|
||||||
|
WHERE questionanswer_id IN (
|
||||||
|
SELECT MIN(qa.id)
|
||||||
|
FROM pretixbase_questionanswer qa
|
||||||
|
GROUP BY qa.cartposition_id, qa.orderposition_id, qa.question_id
|
||||||
|
HAVING COUNT(*) > 1
|
||||||
|
);
|
||||||
|
"""
|
||||||
|
delete_answers = """
|
||||||
|
DELETE
|
||||||
|
FROM pretixbase_questionanswer
|
||||||
|
WHERE pretixbase_questionanswer.id IN (
|
||||||
|
SELECT MIN(qa.id)
|
||||||
|
FROM pretixbase_questionanswer qa
|
||||||
|
GROUP BY qa.cartposition_id, qa.orderposition_id, qa.question_id
|
||||||
|
HAVING COUNT(*) > 1
|
||||||
|
);
|
||||||
|
"""
|
||||||
|
with schema_editor.connection.cursor() as cursor:
|
||||||
|
cursor.execute(delete_options)
|
||||||
|
cursor.execute(delete_answers)
|
||||||
|
if cursor.rowcount == 0:
|
||||||
|
return
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('pretixbase', '0178_auto_20210308_1326'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RunPython(
|
||||||
|
clean_duplicates,
|
||||||
|
migrations.RunPython.noop,
|
||||||
|
),
|
||||||
|
migrations.AlterUniqueTogether(
|
||||||
|
name='questionanswer',
|
||||||
|
unique_together={('orderposition', 'question'), ('cartposition', 'question')},
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -983,6 +983,9 @@ class QuestionAnswer(models.Model):
|
|||||||
|
|
||||||
objects = ScopedManager(organizer='question__event__organizer')
|
objects = ScopedManager(organizer='question__event__organizer')
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
unique_together = [['orderposition', 'question'], ['cartposition', 'question']]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def backend_file_url(self):
|
def backend_file_url(self):
|
||||||
if self.file:
|
if self.file:
|
||||||
|
|||||||
Reference in New Issue
Block a user