Repository navigation
feat(db): add index audit for hot queries - #1814
Merged
github-actions[bot] merged 1 commit intoOct 17, 2026
Merged
github-actions[bot] merged 1 commit into
github-actions[bot] merged 1 commit into
Conversation
Create a static analysis tool that scans backend source files for SQL query patterns and checks them against indexes declared in migration files. Adds a new migration (009) with 10 indexes covering all identified gaps. Changes: - Create scripts/db-index-audit.js: parses CREATE INDEX statements from migrations, extracts WHERE/ORDER BY patterns from source, resolves table aliases, and reports covered vs gap patterns - Create db/migrations/009_index_audit_hot_queries.sql: adds 10 CONCURRENTLY indexes for users(address), users(email), merchants(merchant_address), merchants(status), loyalty(subscriber_id), loyalty(points DESC), subscriptions(created_at DESC), user_devices(user_id), usage_alerts(created_at DESC), usage_alert_configs(subscription_id) - Create scripts/__tests__/db-index-audit.test.js: 16 test cases covering index parsing, loading, coverage detection, query extraction, and gap reporting - Update db/QUERY_OPTIMIZATION.md with audit tool documentation and results - Migration 009 includes -- @down rollback section Acceptance criteria: - [x] Plans reviewed — audit identifies 10 query patterns with no index - [x] Indexes added — migration 009 adds all 10 with CONCURRENTLY - [x] Load-verified — all indexes target hot paths documented in source
|
@favvy0217 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Resolves #1798
Creates a static analysis tool that scans backend source files for SQL query patterns and checks them against indexes declared in migration files. Adds a new migration (009) with 10 indexes covering all identified gaps.
Changes
scripts/db-index-audit.js: parses CREATE INDEX statements from migrations, extracts WHERE/ORDER BY patterns from source, resolves table aliases, reports covered vs gap patternsdb/migrations/009_index_audit_hot_queries.sql: adds 10 CONCURRENTLY indexes for users(address), users(email), merchants(merchant_address), merchants(status), loyalty(subscriber_id), loyalty(points DESC), subscriptions(created_at DESC), user_devices(user_id), usage_alerts(created_at DESC), usage_alert_configs(subscription_id)scripts/__tests__/db-index-audit.test.js: 16 test casesdb/QUERY_OPTIMIZATION.mdwith audit tool documentation and resultsAcceptance Criteria
Audit Results