-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(plugin-server): reduce constraints related to person overrides
- Loading branch information
1 parent
1f9b42c
commit eb105a9
Showing
3 changed files
with
69 additions
and
5 deletions.
There are no files selected for viewing
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
66 changes: 66 additions & 0 deletions
66
posthog/migrations/0354_adjust_personoverride_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,66 @@ | ||
# Generated by Django 3.2.19 on 2023-10-11 21:32 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
TRUNCATE_PERSONOVERRIDE_SQL = "TRUNCATE posthog_personoverride, posthog_personoverridemapping" | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("posthog", "0353_add_5_minute_interval_to_batch_exports"), | ||
] | ||
|
||
operations = [ | ||
migrations.RunSQL(TRUNCATE_PERSONOVERRIDE_SQL, "SELECT 1"), | ||
migrations.RemoveConstraint( | ||
model_name="personoverride", | ||
name="unique override per old_person_id", | ||
), | ||
migrations.RemoveField( | ||
model_name="personoverride", | ||
name="team", | ||
), | ||
migrations.RemoveField( | ||
model_name="personoverridemapping", | ||
name="team_id", | ||
), | ||
migrations.AddField( | ||
model_name="personoverridemapping", | ||
name="team", | ||
field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, to="posthog.team"), | ||
preserve_default=False, | ||
), | ||
migrations.AlterField( | ||
model_name="personoverride", | ||
name="old_person_id", | ||
field=models.OneToOneField( | ||
db_column="old_person_id", | ||
on_delete=django.db.models.deletion.CASCADE, | ||
related_name="person_override_old", | ||
to="posthog.personoverridemapping", | ||
), | ||
), | ||
# drop the old exclusion constraint | ||
migrations.RunSQL( | ||
"ALTER TABLE posthog_personoverride DROP CONSTRAINT exclude_override_person_id_from_being_old_person_id", | ||
""" | ||
ALTER TABLE posthog_personoverride | ||
ADD CONSTRAINT exclude_override_person_id_from_being_old_person_id | ||
EXCLUDE USING gist((array[old_person_id, override_person_id]) WITH &&, override_person_id WITH <>) | ||
DEFERRABLE | ||
INITIALLY DEFERRED | ||
""", | ||
), | ||
# add the new exclusion constraint | ||
migrations.RunSQL( | ||
""" | ||
ALTER TABLE posthog_personoverride | ||
ADD CONSTRAINT exclude_override_person_id_from_being_old_person_id | ||
EXCLUDE USING gist (old_person_id WITH =, override_person_id WITH =) | ||
DEFERRABLE | ||
INITIALLY DEFERRED | ||
""", | ||
"ALTER TABLE posthog_personoverride DROP CONSTRAINT exclude_override_person_id_from_being_old_person_id", | ||
), | ||
] |
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