Add index on plan_recommendations.recommendation_id to Drizzle schema

Plan deletes cascade to recommendation rows, and each cascaded delete
fires an FK check against plan_recommendations.recommendation_id. With
~26M rows and no index on that column the check seq-scans per row,
making any plan deletion path time out.

The index already exists on the live DB (created CONCURRENTLY on
2026-07-02 as idx_plan_recommendations_recommendation_id, 74s build);
this brings the Drizzle schema in line so it stops drifting. No
migration is included — generating/applying it is left as a human
action, and it must reuse the existing index name (IF NOT EXISTS) so
it no-ops against prod.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Jun-te Kim 2026-07-02 16:24:57 +00:00
parent 767cb2af3f
commit b49fbc4265

View file

@ -263,6 +263,13 @@ export const planRecommendations = pgTable(
table.planId,
table.recommendationId,
),
// Supports the FK check fired when `recommendation` rows are deleted
// (cascaded from plan deletes); without it each delete seq-scans this
// ~26M-row table. Already created on the live DB (CONCURRENTLY,
// 2026-07-02) — the migration must match the existing index name.
index("idx_plan_recommendations_recommendation_id").on(
table.recommendationId,
),
],
);