Skip to content

Commit be98be3

Browse files
authored
feat(surveys): add FK constraint for linked_insight_id (#41790)
1 parent a411ae9 commit be98be3

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Generated by Django 4.2.26 on 2025-11-20 02:30
2+
3+
import django.db.models.deletion
4+
from django.db import migrations, models
5+
6+
7+
class Migration(migrations.Migration):
8+
dependencies = [
9+
("posthog", "0912_alter_survey_linked_insight_type"),
10+
]
11+
12+
operations = [
13+
migrations.SeparateDatabaseAndState(
14+
state_operations=[
15+
migrations.AlterField(
16+
model_name="survey",
17+
name="linked_insight",
18+
field=models.ForeignKey(
19+
blank=True,
20+
db_index=False,
21+
null=True,
22+
on_delete=django.db.models.deletion.SET_NULL,
23+
related_name="surveys_linked_insight",
24+
related_query_name="survey_linked_insight",
25+
to="posthog.insight",
26+
),
27+
),
28+
],
29+
database_operations=[
30+
migrations.RunSQL(
31+
sql="""
32+
ALTER TABLE "posthog_survey" ADD CONSTRAINT "posthog_survey_linked_insight_id_586524f3_fk_posthog_d" FOREIGN KEY ("linked_insight_id") REFERENCES "posthog_dashboarditem" ("id") DEFERRABLE INITIALLY DEFERRED NOT VALID; -- existing-table-constraint-ignore
33+
""",
34+
reverse_sql="""
35+
ALTER TABLE "posthog_survey" DROP CONSTRAINT IF EXISTS "posthog_survey_linked_insight_id_586524f3_fk_posthog_d";
36+
""",
37+
),
38+
],
39+
),
40+
]
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0912_alter_survey_linked_insight_type
1+
0913_alter_survey_linked_insight

posthog/models/surveys/survey.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class Meta:
7979
related_name="surveys_linked_insight",
8080
related_query_name="survey_linked_insight",
8181
db_index=False,
82-
db_constraint=False, # Constraint will be added in follow-up migration
82+
db_constraint=True,
8383
)
8484
internal_targeting_flag = models.ForeignKey(
8585
"posthog.FeatureFlag",

0 commit comments

Comments
 (0)