db: drop duplicate snapshots sandbox_id index - #3405
Conversation
PR SummaryLow Risk Overview Reviewed by Cursor Bugbot for commit 55899f2. Bugbot is set up for automated code reviews on this repo. Configure here. |
❌ 5 Tests Failed:
View the top 3 failed test(s) by shortest run time
View the full list of 1 ❄️ flaky test(s)
To view more test analytics, go to the Test Analytics Dashboard |
There was a problem hiding this comment.
LGTM — straightforward, low-risk migration.
Verified the redundant-index premise directly: idx_snapshots_sandbox_id was created in 20250708135400_snapshots_migrations.sql, and the unique constraint snapshots_sandbox_id_unique (added later in 20251009170758_unique_snapshots.sql) on the same column already provides Postgres's implicit backing index, making the plain index redundant. Checked the migration mechanics — correct timestamp, NO TRANSACTION for the CONCURRENTLY drop/create, statement_timeout bounds and the migrator's 3h baseline restore, and a down path that clears a stranded INVALID index before rebuilding — all consistent with the pattern used in the recent 20260725100500_env_builds_status_group_statistics.sql migration.
Extended reasoning...
Overview
Single new migration file dropping a redundant non-unique index on snapshots.sandbox_id, run CONCURRENTLY with a bounded statement_timeout. Down migration clears any leftover INVALID index and rebuilds it, also CONCURRENTLY.
Security risks
None. This is schema-only cleanup; no auth, crypto, or data-exposure surface is touched. Uniqueness enforcement remains on the constraint-backed index (snapshots_sandbox_id_unique), so there is no correctness regression for duplicate detection.
Level of scrutiny
Low. This is a mechanical DB migration following an established pattern in this repo (see 20260725100500_env_builds_status_group_statistics.sql for the same statement_timeout/NO TRANSACTION structure). I independently verified the redundancy claim against the migration history rather than taking the PR description at face value, and confirmed the down-migration correctly guards against the classic "stranded INVALID index" pitfall of interrupted CONCURRENTLY builds.
Other factors
No CODEOWNERS-sensitive paths, no outstanding reviewer comments to address, and Codecov reports full coverage on the change (trivially, since it's a migration file). This is a fresh re-roll of a previously closed draft PR (#3390) per the description, with no changes needed based on the current diff.
idx_snapshots_sandbox_id is an exact duplicate of the constraint-backed snapshots_sandbox_id_unique (same key column). The unique twin serves every lookup; the plain copy shows no scans over a multi-month usage window while every snapshot write maintains both. Dropped CONCURRENTLY; uniqueness enforcement is untouched. Fresh, isolated re-roll of the earlier closed draft (#3390).
Schema proof, both definitions in this repo: the dropped index (20250708135400 L3) and the surviving unique constraint (20251009170758 L4-L5) — identical key
(sandbox_id). Background on why identical indexes are redundant: PostgreSQL wiki — duplicate indexes.