chore(tasks): drop the redundant team_id index on sandbox environments - #95866
chore(tasks): drop the redundant team_id index on sandbox environments#95866posthog[bot] wants to merge 1 commit into
Conversation
The (team, created_by) index on posthog_sandbox_environment leads with team_id, so the auto-created single-column FK index serves no query and no cascade check. Set db_index=False on the team FK and drop the index concurrently. Generated-By: PostHog Desktop Task-Id: 2fbb6166-26d3-4e71-9454-8fe4b64bc4cb
|
Merging to
After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here |
🤖 CI report
|
There was a problem hiding this comment.
Not approved yet — waiting on the conditions below.
The Migration risk check has not finished for this commit, so stamphog cannot tell a safe migration from a risky one yet. The review runs again on the next push, or you can re-request it once the check reports.
Gate mechanics and policy version
| Gate | Result | |
|---|---|---|
| prerequisites | ✓ | all clear |
| deny-list | ✗ | matches: migrations |
| size | ✓ | 39L, 2F substantive, 41L/3F incl. docs/generated/snapshots — within ceiling |
| tier | ✗ | classified as T2-never: T2-never (41L, 3F, single-area, chore) |
| stamphog 2.0.0b4 | .stamphog/policy.yml @ 807767b · reviewed head 807767b |

Problem
posthog_sandbox_environment, one row per user-defined sandbox environment per team.team_idindex on the table that no query has scanned in 35 days.Metaindex on(team, created_by)leads withteam_id, so it already serves everyteam_idlookup and the cascade check when a team row is deleted.Changes
db_index=Falseon theteamforeign key stops Django from declaring the single-column index, and migration0118drops it withDROP INDEX CONCURRENTLY, so no table lock.AlterFieldinSeparateDatabaseAndState, because the concurrent drop cannot run inside the migration transaction.posthog_sandbox_environment_team_id_d94b6a9a(team_id)posthog_san_team_id_817c0d_idx(team_id,created_by_id)posthog_sandbox_environment_custom_image_id_a62b5702custom_image_idstays. It also reports no scans, but it serves theon_delete=SET_NULLcascade, and custom images are archived rather than deleted, so the index only looks idle.How did you test this code?
makemigrations tasks --dry-runreports no state drift.sqlmigrate tasks 0118emits exactlyDROP INDEX CONCURRENTLY IF EXISTS "posthog_sandbox_environment_team_id_d94b6a9a".analyze_migration_riskclassifies the migration as Safe.pg_indexeseach time: forward removes the index, backward recreates the same definition.products/tasks/backend/testscould not start. CI runs them.Automatic notifications
Docs update
None. No user-facing behavior, API, or documented workflow changes.
🤖 Agent context
Autonomy: Fully autonomous
/django-migrations,/writing-pr-descriptions,/writing-code-comments,/writing-simplified-technical-english.gh pr list --state open --searchfound no open PR touching this table. Several merged PRs do the same cleanup on other tables.RunSQLdrop, copying an older merged migration. It now uses theDropIndexConcurrentlyhelper instead, which is idempotent underbin/migrateretries and can rebuild the index on reverse.Created with PostHog Desktop from this inbox report.