Improve and debug calculate metrics script

This commit is contained in:
2025-01-12 14:52:46 -05:00
parent ac8563325a
commit 271a40f2c5
4 changed files with 350 additions and 101 deletions

View 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);