Merge template_usage_stats *_mins into app_usage_mins JSONB
Author: EhabYCreated Jul 22, 2026Updated Sep 17, 2026
Labelsfeaturevs-code
Phase 4 of the Scalable Approach for Adding New IDE Session Types RFC. The durable template_usage_stats table still has dedicated vscode_mins/jetbrains_mins/ssh_mins/reconnecting_pty_mins columns, so adding an IDE would still require a schema change there; this phase makes the durable rollup layer dynamic too.
Scope (RFC: "template_usage_stats must also be migrated"):
UpsertTemplateUsageStats: have theagent_stats_bucketsCTE produceapp_name/app_minutesentries that flow into the existingapp_usage_minsJSONB, the same way web app usage is stored today- Key scheme: builtin session names will share
app_usage_minswith web app slugs; confirm how the insights queries tell them apart before writing the backfill - One-time migration: backfill the dedicated
*_minsvalues intoapp_usage_minsfor existing rows, then drop the dedicated columns, including the always-zerosftp_mins(dead since its TODOs were never implementable) GetTemplateInsights: read IDE minutes fromapp_usage_minsinstead of dedicated columns;convertTemplateInsightsAppsbuilds the builtin apps list dynamicallyGetTemplateAppInsightsstays separate (it filters viaworkspace_apps, which builtin IDE sessions never join)
After this phase, a new IDE flows agent → normalized table → JSONB rollup with zero schema changes, which is the point of the RFC.
Done when
- Rollup writes per-app and per-family minutes and the dedicated columns are dropped (feat: store session usage per app and family in template usage stats, child table
template_usage_stats_session_appsinstead ofapp_usage_mins, see the comment below on slug collisions) - Backfilled historical data produces identical
GetTemplateInsightsresults (feat: store session usage per app and family in template usage stats) - Per-app read query over
template_usage_stats_session_appsand dynamicconvertTemplateInsightsApps - A new app name reported through phase 1 shows up in template insights with no schema change
- Web app usage gets the same split:
app_usage_minsbroken out per app and returned fromGetTemplateInsightsalongside session usage (raised in review on feat: store session usage per app and family in template usage stats, since the child table means the two are now stored differently)
Depends on coder/coder#27410. Storage landed in feat: store session usage per app and family in template usage stats; per-app history starts at migration 000596.
Created by Coder Agents on behalf of @EhabY.
Source: coder/coder