assessment-model/src/app/db
Khalim Conn-Kowlessar 4fd1e00e63 perf(db): covering partial index for the reporting measures aggregate
The reporting 'where the money goes' panel joins the latest plan per
property to its recommendations ON plan_id, filters to the default active
set, and sums estimated_cost / counts property_id per measure_type. The
only plan_id index (idx_recommendation_plan_id) is plain, so the aggregate
heap-fetches every recommendation to apply the filter and read those
columns — hundreds of thousands of fetches on large portfolios (434),
which times the panel out.

idx_recommendation_plan_default carries plan_id + measure_type +
property_id + estimated_cost as key columns (drizzle-orm has no INCLUDE),
partial on default = true AND already_installed = false, so the aggregate
runs index-only. Added to the schema and generated via drizzle-kit.

OPS: build CONCURRENTLY out-of-band on prod before the migration runs so it
no-ops there (0258 pattern); the migration uses IF NOT EXISTS for fresh
environments. See the migration file header.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-08 11:52:35 +00:00
..
migrations perf(db): covering partial index for the reporting measures aggregate 2026-07-08 11:52:35 +00:00
schema perf(db): covering partial index for the reporting measures aggregate 2026-07-08 11:52:35 +00:00
sql amend migration files 2026-07-02 13:48:46 +00:00
surveyDB added decent homes tab button 2025-09-23 17:21:28 +00:00
backfill-recommendation-denormalization.ts perf(backfill): faster, resumable recommendation denormalization + ops tooling 2026-07-02 10:00:46 +00:00
create_user.ts Added create_user and also making users table schema changes 2023-07-10 19:14:06 +01:00
db.ts uplaod 2026-04-16 16:59:30 +00:00
migrate.ts Got drizzle orm working 2023-07-10 17:48:37 +01:00
run-sql.ts perf(backfill): faster, resumable recommendation denormalization + ops tooling 2026-07-02 10:00:46 +00:00