Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(oauth): remove legacy scope trigram index (#88958)

Sven Langefc3e27d4f4b3
diff --git a/posthog/migrations/1320_remove_oauth_scope_trgm.py b/posthog/migrations/1320_remove_oauth_scope_trgm.py
new file mode 100644
index 000000000000..a2634459d704
--- /dev/null
+++ b/posthog/migrations/1320_remove_oauth_scope_trgm.py
@@ -0,0 +1,20 @@
+# Generated by Django 5.2.17 on 2026-08-26 08:01
+
+from django.db import migrations
+
+from posthog.migration_helpers import SafeRemoveIndexConcurrently
+
+
+class Migration(migrations.Migration):
+ atomic = False
+
+ dependencies = [
+ ("posthog", "1319_team_posthog_team_widget_token_idx"),
+ ]
+
+ operations = [
+ SafeRemoveIndexConcurrently(
+ model_name="oauthaccesstoken",
+ name="oauthaccesstoken_scope_trgm",
+ ),
+ ]
diff --git a/posthog/migrations/max_migration.txt b/posthog/migrations/max_migration.txt
index e6ed0e9ad5ce..b16fcf150e55 100644
--- a/posthog/migrations/max_migration.txt
+++ b/posthog/migrations/max_migration.txt
@@ -1 +1 @@
-1319_team_posthog_team_widget_token_idx
+1320_remove_oauth_scope_trgm
diff --git a/posthog/models/oauth.py b/posthog/models/oauth.py
index 1f34c13016d7..1d1e6720dd22 100644
--- a/posthog/models/oauth.py
+++ b/posthog/models/oauth.py
@@ -526,15 +526,7 @@ class OAuthAccessToken(AbstractAccessToken):
verbose_name_plural = "OAuth Access Tokens"
swappable = "OAUTH2_PROVIDER_ACCESS_TOKEN_MODEL"
indexes = [
- # Pending-list merges make one token write absorb batched GIN maintenance.
- # Direct updates keep that work incremental for both scope indexes.
- GinIndex(
- fields=["scope"],
- name="oauthaccesstoken_scope_trgm",
- opclasses=["gin_trgm_ops"],
- condition=Q(application__isnull=False),
- fastupdate=False,
- ),
+ # Direct updates avoid pending-list merges that make one token write absorb batched GIN maintenance.
GinIndex(
oauth_scope_tokens_expression(),
name="oauthaccesstoken_scopes_gin",