Skip to content

Commit 4277edf

Browse files
committed
Add migration to set DB constraint
1 parent 3ca2d9c commit 4277edf

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Generated by Django 5.2.8 on 2025-11-20 12:35
2+
3+
from django.db import migrations
4+
5+
6+
# language=SQL
7+
CONSTRAINT_SQL_POLLSTATS_ONE_SEGMENT_SET_MAX = """
8+
ALTER TABLE stats_pollstats ADD CONSTRAINT check_pollstats_only_one_segment_set CHECK (num_nonnulls(age_segment_id, gender_segment_id, location_id, scheme_segment_id) <= 1);
9+
"""
10+
11+
# language=SQL
12+
CONSTRAINT_SQL_POLLSTATS_ONE_SEGMENT_SET_MAX_DROP = """
13+
ALTER TABLE stats_pollstats DROP CONSTRAINT IF EXISTS check_pollstats_only_one_segment_set;
14+
"""
15+
16+
class Migration(migrations.Migration):
17+
18+
dependencies = [
19+
("stats", "0031_migrate_poll_stats"),
20+
]
21+
22+
operations = [
23+
migrations.RunSQL(CONSTRAINT_SQL_POLLSTATS_ONE_SEGMENT_SET_MAX, CONSTRAINT_SQL_POLLSTATS_ONE_SEGMENT_SET_MAX_DROP),
24+
]

0 commit comments

Comments
 (0)