fix(analytics): Fix market-summary store count and add search indexes
- market-summary now counts from store_products table (not product_variants) - Added trigram indexes for fast ILIKE product searches 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
20
backend/migrations/096_product_search_indexes.sql
Normal file
20
backend/migrations/096_product_search_indexes.sql
Normal file
@@ -0,0 +1,20 @@
|
||||
-- Migration: Add trigram indexes for fast ILIKE product searches
|
||||
-- Enables fast searches on name_raw, brand_name_raw, and description
|
||||
|
||||
-- Enable pg_trgm extension if not already enabled
|
||||
CREATE EXTENSION IF NOT EXISTS pg_trgm;
|
||||
|
||||
-- Create GIN trigram indexes for fast ILIKE searches
|
||||
CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_store_products_name_trgm
|
||||
ON store_products USING gin (name_raw gin_trgm_ops);
|
||||
|
||||
CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_store_products_brand_name_trgm
|
||||
ON store_products USING gin (brand_name_raw gin_trgm_ops);
|
||||
|
||||
CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_store_products_description_trgm
|
||||
ON store_products USING gin (description gin_trgm_ops);
|
||||
|
||||
-- Add comment
|
||||
COMMENT ON INDEX idx_store_products_name_trgm IS 'Trigram index for fast ILIKE searches on product name';
|
||||
COMMENT ON INDEX idx_store_products_brand_name_trgm IS 'Trigram index for fast ILIKE searches on brand name';
|
||||
COMMENT ON INDEX idx_store_products_description_trgm IS 'Trigram index for fast ILIKE searches on description';
|
||||
Reference in New Issue
Block a user