feat: add missing SQLite indexes for billing and API hot-path queries #44
Reference in New Issue
Block a user
Delete Branch "userAdityaa/caravel:database-indexes"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Add missing SQLite indexes for billing and API hot-path queries.
The initial schema (
0001_init.sql) had no indexes beyond primary keys and thesubdomainunique constraint. Four queries executed on every billing webhook and API request were performing full table scans.Changes
backend/migrations/0002_hot_path_indexes.sql(new file)Adds four indexes:
idx_tenant_stripe_customer_idtenantstripe_customer_idget_tenant_by_stripe_customer_id— called on every Stripe webhookidx_relay_tenant_idrelay(tenant, id)list_relays_for_tenant— called in API + billingidx_relay_tenant_status_planrelay(tenant, status, plan)has_active_paid_relays— called on every relay deactivationidx_activity_resource_type_resource_id_created_at_idactivity(resource_type, resource_id, created_at DESC, id DESC)list_activity_for_relay— eliminates full scan + temp sortcloses #36
This change is purely a performance optimization aimed at improving efficiency under higher scale. It’s intended to support smoother workflows and reduce query overhead, not to act as a blocker for current functionality or progress.