Skip to content

Add partial index on tools for active_subscription filtering#28

Open
devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1776222216-add-tools-indexes
Open

Add partial index on tools for active_subscription filtering#28
devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1776222216-add-tools-indexes

Conversation

@devin-ai-integration
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot commented Apr 15, 2026

Summary

Adds a Supabase migration that creates a partial B-tree index on tools(billing_cycle) WHERE active_subscription = true.

Analysis performed: The active_subscription column is used as a filter predicate in three client-side computed selectors (totalMonthlyCost, totalAnnualCost, renewingWithin30Days), all of which filter for active_subscription === true and then branch on billing_cycle. The partial index targets this pattern and keeps the index footprint small by only including rows with active subscriptions.

bill_day was intentionally not indexed — it is only consumed by the nextRenewalDate() date computation utility and never appears as a filter, join, or sort predicate.

Important caveat: Currently, fetchTools loads all rows via select('*').order('name') and all filtering happens client-side in JS. This index is forward-looking — it won't be exercised until those selectors are refactored into server-side queries (e.g. .eq('active_subscription', true)).

Review & Testing Checklist for Human

  • Confirm the index is actually useful for your roadmap — no current Supabase query filters on active_subscription or billing_cycle server-side. If you don't plan to push these filters to the DB, this index adds write overhead with no read benefit.
  • Verify the partial index design (ON tools(billing_cycle) WHERE active_subscription = true) matches the query patterns you intend to support. If you'd rather filter/sort by a different column (e.g. cost, renewal_date), the indexed column should change.
  • Confirm skipping an index on bill_day is acceptable for your use case.

Notes

  • The migration uses CREATE INDEX IF NOT EXISTS, so it is idempotent and safe to re-run.
  • The migration filename (20260415_...) follows the existing naming convention in supabase/migrations/.

Link to Devin session: https://app.devin.ai/sessions/c463c41903f2427ebc930a895dc4e7ad
Requested by: @alecvdp


Open with Devin

Add a partial index on tools(billing_cycle) WHERE active_subscription = true.

The active_subscription column is used as a filter predicate in multiple
computed selectors (totalMonthlyCost, totalAnnualCost, renewingWithin30Days).
This partial index keeps the footprint small while targeting the common
query pattern of filtering for tools with an active subscription.

No index added for bill_day — it is only used in the nextRenewalDate()
date computation utility and never appears as a filter, join, or sort
predicate in any query.

Co-Authored-By: alecvdpoel <alecvdpoel@pm.me>
@devin-ai-integration
Copy link
Copy Markdown
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

Copy link
Copy Markdown
Contributor Author

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 1 additional finding.

Open in Devin Review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant