Improve and debug calculate metrics script
This commit is contained in:
17
inventory-server/db/migrations/add_metrics_indexes.sql
Normal file
17
inventory-server/db/migrations/add_metrics_indexes.sql
Normal file
@@ -0,0 +1,17 @@
|
||||
-- Indexes for orders table
|
||||
CREATE INDEX IF NOT EXISTS idx_orders_product_date ON orders(product_id, date);
|
||||
CREATE INDEX IF NOT EXISTS idx_orders_date ON orders(date);
|
||||
|
||||
-- Indexes for purchase_orders table
|
||||
CREATE INDEX IF NOT EXISTS idx_po_product_date ON purchase_orders(product_id, date);
|
||||
CREATE INDEX IF NOT EXISTS idx_po_product_status ON purchase_orders(product_id, status);
|
||||
CREATE INDEX IF NOT EXISTS idx_po_vendor ON purchase_orders(vendor);
|
||||
|
||||
-- Indexes for product_metrics table
|
||||
CREATE INDEX IF NOT EXISTS idx_metrics_revenue ON product_metrics(total_revenue);
|
||||
|
||||
-- Indexes for stock_thresholds table
|
||||
CREATE INDEX IF NOT EXISTS idx_thresholds_category_vendor ON stock_thresholds(category_id, vendor);
|
||||
|
||||
-- Indexes for product_categories table
|
||||
CREATE INDEX IF NOT EXISTS idx_product_categories_both ON product_categories(product_id, category_id);
|
||||
Reference in New Issue
Block a user