-
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(environments): Make taxonomy reads + writes project–based (#26766)
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
372c92c
commit 78959b2
Showing
12 changed files
with
225 additions
and
30 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
# Generated by Django 4.2.15 on 2024-12-09 15:51 | ||
|
||
from django.db import migrations | ||
from django.db import models | ||
import django.db.models.functions.comparison | ||
import posthog.models.utils | ||
from django.contrib.postgres.operations import AddIndexConcurrently, RemoveIndexConcurrently | ||
|
||
|
||
class Migration(migrations.Migration): | ||
atomic = False # Added to support concurrent index creation | ||
dependencies = [("posthog", "0531_alter_hogfunction_type")] | ||
|
||
operations = [ | ||
# First clean up rows that would fail the project-based unique constraints we're adding | ||
migrations.RunSQL( | ||
sql=""" | ||
DELETE FROM posthog_propertydefinition | ||
WHERE team_id IN ( | ||
SELECT id FROM posthog_team WHERE id != project_id | ||
);""", | ||
reverse_sql=migrations.RunSQL.noop, | ||
elidable=True, | ||
), | ||
migrations.RunSQL( | ||
sql=""" | ||
DELETE FROM posthog_eventdefinition | ||
WHERE team_id IN ( | ||
SELECT id FROM posthog_team WHERE id != project_id | ||
);""", | ||
reverse_sql=migrations.RunSQL.noop, | ||
elidable=True, | ||
), | ||
migrations.RunSQL( | ||
sql=""" | ||
DELETE FROM posthog_eventproperty | ||
WHERE team_id IN ( | ||
SELECT id FROM posthog_team WHERE id != project_id | ||
);""", | ||
reverse_sql=migrations.RunSQL.noop, | ||
elidable=True, | ||
), | ||
# Remove misguided `project_id`-only indexes from the previous migration | ||
RemoveIndexConcurrently( | ||
model_name="eventproperty", | ||
name="posthog_eve_proj_id_22de03_idx", | ||
), | ||
RemoveIndexConcurrently( | ||
model_name="eventproperty", | ||
name="posthog_eve_proj_id_26dbfb_idx", | ||
), | ||
RemoveIndexConcurrently( | ||
model_name="propertydefinition", | ||
name="index_property_def_query_proj", | ||
), | ||
RemoveIndexConcurrently( | ||
model_name="propertydefinition", | ||
name="posthog_pro_project_3583d2_idx", | ||
), | ||
# Add new useful indexes using `coalesce(project_id, team_id)` | ||
AddIndexConcurrently( | ||
model_name="eventproperty", | ||
index=models.Index( | ||
django.db.models.functions.comparison.Coalesce(models.F("project_id"), models.F("team_id")), | ||
models.F("event"), | ||
name="posthog_eve_proj_id_22de03_idx", | ||
), | ||
), | ||
AddIndexConcurrently( | ||
model_name="eventproperty", | ||
index=models.Index( | ||
django.db.models.functions.comparison.Coalesce(models.F("project_id"), models.F("team_id")), | ||
models.F("property"), | ||
name="posthog_eve_proj_id_26dbfb_idx", | ||
), | ||
), | ||
AddIndexConcurrently( | ||
model_name="propertydefinition", | ||
index=models.Index( | ||
django.db.models.functions.comparison.Coalesce(models.F("project_id"), models.F("team_id")), | ||
models.F("type"), | ||
django.db.models.functions.comparison.Coalesce(models.F("group_type_index"), -1), | ||
models.OrderBy(models.F("query_usage_30_day"), descending=True, nulls_last=True), | ||
models.OrderBy(models.F("name")), | ||
name="index_property_def_query_proj", | ||
), | ||
), | ||
AddIndexConcurrently( | ||
model_name="propertydefinition", | ||
index=models.Index( | ||
django.db.models.functions.comparison.Coalesce(models.F("project_id"), models.F("team_id")), | ||
models.F("type"), | ||
models.F("is_numerical"), | ||
name="posthog_pro_project_3583d2_idx", | ||
), | ||
), | ||
migrations.AddConstraint( | ||
model_name="eventdefinition", | ||
constraint=posthog.models.utils.UniqueConstraintByExpression( | ||
concurrently=True, expression="(coalesce(project_id, team_id), name)", name="event_definition_proj_uniq" | ||
), | ||
), | ||
migrations.AddConstraint( | ||
model_name="eventproperty", | ||
constraint=posthog.models.utils.UniqueConstraintByExpression( | ||
concurrently=True, | ||
expression="(coalesce(project_id, team_id), event, property)", | ||
name="posthog_event_property_unique_proj_event_property", | ||
), | ||
), | ||
migrations.AddConstraint( | ||
model_name="propertydefinition", | ||
constraint=posthog.models.utils.UniqueConstraintByExpression( | ||
concurrently=True, | ||
expression="(coalesce(project_id, team_id), name, type, coalesce(group_type_index, -1))", | ||
name="posthog_propdef_proj_uniq", | ||
), | ||
), | ||
] |
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 |
---|---|---|
@@ -1 +1 @@ | ||
0531_alter_hogfunction_type | ||
0532_taxonomy_unique_on_project |
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
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
4 changes: 2 additions & 2 deletions
4
...4dcdf2e218e48e0fd8a247e1b7ae0f04aee3.json → ...376473bd31ace71b4ab6114a39b5aa141f6f.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
4 changes: 2 additions & 2 deletions
4
...73799ecba84594ca04cfb24481cffbf6f6ca.json → ...22cc3ed70f0c5c14593f3d32ef6dc2ae82f7.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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.